From cce58bd9817ff042ca6aa91d42e87cec16d64d05 Mon Sep 17 00:00:00 2001 From: Eugen Minciu Date: Sun, 28 Dec 2014 19:47:14 +0200 Subject: [PATCH 1/5] Add a builddir option. --- src/nimble.nim | 5 +++-- src/nimblepkg/packageinfo.nim | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index 6bb23c8..3436200 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -425,10 +425,11 @@ proc buildFromDir(pkgInfo: TPackageInfo, paths: seq[string]) = var args = "" for path in paths: args.add("--path:\"" & path & "\" ") for bin in pkgInfo.bin: + let outputOpt = pkgInfo.getOutputOption(bin) echo("Building ", pkginfo.name, "/", bin, " using ", pkgInfo.backend, " backend...") - doCmd(getNimBin() & " $# -d:release --noBabelPath $# \"$#\"" % - [pkgInfo.backend, args, realDir / bin.changeFileExt("nim")]) + doCmd(getNimBin() & " $# -d:release --noBabelPath $#$# \"$#\"" % + [pkgInfo.backend, args, outputOpt, realDir / bin.changeFileExt("nim")]) proc saveNimbleMeta(pkgDestDir, url: string, filesInstalled: TSet[string]) = var nimblemeta = %{"url": %url} diff --git a/src/nimblepkg/packageinfo.nim b/src/nimblepkg/packageinfo.nim index 8b3056e..9ac78b0 100644 --- a/src/nimblepkg/packageinfo.nim +++ b/src/nimblepkg/packageinfo.nim @@ -21,6 +21,7 @@ type installExt*: seq[string] requires*: seq[TPkgTuple] bin*: seq[string] + buildDir*: string srcDir*: string backend*: string @@ -56,6 +57,7 @@ proc initPackageInfo(): TPackageInfo = result.requires = @[] result.bin = @[] result.srcDir = "" + result.buildDir = "" result.backend = "c" proc validatePackageInfo(pkgInfo: TPackageInfo, path: string) = @@ -140,6 +142,7 @@ proc readPackageInfo*(path: string): TPackageInfo = of "description": result.description = ev.value of "license": result.license = ev.value of "srcdir": result.srcDir = ev.value + of "builddir": result.buildDir = ev.value of "skipdirs": result.skipDirs.add(ev.value.multiSplit) of "skipfiles": @@ -318,6 +321,14 @@ proc getRealDir*(pkgInfo: TPackageInfo): string = else: result = pkgInfo.mypath.splitFile.dir +proc getOutputOption*(pkgInfo: TPackageInfo, bin: string): string = + ## Returns an output option for the nim compiler if a build directory + ## has been set. + if pkgInfo.buildDir != "": + result = " -o:\"" & pkgInfo.mypath.splitFile.dir / pkgInfo.buildDir / bin & "\"" + else: + result = "" + proc getNameVersion*(pkgpath: string): tuple[name, version: string] = ## Splits ``pkgpath`` in the format ``/home/user/.nimble/pkgs/package-0.1`` ## into ``(packagea, 0.1)`` From 0218c1d493a8a02565bf23e9f1ed168d40dc7519 Mon Sep 17 00:00:00 2001 From: Eugen Minciu Date: Sun, 28 Dec 2014 21:11:35 +0200 Subject: [PATCH 2/5] Add option to build in debug/release mode. --- src/nimble.nim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index 3436200..1b0d9fd 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -419,17 +419,18 @@ proc processDeps(pkginfo: TPackageInfo, options: TOptions): seq[string] = addRevDep(options, i, pkginfo) saveNimbleData(options) -proc buildFromDir(pkgInfo: TPackageInfo, paths: seq[string]) = +proc buildFromDir(pkgInfo: TPackageInfo, paths: seq[string], forRelease: bool) = ## Builds a package as specified by ``pkgInfo``. let realDir = pkgInfo.getRealDir() + let releaseOpt = if forRelease: "-d:release" else: "" var args = "" for path in paths: args.add("--path:\"" & path & "\" ") for bin in pkgInfo.bin: let outputOpt = pkgInfo.getOutputOption(bin) echo("Building ", pkginfo.name, "/", bin, " using ", pkgInfo.backend, " backend...") - doCmd(getNimBin() & " $# -d:release --noBabelPath $#$# \"$#\"" % - [pkgInfo.backend, args, outputOpt, realDir / bin.changeFileExt("nim")]) + doCmd(getNimBin() & " $# $# --noBabelPath $# $# \"$#\"" % + [pkgInfo.backend, releaseOpt, args, outputOpt, realDir / bin.changeFileExt("nim")]) proc saveNimbleMeta(pkgDestDir, url: string, filesInstalled: TSet[string]) = var nimblemeta = %{"url": %url} @@ -480,7 +481,7 @@ proc installFromDir(dir: string, latest: bool, options: TOptions, # Build before removing an existing package (if one exists). This way # if the build fails then the old package will still be installed. - if pkgInfo.bin.len > 0: buildFromDir(pkgInfo, result.paths) + if pkgInfo.bin.len > 0: buildFromDir(pkgInfo, result.paths, true) let versionStr = (if latest: "" else: '-' & pkgInfo.version) let pkgDestDir = pkgsDir / (pkgInfo.name & versionStr) @@ -620,7 +621,7 @@ proc install(packages: seq[TPkgTuple], proc build(options: TOptions) = var pkgInfo = getPkgInfo(getCurrentDir()) let paths = processDeps(pkginfo, options) - buildFromDir(pkgInfo, paths) + buildFromDir(pkgInfo, paths, false) proc search(options: TOptions) = ## Searches for matches in ``options.action.search``. From 70f03b2c9b9df48eb1e33be8aa603721b09297ef Mon Sep 17 00:00:00 2001 From: Eugen Minciu Date: Sun, 28 Dec 2014 21:46:57 +0200 Subject: [PATCH 3/5] Output build to the base directory by default. Make nimble build output to the directory where the .nimble file resides by default. --- src/nimblepkg/packageinfo.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nimblepkg/packageinfo.nim b/src/nimblepkg/packageinfo.nim index 9ac78b0..4e2e59b 100644 --- a/src/nimblepkg/packageinfo.nim +++ b/src/nimblepkg/packageinfo.nim @@ -327,7 +327,7 @@ proc getOutputOption*(pkgInfo: TPackageInfo, bin: string): string = if pkgInfo.buildDir != "": result = " -o:\"" & pkgInfo.mypath.splitFile.dir / pkgInfo.buildDir / bin & "\"" else: - result = "" + result = " -o:\"" & pkgInfo.mypath.splitFile.dir / bin & "\"" proc getNameVersion*(pkgpath: string): tuple[name, version: string] = ## Splits ``pkgpath`` in the format ``/home/user/.nimble/pkgs/package-0.1`` From 6b007e88092f1d36a550a22f786b3a9caa9536f2 Mon Sep 17 00:00:00 2001 From: Eugen Minciu Date: Sun, 28 Dec 2014 21:49:04 +0200 Subject: [PATCH 4/5] Document the binDir and nimble build changes. --- developers.markdown | 3 +++ readme.markdown | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/developers.markdown b/developers.markdown index db66d70..bd29571 100644 --- a/developers.markdown +++ b/developers.markdown @@ -212,6 +212,9 @@ their own packages to it! Take a look at * ``srcDir`` - Specifies the directory which contains the .nim source files. **Default**: The directory in which the .nimble file resides; i.e. root dir of package. +* ``buildDir`` - Specifies the directory which contains the .nim source files. + **Default**: The directory in which the .nimble file resides; i.e. root dir of + package. * ``bin`` - A list of files which should be built separated by commas with no file extension required. This option turns your package into a *binary package*, nimble will build the files specified and install them appropriately. diff --git a/readme.markdown b/readme.markdown index 50619fd..33d17fa 100644 --- a/readme.markdown +++ b/readme.markdown @@ -158,8 +158,12 @@ Similar to the ``install`` command you can specify a version range, for example: ### nimble build The ``build`` command is mostly used by developers who want to test building -their ``.nimble`` package. The ``install`` command calls ``build`` implicitly, -so there is rarely any reason to use this command directly. +their ``.nimble`` package. This command will build the package in debug mode, +without installing anything. The ``install`` command will build the package +in release mode instead. + +If you are a developer willing to produce new Nimble packages please read the +[developers.markdown file](developers.markdown) for detailed information. ### nimble list From 499ce7438f85b91bb9e55a36a6e90be7d33dd20f Mon Sep 17 00:00:00 2001 From: Eugen Minciu Date: Sun, 28 Dec 2014 22:21:24 +0200 Subject: [PATCH 5/5] Fix buildDir documentation. --- developers.markdown | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/developers.markdown b/developers.markdown index bd29571..c29aecc 100644 --- a/developers.markdown +++ b/developers.markdown @@ -211,10 +211,11 @@ their own packages to it! Take a look at Separated by commas. * ``srcDir`` - Specifies the directory which contains the .nim source files. **Default**: The directory in which the .nimble file resides; i.e. root dir of - package. -* ``buildDir`` - Specifies the directory which contains the .nim source files. - **Default**: The directory in which the .nimble file resides; i.e. root dir of - package. + the package. +* ``buildDir`` - Specifies the directory where ``nimble build`` will output + binaries. + **Default**: The directory in which the .nimble file resides; i.e. + root dir of the package. * ``bin`` - A list of files which should be built separated by commas with no file extension required. This option turns your package into a *binary package*, nimble will build the files specified and install them appropriately. @@ -231,4 +232,4 @@ their own packages to it! Take a look at range separated by commas. **Example**: ``nimrod >= 0.9.2, jester``; with this value your package will depend on ``nimrod`` version 0.9.2 or greater and on any version of ``jester``. - \ No newline at end of file +