Implements binary package symlinking to $babelDir/bin.
This fixes the issues outlined http://forum.nimrod-code.org/t/163; Windows support is still TODO.
This commit is contained in:
parent
f2a47a00a1
commit
b56262010b
3 changed files with 37 additions and 13 deletions
43
babel.nim
43
babel.nim
|
|
@ -113,8 +113,8 @@ proc doCmd(cmd: string) =
|
||||||
quit("Execution failed with exit code " & $exitCode, QuitFailure)
|
quit("Execution failed with exit code " & $exitCode, QuitFailure)
|
||||||
|
|
||||||
proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
||||||
## Used for library-only packages. Copies all the required files, skips
|
## Copies all the required files, skips files specified in the .babel file
|
||||||
## files specified in the .babel file.
|
## (TPackageInfo).
|
||||||
for kind, file in walkDir(currentDir):
|
for kind, file in walkDir(currentDir):
|
||||||
if kind == pcDir:
|
if kind == pcDir:
|
||||||
var skip = false
|
var skip = false
|
||||||
|
|
@ -122,7 +122,7 @@ proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
||||||
if samePaths(file, origDir / ignoreDir):
|
if samePaths(file, origDir / ignoreDir):
|
||||||
skip = true
|
skip = true
|
||||||
break
|
break
|
||||||
let thisDir = splitPath(file).tail
|
let thisDir = splitPath(file).tail
|
||||||
assert thisDir != ""
|
assert thisDir != ""
|
||||||
if thisDir[0] == '.': skip = true
|
if thisDir[0] == '.': skip = true
|
||||||
if thisDir == "nimcache": skip = true
|
if thisDir == "nimcache": skip = true
|
||||||
|
|
@ -142,6 +142,11 @@ proc copyFilesRec(origDir, currentDir, dest: string, pkgInfo: TPackageInfo) =
|
||||||
skip = true
|
skip = true
|
||||||
break
|
break
|
||||||
|
|
||||||
|
for ignoreExt in pkgInfo.skipExt:
|
||||||
|
if file.splitFile.ext == ('.' & ignoreExt):
|
||||||
|
skip = true
|
||||||
|
break
|
||||||
|
|
||||||
if not skip:
|
if not skip:
|
||||||
copyFileD(file, changeRoot(origDir, dest, file))
|
copyFileD(file, changeRoot(origDir, dest, file))
|
||||||
|
|
||||||
|
|
@ -181,14 +186,19 @@ proc buildFromDir(dir: string, paths: seq[string]) =
|
||||||
|
|
||||||
proc installFromDir(dir: string, latest: bool): string =
|
proc installFromDir(dir: string, latest: bool): string =
|
||||||
## Returns where package has been installed to. If package is a binary,
|
## Returns where package has been installed to. If package is a binary,
|
||||||
## ``""`` is returned.
|
## ``""`` is returned. 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)
|
var pkgInfo = getPkgInfo(dir)
|
||||||
let pkgDestDir = libsDir / (pkgInfo.name &
|
let pkgDestDir = libsDir / (pkgInfo.name &
|
||||||
(if latest: "" else: '-' & pkgInfo.version))
|
(if latest: "" else: '-' & pkgInfo.version))
|
||||||
if existsDir(pkgDestDir):
|
if existsDir(pkgDestDir):
|
||||||
if not prompt("Package already exists. Overwrite?"):
|
if not prompt(pkgInfo.name & " already exists. Overwrite?"):
|
||||||
quit(QuitSuccess)
|
quit(QuitSuccess)
|
||||||
removeDir(pkgDestDir)
|
removeDir(pkgDestDir)
|
||||||
|
# Remove any symlinked binaries
|
||||||
|
for bin in pkgInfo.bin:
|
||||||
|
# TODO: Check that this binary belongs to the package being installed.
|
||||||
|
removeFile(binDir / bin)
|
||||||
|
|
||||||
echo("Installing ", pkginfo.name, "-", pkginfo.version)
|
echo("Installing ", pkginfo.name, "-", pkginfo.version)
|
||||||
|
|
||||||
|
|
@ -199,19 +209,28 @@ proc installFromDir(dir: string, latest: bool): string =
|
||||||
if pkgInfo.bin.len > 0:
|
if pkgInfo.bin.len > 0:
|
||||||
buildFromDir(dir, paths)
|
buildFromDir(dir, paths)
|
||||||
createDir(binDir)
|
createDir(binDir)
|
||||||
|
# Copy all binaries and files that are not skipped
|
||||||
|
var nPkgInfo = pkgInfo
|
||||||
|
nPkgInfo.skipExt.add("nim") # Implicitly skip .nim files
|
||||||
|
copyFilesRec(dir, dir, pkgDestDir, nPkgInfo)
|
||||||
|
# Set file permissions to +x for all binaries built,
|
||||||
|
# and symlink them on *nix OS' to $babelDir/bin/
|
||||||
for bin in pkgInfo.bin:
|
for bin in pkgInfo.bin:
|
||||||
copyFileD(dir / bin, binDir / bin)
|
let currentPerms = getFilePermissions(pkgDestDir / bin)
|
||||||
let currentPerms = getFilePermissions(binDir / bin)
|
setFilePermissions(pkgDestDir / bin, currentPerms + {fpUserExec})
|
||||||
setFilePermissions(binDir / bin, currentPerms + {fpUserExec})
|
when defined(unix):
|
||||||
# Copy the .babel to lib/
|
doCmd("ln -s \"" & pkgDestDir / bin & "\" " & binDir / bin)
|
||||||
let babelFile = findBabelFile(dir)
|
elif defined(windows):
|
||||||
copyFileD(babelFile, changeRoot(dir, pkgDestDir, babelFile))
|
{.error: "TODO WINDOWS".}
|
||||||
|
else:
|
||||||
|
{.error: "Sorry, your platform is not supported.".}
|
||||||
result = ""
|
result = ""
|
||||||
else:
|
else:
|
||||||
copyFilesRec(dir, dir, pkgDestDir, pkgInfo)
|
copyFilesRec(dir, dir, pkgDestDir, pkgInfo)
|
||||||
echo(pkgInfo.name & " installed successfully.")
|
|
||||||
result = pkgDestDir
|
result = pkgDestDir
|
||||||
|
|
||||||
|
echo(pkgInfo.name & " installed successfully.")
|
||||||
|
|
||||||
proc getTagsList(dir: string): seq[string] =
|
proc getTagsList(dir: string): seq[string] =
|
||||||
let output = execProcess("cd \"" & dir & "\" && git tag")
|
let output = execProcess("cd \"" & dir & "\" && git tag")
|
||||||
if output.len > 0:
|
if output.len > 0:
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ type
|
||||||
license*: string
|
license*: string
|
||||||
skipDirs*: seq[string]
|
skipDirs*: seq[string]
|
||||||
skipFiles*: seq[string]
|
skipFiles*: seq[string]
|
||||||
|
skipExt*: seq[string]
|
||||||
requires*: seq[tuple[name: string, ver: PVersionRange]]
|
requires*: seq[tuple[name: string, ver: PVersionRange]]
|
||||||
bin*: seq[string]
|
bin*: seq[string]
|
||||||
|
|
||||||
|
|
@ -34,6 +35,7 @@ proc initPackageInfo(): TPackageInfo =
|
||||||
result.license = ""
|
result.license = ""
|
||||||
result.skipDirs = @[]
|
result.skipDirs = @[]
|
||||||
result.skipFiles = @[]
|
result.skipFiles = @[]
|
||||||
|
result.skipExt = @[]
|
||||||
result.requires = @[]
|
result.requires = @[]
|
||||||
result.bin = @[]
|
result.bin = @[]
|
||||||
|
|
||||||
|
|
@ -89,6 +91,8 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
||||||
result.skipDirs.add(ev.value.split(','))
|
result.skipDirs.add(ev.value.split(','))
|
||||||
of "skipfiles":
|
of "skipfiles":
|
||||||
result.skipFiles.add(ev.value.split(','))
|
result.skipFiles.add(ev.value.split(','))
|
||||||
|
of "skipext":
|
||||||
|
result.skipExt.add(ev.value.split(','))
|
||||||
of "bin":
|
of "bin":
|
||||||
result.bin = ev.value.split(',')
|
result.bin = ev.value.split(',')
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,5 @@
|
||||||
* A way to install specific versions of a package.
|
* A way to install specific versions of a package.
|
||||||
* more package download methods
|
* more package download methods
|
||||||
* Allow for proper versions of packages to download. Reuse 'version' field
|
* Allow for proper versions of packages to download. Reuse 'version' field
|
||||||
in packages.json.
|
in packages.json.
|
||||||
|
* Install only .nim files when installing library packages?
|
||||||
Loading…
Add table
Add a link
Reference in a new issue