From 2a8d3082d46fca837af3a069ff58d7e484fa584a Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 16 Aug 2013 15:48:20 +0100 Subject: [PATCH] Implemented 'backend' option. --- babel.nim | 6 ++++-- packageinfo.nim | 8 ++++++++ readme.markdown | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/babel.nim b/babel.nim index 213c717..dd4f684 100644 --- a/babel.nim +++ b/babel.nim @@ -211,8 +211,10 @@ proc buildFromDir(pkgInfo: TPackageInfo, paths: seq[string]) = var args = "" for path in paths: args.add("--path:" & path & " ") for bin in pkgInfo.bin: - echo("Building ", pkginfo.name, "/", bin, "...") - doCmd("nimrod c -d:release " & args & realDir / bin.changeFileExt("nim")) + echo("Building ", pkginfo.name, "/", bin, " using ", pkgInfo.backend, + " backend...") + doCmd("nimrod $# -d:release $#" % + [pkgInfo.backend, args & realDir / bin.changeFileExt("nim")]) proc installFromDir(dir: string, latest: bool): string = ## Returns where package has been installed to. diff --git a/packageinfo.nim b/packageinfo.nim index 7160a9e..bdb6c07 100644 --- a/packageinfo.nim +++ b/packageinfo.nim @@ -19,6 +19,7 @@ type requires*: seq[tuple[name: string, ver: PVersionRange]] bin*: seq[string] srcDir*: string + backend*: string TPackage* = object name*: string @@ -46,6 +47,7 @@ proc initPackageInfo(): TPackageInfo = result.requires = @[] result.bin = @[] result.srcDir = "" + result.backend = "c" proc validatePackageInfo(pkgInfo: TPackageInfo, path: string) = if pkgInfo.name == "": @@ -58,6 +60,8 @@ proc validatePackageInfo(pkgInfo: TPackageInfo, path: string) = quit("Incorrect .babel file: " & path & " does not contain a description field.") if pkgInfo.license == "": quit("Incorrect .babel file: " & path & " does not contain a license field.") + if pkgInfo.backend notin ["c", "cc", "objc", "cpp", "js"]: + raise newException(EBabel, "'" & pkgInfo.backend & "' is an invalid backend.") proc parseRequires(req: string): tuple[name: string, ver: PVersionRange] = try: @@ -111,6 +115,10 @@ proc readPackageInfo*(path: string): TPackageInfo = of "bin": for i in ev.value.split(','): result.bin.add(i.addFileExt(ExeExt)) + of "backend": + result.backend = ev.value.toLower() + case result.backend.normalize + of "javascript": result.backend = "js" else: quit("Invalid field: " & ev.key, QuitFailure) of "deps", "dependencies": diff --git a/readme.markdown b/readme.markdown index da3dc62..5085d4b 100644 --- a/readme.markdown +++ b/readme.markdown @@ -172,6 +172,10 @@ the package after checking out the latest version. * ``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*, babel will build the files specified and install them appropriately. +* ``backend`` - Specifies the backend which will be used to build the files + listed in ``bin``. Possible values include: ``c``, ``cc``, ``cpp``, ``objc``, + ``js``. + **Default**: c ### [Deps]/[Dependencies]