Implemented `nimble c`.
This commit is contained in:
parent
0349c396a0
commit
f7114ca788
2 changed files with 72 additions and 14 deletions
|
|
@ -161,6 +161,16 @@ The ``build`` command is mostly used by developers who want to test building
|
||||||
their ``.nimble`` package. The ``install`` command calls ``build`` implicitly,
|
their ``.nimble`` package. The ``install`` command calls ``build`` implicitly,
|
||||||
so there is rarely any reason to use this command directly.
|
so there is rarely any reason to use this command directly.
|
||||||
|
|
||||||
|
### nimble c
|
||||||
|
|
||||||
|
The ``c`` (or ``compile``, ``js``, ``cc``, ``cpp``) command can be used by
|
||||||
|
developers to compile individual modules inside their package. All options
|
||||||
|
passed to Nimble will also be passed to the Nim compiler during compilation.
|
||||||
|
|
||||||
|
Nimble will use the backend specified in the package's ``.nimble`` file if
|
||||||
|
the command ``c`` or ``compile`` is specified. The more specific ``js``, ``cc``,
|
||||||
|
``cpp`` can be used to override that.
|
||||||
|
|
||||||
### nimble list
|
### nimble list
|
||||||
|
|
||||||
The ``list`` command will display the known list of packages available for
|
The ``list`` command will display the known list of packages available for
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ type
|
||||||
|
|
||||||
ActionType = enum
|
ActionType = enum
|
||||||
actionNil, actionUpdate, actionInit, actionInstall, actionSearch,
|
actionNil, actionUpdate, actionInit, actionInstall, actionSearch,
|
||||||
actionList, actionBuild, actionPath, actionUninstall
|
actionList, actionBuild, actionPath, actionUninstall, actionCompile
|
||||||
|
|
||||||
Action = object
|
Action = object
|
||||||
case typ: ActionType
|
case typ: ActionType
|
||||||
|
|
@ -38,7 +38,11 @@ type
|
||||||
search: seq[string] # Search string.
|
search: seq[string] # Search string.
|
||||||
of actionInit:
|
of actionInit:
|
||||||
projName: string
|
projName: string
|
||||||
else:nil
|
of actionCompile:
|
||||||
|
file: string
|
||||||
|
backend: string
|
||||||
|
compileOptions: seq[string]
|
||||||
|
else: nil
|
||||||
|
|
||||||
ForcePrompt = enum
|
ForcePrompt = enum
|
||||||
dontForcePrompt, forcePromptYes, forcePromptNo
|
dontForcePrompt, forcePromptYes, forcePromptNo
|
||||||
|
|
@ -52,6 +56,8 @@ Commands:
|
||||||
init [pkgname] Initializes a new Nimble project.
|
init [pkgname] Initializes a new Nimble project.
|
||||||
uninstall [pkgname, ...] Uninstalls a list of packages.
|
uninstall [pkgname, ...] Uninstalls a list of packages.
|
||||||
build Builds a package.
|
build Builds a package.
|
||||||
|
c, cc, js [opts, ...] f.nim Builds a file inside a package. Passes options
|
||||||
|
to the Nim compiler.
|
||||||
update [url] Updates package list. A package list URL can
|
update [url] Updates package list. A package list URL can
|
||||||
be optionally specified.
|
be optionally specified.
|
||||||
search [--ver] pkg/tag Searches for a specified package. Search is
|
search [--ver] pkg/tag Searches for a specified package. Search is
|
||||||
|
|
@ -148,6 +154,12 @@ proc parseCmdLine(): Options =
|
||||||
result.action.packages = @[]
|
result.action.packages = @[]
|
||||||
of "build":
|
of "build":
|
||||||
result.action.typ = actionBuild
|
result.action.typ = actionBuild
|
||||||
|
of "c", "compile", "js", "cpp", "cc":
|
||||||
|
result.action.typ = actionCompile
|
||||||
|
result.action.compileOptions = @[]
|
||||||
|
result.action.file = ""
|
||||||
|
if key == "c" or key == "compile": result.action.backend = ""
|
||||||
|
else: result.action.backend = key
|
||||||
of "init":
|
of "init":
|
||||||
result.action.typ = actionInit
|
result.action.typ = actionInit
|
||||||
result.action.projName = ""
|
result.action.projName = ""
|
||||||
|
|
@ -185,11 +197,20 @@ proc parseCmdLine(): Options =
|
||||||
raise newException(NimbleError,
|
raise newException(NimbleError,
|
||||||
"Can only initialize one package at a time.")
|
"Can only initialize one package at a time.")
|
||||||
result.action.projName = key
|
result.action.projName = key
|
||||||
|
of actionCompile:
|
||||||
|
result.action.file = key
|
||||||
of actionList, actionBuild:
|
of actionList, actionBuild:
|
||||||
writeHelp()
|
writeHelp()
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
of cmdLongOption, cmdShortOption:
|
of cmdLongOption, cmdShortOption:
|
||||||
|
case result.action.typ
|
||||||
|
of actionCompile:
|
||||||
|
if val == "":
|
||||||
|
result.action.compileOptions.add("--" & key)
|
||||||
|
else:
|
||||||
|
result.action.compileOptions.add("--" & key & ":" & val)
|
||||||
|
else:
|
||||||
case key
|
case key
|
||||||
of "help", "h": writeHelp()
|
of "help", "h": writeHelp()
|
||||||
of "version", "v": writeVersion()
|
of "version", "v": writeVersion()
|
||||||
|
|
@ -640,6 +661,31 @@ proc build(options: Options) =
|
||||||
let paths = processDeps(pkginfo, options)
|
let paths = processDeps(pkginfo, options)
|
||||||
buildFromDir(pkgInfo, paths)
|
buildFromDir(pkgInfo, paths)
|
||||||
|
|
||||||
|
proc compile(options: Options) =
|
||||||
|
var pkgInfo = getPkgInfo(getCurrentDir())
|
||||||
|
let paths = processDeps(pkginfo, options)
|
||||||
|
let realDir = pkgInfo.getRealDir()
|
||||||
|
|
||||||
|
var args = ""
|
||||||
|
for path in paths: args.add("--path:\"" & path & "\" ")
|
||||||
|
for option in options.action.compileOptions:
|
||||||
|
args.add(option & " ")
|
||||||
|
|
||||||
|
let bin = options.action.file
|
||||||
|
let backend =
|
||||||
|
if options.action.backend.len > 0:
|
||||||
|
options.action.backend
|
||||||
|
else:
|
||||||
|
pkgInfo.backend
|
||||||
|
|
||||||
|
if bin == "":
|
||||||
|
raise newException(NimbleError, "You need to specify a file to compile.")
|
||||||
|
|
||||||
|
echo("Compiling ", bin, " (", pkgInfo.name, ") using ", backend,
|
||||||
|
" backend...")
|
||||||
|
doCmd(getNimBin() & " $# --noBabelPath $# \"$#\"" %
|
||||||
|
[backend, args, bin])
|
||||||
|
|
||||||
proc search(options: Options) =
|
proc search(options: Options) =
|
||||||
## Searches for matches in ``options.action.search``.
|
## Searches for matches in ``options.action.search``.
|
||||||
##
|
##
|
||||||
|
|
@ -855,6 +901,8 @@ proc doAction(options: Options) =
|
||||||
listPaths(options)
|
listPaths(options)
|
||||||
of actionBuild:
|
of actionBuild:
|
||||||
build(options)
|
build(options)
|
||||||
|
of actionCompile:
|
||||||
|
compile(options)
|
||||||
of actionInit:
|
of actionInit:
|
||||||
init(options)
|
init(options)
|
||||||
of actionNil:
|
of actionNil:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue