moved new feature to separate 'distros.nim' module

This commit is contained in:
Araq 2016-12-23 16:01:10 +01:00
commit b3b4c6343f
6 changed files with 99 additions and 66 deletions

View file

@ -19,6 +19,9 @@ var
installExt*, bin*: seq[string] = @[] ## Nimble metadata.
requiresData*: seq[string] = @[] ## The package's dependencies.
foreignDeps*: seq[string] = @[] ## The foreign dependencies. Only
## exported for 'distros.nim'.
proc requires*(deps: varargs[string]) =
## Call this to set the list of requirements of your Nimble
## package.
@ -42,58 +45,3 @@ proc getPkgDir*(): string =
## Returns the package directory containing the .nimble file currently
## being evaluated.
builtin
from strutils import contains
type
Distribution* {.pure.} = enum ## an enum so that the poor programmer
## cannot introduce typos
Windows, ## some version of Windows
Posix, ## some Posix system
MacOSX, ## some version of OSX
Linux, ## some version of Linux
Ubuntu,
Gentoo,
Fedora,
RedHat,
BSD,
FreeBSD,
OpenBSD
proc detectOsImpl(d: Distribution): bool =
case d
of Distribution.Windows: ## some version of Windows
result = defined(windows)
of Distribution.Posix: result = defined(posix)
of Distribution.MacOSX: result = defined(macosx)
of Distribution.Linux: result = defined(linux)
of Distribution.Ubuntu, Distribution.Gentoo, Distribution.FreeBSD,
Distribution.OpenBSD, Distribution.Fedora:
result = $d in gorge"uname"
of Distribution.RedHat:
result = "Red Hat" in gorge"uname"
of Distribution.BSD: result = defined(bsd)
template detectOs*(d: untyped): bool =
detectOsImpl(Distribution.d)
var foreignDeps: seq[string] = @[]
proc foreignCmd*(cmd: string; requiresSudo=false) =
foreignDeps.add((if requiresSudo: "sudo " else: "") & cmd)
proc foreignDep*(foreignPackageName: string) =
let p = foreignPackageName
when defined(windows):
foreignCmd "Chocolatey install " & p
elif defined(bsd):
foreignCmd "ports install " & p, true
elif defined(linux):
if detectOs(Ubuntu):
foreignCmd "apt-get install " & p, true
elif detectOs(Gentoo):
foreignCmd "emerge install " & p, true
elif detectOs(Fedora):
foreignCmd "yum install " & p, true
else:
discard