Implemented `nimble c`.

This commit is contained in:
Dominik Picheta 2015-04-11 21:35:10 +01:00
commit f7114ca788
2 changed files with 72 additions and 14 deletions

View file

@ -29,7 +29,7 @@ the following commands to clone nimble, compile it and then install it.
git clone https://github.com/nim-lang/nimble.git git clone https://github.com/nim-lang/nimble.git
cd nimble cd nimble
nim c -r src/nimble install nim c -r src/nimble install
After these steps nimble should be compiled and installed. You should then add After these steps nimble should be compiled and installed. You should then add
``~/.nimble/bin`` to your ``$PATH``. Updating nimble can then be done by ``~/.nimble/bin`` to your ``$PATH``. Updating nimble can then be done by
executing ``nimble install nimble``. executing ``nimble install nimble``.
@ -118,7 +118,7 @@ Example:
Nimble always fetches and installs the latest version of a package. Note that Nimble always fetches and installs the latest version of a package. Note that
latest version is defined as the latest tagged version in the git (or hg) latest version is defined as the latest tagged version in the git (or hg)
repository, if the package has no tagged versions then the latest commit in the repository, if the package has no tagged versions then the latest commit in the
remote repository will be installed. If you already have that version installed remote repository will be installed. If you already have that version installed
Nimble will ask you whether you wish it to overwrite your local copy. Nimble will ask you whether you wish it to overwrite your local copy.
You can force Nimble to download the latest commit from the package's repo, for You can force Nimble to download the latest commit from the package's repo, for
@ -139,7 +139,7 @@ In this case a version which is greater than ``0.5`` will be installed.
If you don't specify a parameter and there is a ``package.nimble`` file in your If you don't specify a parameter and there is a ``package.nimble`` file in your
current working directory then Nimble will install the package residing in current working directory then Nimble will install the package residing in
the current working directory. This can be useful for developers who are testing the current working directory. This can be useful for developers who are testing
locally their ``.nimble`` files before submitting them to the official package locally their ``.nimble`` files before submitting them to the official package
list. See [developers.markdown](developers.markdown) for more info on this. list. See [developers.markdown](developers.markdown) for more info on this.
A URL to a repository can also be specified, Nimble will automatically detect A URL to a repository can also be specified, Nimble will automatically detect
@ -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
@ -183,7 +193,7 @@ substrings). Example:
tags: library, opengl, math, game tags: library, opengl, math, game
description: OpenGL math library description: OpenGL math library
license: CC0 license: CC0
extmath: extmath:
url: git://github.com/achesak/extmath.nim (git) url: git://github.com/achesak/extmath.nim (git)
tags: library, math, trigonometry tags: library, math, trigonometry

View file

@ -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,19 +197,28 @@ 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 key case result.action.typ
of "help", "h": writeHelp() of actionCompile:
of "version", "v": writeVersion() if val == "":
of "accept", "y": result.forcePrompts = forcePromptYes result.action.compileOptions.add("--" & key)
of "reject", "n": result.forcePrompts = forcePromptNo else:
of "ver": result.queryVersions = true result.action.compileOptions.add("--" & key & ":" & val)
of "installed", "i": result.queryInstalled = true else:
else: discard case key
of "help", "h": writeHelp()
of "version", "v": writeVersion()
of "accept", "y": result.forcePrompts = forcePromptYes
of "reject", "n": result.forcePrompts = forcePromptNo
of "ver": result.queryVersions = true
of "installed", "i": result.queryInstalled = true
else: discard
of cmdEnd: assert(false) # cannot happen of cmdEnd: assert(false) # cannot happen
if result.action.typ == actionNil: if result.action.typ == actionNil:
writeHelp() writeHelp()
@ -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: