-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,23 +8,30 @@ | |
# | ||
|
||
## This module implements the basics for Linux distribution ("distro") | ||
## detection and the OS's native package manager. Its primary purpose is in | ||
## producing output for Nimble packages like:: | ||
## detection and the OS's native package manager. Its primary purpose is to | ||
## produce output for Nimble packages like:: | ||
## | ||
## To complete the installation, run: | ||
## | ||
## sudo apt-get libblas-dev | ||
## sudo apt-get libvoodoo | ||
## | ||
## The above output could be the result of a code snippet like: | ||
## | ||
## .. code-block:: nim | ||
## | ||
## if detectOs(Ubuntu): | ||
## foreignDep "lbiblas-dev" | ||
## foreignDep "libvoodoo" | ||
## | ||
|
||
from strutils import contains, toLowerAscii | ||
|
||
when not defined(nimscript): | ||
from osproc import execProcess | ||
|
||
type | ||
Distribution* {.pure.} = enum ## an enum so that the poor programmer | ||
## cannot introduce typos | ||
Distribution* {.pure.} = enum ## the list of known distributions | ||
Windows ## some version of Windows | ||
Posix ## some Posix system | ||
MacOSX ## some version of OSX | ||
|
@@ -161,20 +168,25 @@ proc detectOsImpl(d: Distribution): bool = | |
result = toLowerAscii($d) in toLowerAscii(uname()) | ||
|
||
template detectOs*(d: untyped): bool = | ||
## Distro/OS detection. For convenience the | ||
## required ``Distribution.`` qualifier is added to the | ||
## enum value. | ||
detectOsImpl(Distribution.d) | ||
|
||
when not defined(nimble): | ||
var foreignDeps: seq[string] = @[] | ||
|
||
proc foreignCmd*(cmd: string; requiresSudo=false) = | ||
## Registers a foreign command to the intern list of commands | ||
## that can be queried later. | ||
let c = (if requiresSudo: "sudo " else: "") & cmd | ||
when defined(nimble): | ||
nimscriptapi.foreignDeps.add(c) | ||
else: | ||
foreignDeps.add(c) | ||
|
||
proc foreignDepInstallCmd*(foreignPackageName: string): (string, bool) = | ||
## returns the distro's native command line to install 'foreignPackageName' | ||
## Returns the distro's native command line to install 'foreignPackageName' | ||
## and whether it requires root/admin rights. | ||
let p = foreignPackageName | ||
when defined(windows): | ||
|
@@ -211,16 +223,17 @@ proc foreignDepInstallCmd*(foreignPackageName: string): (string, bool) = | |
result = ("brew install " & p, true) | ||
|
||
proc foreignDep*(foreignPackageName: string) = | ||
## Registers 'foreignPackageName' to the internal list of foreign deps. | ||
## It is your job to ensure the package name | ||
let (installCmd, sudo) = foreignDepInstallCmd(foreignPackageName) | ||
foreignCmd installCmd, sudo | ||
|
||
proc echoForeignDeps*() = | ||
## Writes the list of registered foreign deps to stdout. | ||
echo "To finish the installation, run:" | ||
for d in foreignDeps: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Araq
Author
Member
|
||
echo d | ||
|
||
when isMainModule: | ||
when false: | ||
foreignDep("libblas-dev") | ||
foreignDep "libfoo" | ||
echoForeignDeps() |
Please make sure that Nimble can capture the value of this variable. Nimble has its own output system and it would be nice to use it.