moved new feature to separate 'distros.nim' module
This commit is contained in:
parent
5fef5c577e
commit
b3b4c6343f
6 changed files with 99 additions and 66 deletions
|
|
@ -939,6 +939,10 @@ proc doAction(options: Options) =
|
||||||
let (_, pkgInfo) = install(options.action.packages, options)
|
let (_, pkgInfo) = install(options.action.packages, options)
|
||||||
if options.action.packages.len == 0:
|
if options.action.packages.len == 0:
|
||||||
nimScriptHint(pkgInfo)
|
nimScriptHint(pkgInfo)
|
||||||
|
if pkgInfo.foreignDeps.len > 0:
|
||||||
|
echo("To finish the installation, run: ")
|
||||||
|
for i in 0..<pkgInfo.foreignDeps.len:
|
||||||
|
echo(pkgInfo.foreignDeps[i])
|
||||||
of actionUninstall:
|
of actionUninstall:
|
||||||
uninstall(options)
|
uninstall(options)
|
||||||
of actionSearch:
|
of actionSearch:
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ when not defined(nimscript):
|
||||||
binDir*: string
|
binDir*: string
|
||||||
srcDir*: string
|
srcDir*: string
|
||||||
backend*: string
|
backend*: string
|
||||||
|
foreignDeps*: seq[string]
|
||||||
|
|
||||||
const
|
const
|
||||||
nimbleVersion* = "0.7.11"
|
nimbleVersion* = "0.7.11"
|
||||||
|
|
|
||||||
59
src/nimblepkg/distros.nim
Normal file
59
src/nimblepkg/distros.nim
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||||
|
# BSD License. Look at license.txt for more info.
|
||||||
|
|
||||||
|
## This module is implicitly imported in NimScript .nimble files.
|
||||||
|
|
||||||
|
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 -a"
|
||||||
|
of Distribution.RedHat:
|
||||||
|
result = "Red Hat" in gorge"uname -a"
|
||||||
|
of Distribution.BSD: result = defined(bsd)
|
||||||
|
|
||||||
|
template detectOs*(d: untyped): bool =
|
||||||
|
detectOsImpl(Distribution.d)
|
||||||
|
|
||||||
|
proc foreignCmd*(cmd: string; requiresSudo=false) =
|
||||||
|
nimscriptapi.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
|
||||||
|
elif detectOs(RedHat):
|
||||||
|
foreignCmd "rpm install " & p, true
|
||||||
|
else:
|
||||||
|
discard
|
||||||
|
|
@ -19,6 +19,9 @@ var
|
||||||
installExt*, bin*: seq[string] = @[] ## Nimble metadata.
|
installExt*, bin*: seq[string] = @[] ## Nimble metadata.
|
||||||
requiresData*: seq[string] = @[] ## The package's dependencies.
|
requiresData*: seq[string] = @[] ## The package's dependencies.
|
||||||
|
|
||||||
|
foreignDeps*: seq[string] = @[] ## The foreign dependencies. Only
|
||||||
|
## exported for 'distros.nim'.
|
||||||
|
|
||||||
proc requires*(deps: varargs[string]) =
|
proc requires*(deps: varargs[string]) =
|
||||||
## Call this to set the list of requirements of your Nimble
|
## Call this to set the list of requirements of your Nimble
|
||||||
## package.
|
## package.
|
||||||
|
|
@ -42,58 +45,3 @@ proc getPkgDir*(): string =
|
||||||
## Returns the package directory containing the .nimble file currently
|
## Returns the package directory containing the .nimble file currently
|
||||||
## being evaluated.
|
## being evaluated.
|
||||||
builtin
|
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
|
|
||||||
|
|
|
||||||
|
|
@ -200,13 +200,21 @@ proc findNimscriptApi(options: Options): string =
|
||||||
|
|
||||||
proc getNimPrefixDir(): string = splitPath(findExe("nim")).head.parentDir
|
proc getNimPrefixDir(): string = splitPath(findExe("nim")).head.parentDir
|
||||||
|
|
||||||
|
when declared(ModuleGraph):
|
||||||
|
var graph: ModuleGraph
|
||||||
|
|
||||||
proc execScript(scriptName: string, flags: StringTableRef,
|
proc execScript(scriptName: string, flags: StringTableRef,
|
||||||
options: Options): PSym =
|
options: Options): PSym =
|
||||||
## Executes the specified script. Returns the script's module symbol.
|
## Executes the specified script. Returns the script's module symbol.
|
||||||
##
|
##
|
||||||
## No clean up is performed and must be done manually!
|
## No clean up is performed and must be done manually!
|
||||||
|
when declared(resetAllModulesHard):
|
||||||
|
# for compatibility with older Nim versions:
|
||||||
if "nimblepkg/nimscriptapi" notin compiler_options.implicitIncludes:
|
if "nimblepkg/nimscriptapi" notin compiler_options.implicitIncludes:
|
||||||
compiler_options.implicitIncludes.add("nimblepkg/nimscriptapi")
|
compiler_options.implicitIncludes.add("nimblepkg/nimscriptapi")
|
||||||
|
else:
|
||||||
|
if "nimblepkg/nimscriptapi" notin compiler_options.implicitImports:
|
||||||
|
compiler_options.implicitImports.add("nimblepkg/nimscriptapi")
|
||||||
|
|
||||||
# Ensure the compiler can find its standard library #220.
|
# Ensure the compiler can find its standard library #220.
|
||||||
compiler_options.gPrefixDir = getNimPrefixDir()
|
compiler_options.gPrefixDir = getNimPrefixDir()
|
||||||
|
|
@ -241,7 +249,7 @@ proc execScript(scriptName: string, flags: StringTableRef,
|
||||||
when declared(resetAllModulesHard):
|
when declared(resetAllModulesHard):
|
||||||
result = makeModule(scriptName)
|
result = makeModule(scriptName)
|
||||||
else:
|
else:
|
||||||
let graph = newModuleGraph()
|
graph = newModuleGraph()
|
||||||
result = graph.makeModule(scriptName)
|
result = graph.makeModule(scriptName)
|
||||||
|
|
||||||
incl(result.flags, sfMainModule)
|
incl(result.flags, sfMainModule)
|
||||||
|
|
@ -301,24 +309,35 @@ proc readPackageInfoFromNims*(scriptName: string, options: Options,
|
||||||
# Execute the nimscript file.
|
# Execute the nimscript file.
|
||||||
let thisModule = execScript(scriptName, nil, options)
|
let thisModule = execScript(scriptName, nil, options)
|
||||||
|
|
||||||
|
when declared(resetAllModulesHard):
|
||||||
|
let apiModule = thisModule
|
||||||
|
else:
|
||||||
|
var apiModule: PSym
|
||||||
|
for i in 0..<graph.modules.len:
|
||||||
|
if graph.modules[i] != nil and
|
||||||
|
graph.modules[i].name.s == "nimscriptapi":
|
||||||
|
apiModule = graph.modules[i]
|
||||||
|
break
|
||||||
|
doAssert apiModule != nil
|
||||||
|
|
||||||
# Check whether an error has occurred.
|
# Check whether an error has occurred.
|
||||||
if msgs.gErrorCounter > 0:
|
if msgs.gErrorCounter > 0:
|
||||||
raise newException(NimbleError, previousMsg)
|
raise newException(NimbleError, previousMsg)
|
||||||
|
|
||||||
# Extract all the necessary fields populated by the nimscript file.
|
# Extract all the necessary fields populated by the nimscript file.
|
||||||
proc getSym(thisModule: PSym, ident: string): PSym =
|
proc getSym(apiModule: PSym, ident: string): PSym =
|
||||||
result = thisModule.tab.strTableGet(getIdent(ident))
|
result = apiModule.tab.strTableGet(getIdent(ident))
|
||||||
if result.isNil:
|
if result.isNil:
|
||||||
raise newException(NimbleError, "Ident not found: " & ident)
|
raise newException(NimbleError, "Ident not found: " & ident)
|
||||||
|
|
||||||
template trivialField(field) =
|
template trivialField(field) =
|
||||||
result.field = getGlobal(getSym(thisModule, astToStr field))
|
result.field = getGlobal(getSym(apiModule, astToStr field))
|
||||||
|
|
||||||
template trivialFieldSeq(field) =
|
template trivialFieldSeq(field) =
|
||||||
result.field.add getGlobalAsSeq(getSym(thisModule, astToStr field))
|
result.field.add getGlobalAsSeq(getSym(apiModule, astToStr field))
|
||||||
|
|
||||||
# keep reasonable default:
|
# keep reasonable default:
|
||||||
let name = getGlobal(thisModule.tab.strTableGet(getIdent"packageName"))
|
let name = getGlobal(apiModule.tab.strTableGet(getIdent"packageName"))
|
||||||
if name.len > 0: result.name = name
|
if name.len > 0: result.name = name
|
||||||
|
|
||||||
trivialField version
|
trivialField version
|
||||||
|
|
@ -333,14 +352,15 @@ proc readPackageInfoFromNims*(scriptName: string, options: Options,
|
||||||
trivialFieldSeq installDirs
|
trivialFieldSeq installDirs
|
||||||
trivialFieldSeq installFiles
|
trivialFieldSeq installFiles
|
||||||
trivialFieldSeq installExt
|
trivialFieldSeq installExt
|
||||||
|
trivialFieldSeq foreignDeps
|
||||||
|
|
||||||
extractRequires(getSym(thisModule, "requiresData"), result.requires)
|
extractRequires(getSym(apiModule, "requiresData"), result.requires)
|
||||||
|
|
||||||
let binSeq = getGlobalAsSeq(getSym(thisModule, "bin"))
|
let binSeq = getGlobalAsSeq(getSym(apiModule, "bin"))
|
||||||
for i in binSeq:
|
for i in binSeq:
|
||||||
result.bin.add(i.addFileExt(ExeExt))
|
result.bin.add(i.addFileExt(ExeExt))
|
||||||
|
|
||||||
let backend = getGlobal(getSym(thisModule, "backend"))
|
let backend = getGlobal(getSym(apiModule, "backend"))
|
||||||
if backend.len == 0:
|
if backend.len == 0:
|
||||||
result.backend = "c"
|
result.backend = "c"
|
||||||
elif cmpIgnoreStyle(backend, "javascript") == 0:
|
elif cmpIgnoreStyle(backend, "javascript") == 0:
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ proc initPackageInfo*(path: string): PackageInfo =
|
||||||
result.installFiles = @[]
|
result.installFiles = @[]
|
||||||
result.installExt = @[]
|
result.installExt = @[]
|
||||||
result.requires = @[]
|
result.requires = @[]
|
||||||
|
result.foreignDeps = @[]
|
||||||
result.bin = @[]
|
result.bin = @[]
|
||||||
result.srcDir = ""
|
result.srcDir = ""
|
||||||
result.binDir = ""
|
result.binDir = ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue