Implemented a 'rootDir' key.
This commit is contained in:
parent
19b5d3072f
commit
3ddb48bc08
2 changed files with 27 additions and 10 deletions
23
babel.nim
23
babel.nim
|
|
@ -203,6 +203,9 @@ proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
||||||
|
|
||||||
copyFileD(file, changeRoot(origDir, dest, file))
|
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 install(packages: seq[String], verRange: PVersionRange): string {.discardable.}
|
||||||
proc processDeps(pkginfo: TPackageInfo): seq[string] =
|
proc processDeps(pkginfo: TPackageInfo): seq[string] =
|
||||||
## Verifies and installs dependencies.
|
## Verifies and installs dependencies.
|
||||||
|
|
@ -225,20 +228,22 @@ proc processDeps(pkginfo: TPackageInfo): seq[string] =
|
||||||
echo("Dependency already satisfied.")
|
echo("Dependency already satisfied.")
|
||||||
result.add(pkg.mypath.splitFile.dir)
|
result.add(pkg.mypath.splitFile.dir)
|
||||||
|
|
||||||
proc buildFromDir(dir: string, paths: seq[string]) =
|
proc buildFromDir(pkgInfo: TPackageInfo, paths: seq[string]) =
|
||||||
## Builds a package which resides in ``dir``
|
## Builds a package as specified by ``pkgInfo``.
|
||||||
var pkgInfo = getPkgInfo(dir)
|
let realDir = pkgInfo.getRealDir()
|
||||||
var args = ""
|
var args = ""
|
||||||
for path in paths: args.add("--path:" & path & " ")
|
for path in paths: args.add("--path:" & path & " ")
|
||||||
for bin in pkgInfo.bin:
|
for bin in pkgInfo.bin:
|
||||||
echo("Building ", pkginfo.name, "/", 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 =
|
proc installFromDir(dir: string, latest: bool): string =
|
||||||
## Returns where package has been installed to.
|
## Returns where package has been installed to.
|
||||||
## The return value of this function is used by
|
## The return value of this function is used by
|
||||||
## ``processDeps`` to gather a list of paths to pass to the nimrod compiler.
|
## ``processDeps`` to gather a list of paths to pass to the nimrod compiler.
|
||||||
var pkgInfo = getPkgInfo(dir)
|
var pkgInfo = getPkgInfo(dir)
|
||||||
|
let realDir = pkgInfo.getRealDir()
|
||||||
|
|
||||||
let pkgDestDir = pkgsDir / (pkgInfo.name &
|
let pkgDestDir = pkgsDir / (pkgInfo.name &
|
||||||
(if latest: "" else: '-' & pkgInfo.version))
|
(if latest: "" else: '-' & pkgInfo.version))
|
||||||
if existsDir(pkgDestDir):
|
if existsDir(pkgDestDir):
|
||||||
|
|
@ -260,15 +265,15 @@ proc installFromDir(dir: string, latest: bool): string =
|
||||||
|
|
||||||
createDir(pkgDestDir)
|
createDir(pkgDestDir)
|
||||||
if pkgInfo.bin.len > 0:
|
if pkgInfo.bin.len > 0:
|
||||||
buildFromDir(dir, paths)
|
buildFromDir(pkgInfo, paths)
|
||||||
createDir(binDir)
|
createDir(binDir)
|
||||||
# Copy all binaries and files that are not skipped
|
# 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,
|
# Set file permissions to +x for all binaries built,
|
||||||
# and symlink them on *nix OS' to $babelDir/bin/
|
# and symlink them on *nix OS' to $babelDir/bin/
|
||||||
for bin in pkgInfo.bin:
|
for bin in pkgInfo.bin:
|
||||||
if not existsFile(pkgDestDir / bin):
|
if not existsFile(pkgDestDir / bin):
|
||||||
copyFileD(dir / bin, pkgDestDir / bin)
|
copyFileD(realDir / bin, pkgDestDir / bin)
|
||||||
|
|
||||||
let currentPerms = getFilePermissions(pkgDestDir / bin)
|
let currentPerms = getFilePermissions(pkgDestDir / bin)
|
||||||
setFilePermissions(pkgDestDir / bin, currentPerms + {fpUserExec})
|
setFilePermissions(pkgDestDir / bin, currentPerms + {fpUserExec})
|
||||||
|
|
@ -282,7 +287,7 @@ proc installFromDir(dir: string, latest: bool): string =
|
||||||
else:
|
else:
|
||||||
{.error: "Sorry, your platform is not supported.".}
|
{.error: "Sorry, your platform is not supported.".}
|
||||||
else:
|
else:
|
||||||
copyFilesRec(dir, dir, pkgDestDir, pkgInfo)
|
copyFilesRec(realDir, realDir, pkgDestDir, pkgInfo)
|
||||||
result = pkgDestDir
|
result = pkgDestDir
|
||||||
|
|
||||||
echo(pkgInfo.name & " installed successfully.")
|
echo(pkgInfo.name & " installed successfully.")
|
||||||
|
|
@ -361,7 +366,7 @@ proc install(packages: seq[String], verRange: PVersionRange): string =
|
||||||
proc build =
|
proc build =
|
||||||
var pkgInfo = getPkgInfo(getCurrentDir())
|
var pkgInfo = getPkgInfo(getCurrentDir())
|
||||||
let paths = processDeps(pkginfo)
|
let paths = processDeps(pkginfo)
|
||||||
buildFromDir(getCurrentDir(), paths)
|
buildFromDir(pkgInfo, paths)
|
||||||
|
|
||||||
proc search(action: TAction) =
|
proc search(action: TAction) =
|
||||||
assert action.typ == ActionSearch
|
assert action.typ == ActionSearch
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ type
|
||||||
installExt*: seq[string]
|
installExt*: seq[string]
|
||||||
requires*: seq[tuple[name: string, ver: PVersionRange]]
|
requires*: seq[tuple[name: string, ver: PVersionRange]]
|
||||||
bin*: seq[string]
|
bin*: seq[string]
|
||||||
|
rootDir*: string
|
||||||
|
|
||||||
TPackage* = object
|
TPackage* = object
|
||||||
name*: string
|
name*: string
|
||||||
|
|
@ -44,6 +45,7 @@ proc initPackageInfo(): TPackageInfo =
|
||||||
result.installExt = @[]
|
result.installExt = @[]
|
||||||
result.requires = @[]
|
result.requires = @[]
|
||||||
result.bin = @[]
|
result.bin = @[]
|
||||||
|
result.rootDir = ""
|
||||||
|
|
||||||
proc validatePackageInfo(pkgInfo: TPackageInfo, path: string) =
|
proc validatePackageInfo(pkgInfo: TPackageInfo, path: string) =
|
||||||
if pkgInfo.name == "":
|
if pkgInfo.name == "":
|
||||||
|
|
@ -93,6 +95,7 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
||||||
of "author": result.author = ev.value
|
of "author": result.author = ev.value
|
||||||
of "description": result.description = ev.value
|
of "description": result.description = ev.value
|
||||||
of "license": result.license = ev.value
|
of "license": result.license = ev.value
|
||||||
|
of "rootdir": result.rootDir = ev.value
|
||||||
of "skipdirs":
|
of "skipdirs":
|
||||||
result.skipDirs.add(ev.value.split(','))
|
result.skipDirs.add(ev.value.split(','))
|
||||||
of "skipfiles":
|
of "skipfiles":
|
||||||
|
|
@ -188,8 +191,9 @@ proc findBabelFile*(dir: string): string =
|
||||||
proc getPkgInfo*(dir: string): TPackageInfo =
|
proc getPkgInfo*(dir: string): TPackageInfo =
|
||||||
## Find the .babel file in ``dir`` and parses it, returning a TPackageInfo.
|
## Find the .babel file in ``dir`` and parses it, returning a TPackageInfo.
|
||||||
let babelFile = findBabelFile(dir)
|
let babelFile = findBabelFile(dir)
|
||||||
|
echo(dir)
|
||||||
if babelFile == "":
|
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)
|
result = readPackageInfo(babelFile)
|
||||||
|
|
||||||
proc getInstalledPkgs*(libsDir: string): seq[TPackageInfo] =
|
proc getInstalledPkgs*(libsDir: string): seq[TPackageInfo] =
|
||||||
|
|
@ -220,6 +224,14 @@ proc findPkg*(pkglist: seq[TPackageInfo],
|
||||||
r = pkg
|
r = pkg
|
||||||
result = true
|
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) =
|
proc echoPackage*(pkg: TPackage) =
|
||||||
echo(pkg.name & ":")
|
echo(pkg.name & ":")
|
||||||
echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")")
|
echo(" url: " & pkg.url & " (" & pkg.downloadMethod & ")")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue