From 3ddb48bc085ac6ed4a3aa3520094f2a6d4168bb7 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 26 Jun 2013 23:24:11 +0100 Subject: [PATCH] Implemented a 'rootDir' key. --- babel.nim | 23 ++++++++++++++--------- packageinfo.nim | 14 +++++++++++++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/babel.nim b/babel.nim index 8eb488c..da70e66 100644 --- a/babel.nim +++ b/babel.nim @@ -203,6 +203,9 @@ proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) = copyFileD(file, changeRoot(origDir, dest, file)) + copyFileD(pkgInfo.mypath, + changeRoot(pkgInfo.mypath.splitFile.dir, dest, pkgInfo.mypath)) + proc install(packages: seq[String], verRange: PVersionRange): string {.discardable.} proc processDeps(pkginfo: TPackageInfo): seq[string] = ## Verifies and installs dependencies. @@ -225,20 +228,22 @@ proc processDeps(pkginfo: TPackageInfo): seq[string] = echo("Dependency already satisfied.") result.add(pkg.mypath.splitFile.dir) -proc buildFromDir(dir: string, paths: seq[string]) = - ## Builds a package which resides in ``dir`` - var pkgInfo = getPkgInfo(dir) +proc buildFromDir(pkgInfo: TPackageInfo, paths: seq[string]) = + ## Builds a package as specified by ``pkgInfo``. + let realDir = pkgInfo.getRealDir() 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 & dir / bin.changeFileExt("nim")) + doCmd("nimrod c -d:release " & args & realDir / bin.changeFileExt("nim")) proc installFromDir(dir: string, latest: bool): string = ## Returns where package has been installed to. ## The return value of this function is used by ## ``processDeps`` to gather a list of paths to pass to the nimrod compiler. var pkgInfo = getPkgInfo(dir) + let realDir = pkgInfo.getRealDir() + let pkgDestDir = pkgsDir / (pkgInfo.name & (if latest: "" else: '-' & pkgInfo.version)) if existsDir(pkgDestDir): @@ -260,15 +265,15 @@ proc installFromDir(dir: string, latest: bool): string = createDir(pkgDestDir) if pkgInfo.bin.len > 0: - buildFromDir(dir, paths) + buildFromDir(pkgInfo, paths) createDir(binDir) # Copy all binaries and files that are not skipped - copyFilesRec(dir, dir, pkgDestDir, pkgInfo) + copyFilesRec(realDir, realDir, pkgDestDir, pkgInfo) # Set file permissions to +x for all binaries built, # and symlink them on *nix OS' to $babelDir/bin/ for bin in pkgInfo.bin: if not existsFile(pkgDestDir / bin): - copyFileD(dir / bin, pkgDestDir / bin) + copyFileD(realDir / bin, pkgDestDir / bin) let currentPerms = getFilePermissions(pkgDestDir / bin) setFilePermissions(pkgDestDir / bin, currentPerms + {fpUserExec}) @@ -282,7 +287,7 @@ proc installFromDir(dir: string, latest: bool): string = else: {.error: "Sorry, your platform is not supported.".} else: - copyFilesRec(dir, dir, pkgDestDir, pkgInfo) + copyFilesRec(realDir, realDir, pkgDestDir, pkgInfo) result = pkgDestDir echo(pkgInfo.name & " installed successfully.") @@ -361,7 +366,7 @@ proc install(packages: seq[String], verRange: PVersionRange): string = proc build = var pkgInfo = getPkgInfo(getCurrentDir()) let paths = processDeps(pkginfo) - buildFromDir(getCurrentDir(), paths) + buildFromDir(pkgInfo, paths) proc search(action: TAction) = assert action.typ == ActionSearch diff --git a/packageinfo.nim b/packageinfo.nim index 30f4ca3..32bae60 100644 --- a/packageinfo.nim +++ b/packageinfo.nim @@ -18,6 +18,7 @@ type installExt*: seq[string] requires*: seq[tuple[name: string, ver: PVersionRange]] bin*: seq[string] + rootDir*: string TPackage* = object name*: string @@ -44,6 +45,7 @@ proc initPackageInfo(): TPackageInfo = result.installExt = @[] result.requires = @[] result.bin = @[] + result.rootDir = "" proc validatePackageInfo(pkgInfo: TPackageInfo, path: string) = if pkgInfo.name == "": @@ -93,6 +95,7 @@ proc readPackageInfo*(path: string): TPackageInfo = of "author": result.author = ev.value of "description": result.description = ev.value of "license": result.license = ev.value + of "rootdir": result.rootDir = ev.value of "skipdirs": result.skipDirs.add(ev.value.split(',')) of "skipfiles": @@ -188,8 +191,9 @@ proc findBabelFile*(dir: string): string = proc getPkgInfo*(dir: string): TPackageInfo = ## Find the .babel file in ``dir`` and parses it, returning a TPackageInfo. let babelFile = findBabelFile(dir) + echo(dir) if babelFile == "": - quit("Specified directory does not contain a .babel file.", QuitFailure) + raise newException(EBabel, "Specified directory does not contain a .babel file.") result = readPackageInfo(babelFile) proc getInstalledPkgs*(libsDir: string): seq[TPackageInfo] = @@ -220,6 +224,14 @@ proc findPkg*(pkglist: seq[TPackageInfo], r = pkg result = true +proc getRealDir*(pkgInfo: TPackageInfo): string = + ## Returns the ``pkgInfo.rootDir`` or the .mypath directory if package does + ## not specify the root dir. + if pkgInfo.rootDir != "": + result = pkgInfo.mypath.splitFile.dir / pkgInfo.rootDir + else: + result = pkgInfo.mypath.splitFile.dir + proc echoPackage*(pkg: TPackage) = echo(pkg.name & ":") echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")")