Fixes #286.
This commit is contained in:
parent
26755c0183
commit
ff82fc2536
1 changed files with 29 additions and 8 deletions
|
|
@ -338,7 +338,15 @@ proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string], forRelease: bool) =
|
||||||
raise newException(BuildFailed, "Build failed for package: " &
|
raise newException(BuildFailed, "Build failed for package: " &
|
||||||
pkgInfo.name)
|
pkgInfo.name)
|
||||||
|
|
||||||
proc saveNimbleMeta(pkgDestDir, url, vcsRevision: string, filesInstalled: HashSet[string]) =
|
proc saveNimbleMeta(pkgDestDir, url, vcsRevision: string,
|
||||||
|
filesInstalled, bins: HashSet[string]) =
|
||||||
|
## Saves the specified data into a ``nimblemeta.json`` file inside
|
||||||
|
## ``pkgDestDir``.
|
||||||
|
##
|
||||||
|
## filesInstalled - A list of absolute paths to files which have been
|
||||||
|
## installed.
|
||||||
|
## bins - A list of binary filenames which have been installed for this
|
||||||
|
## package.
|
||||||
var nimblemeta = %{"url": %url}
|
var nimblemeta = %{"url": %url}
|
||||||
if not vcsRevision.isNil:
|
if not vcsRevision.isNil:
|
||||||
nimblemeta["vcsRevision"] = %vcsRevision
|
nimblemeta["vcsRevision"] = %vcsRevision
|
||||||
|
|
@ -346,6 +354,10 @@ proc saveNimbleMeta(pkgDestDir, url, vcsRevision: string, filesInstalled: HashSe
|
||||||
nimblemeta["files"] = files
|
nimblemeta["files"] = files
|
||||||
for file in filesInstalled:
|
for file in filesInstalled:
|
||||||
files.add(%changeRoot(pkgDestDir, "", file))
|
files.add(%changeRoot(pkgDestDir, "", file))
|
||||||
|
let binaries = newJArray()
|
||||||
|
nimblemeta["binaries"] = binaries
|
||||||
|
for bin in bins:
|
||||||
|
binaries.add(%bin)
|
||||||
writeFile(pkgDestDir / "nimblemeta.json", $nimblemeta)
|
writeFile(pkgDestDir / "nimblemeta.json", $nimblemeta)
|
||||||
|
|
||||||
proc removePkgDir(dir: string, options: Options) =
|
proc removePkgDir(dir: string, options: Options) =
|
||||||
|
|
@ -366,6 +378,15 @@ proc removePkgDir(dir: string, options: Options) =
|
||||||
else:
|
else:
|
||||||
display("Warning:", ("Cannot completely remove $1. Files not installed " &
|
display("Warning:", ("Cannot completely remove $1. Files not installed " &
|
||||||
"by nimble are present.") % dir, Warning, HighPriority)
|
"by nimble are present.") % dir, Warning, HighPriority)
|
||||||
|
|
||||||
|
# Remove binaries.
|
||||||
|
if nimblemeta.hasKey("binaries"):
|
||||||
|
for binary in nimblemeta["binaries"]:
|
||||||
|
removeFile(options.getBinDir() / binary.str)
|
||||||
|
else:
|
||||||
|
display("Warning:", ("Cannot completely remove $1. Binary symlinks may " &
|
||||||
|
"have been left over in $2.") %
|
||||||
|
[dir, options.getBinDir()])
|
||||||
except OSError, JsonParsingError:
|
except OSError, JsonParsingError:
|
||||||
display("Warning", "Unable to read nimblemeta.json: " &
|
display("Warning", "Unable to read nimblemeta.json: " &
|
||||||
getCurrentExceptionMsg(), Warning, HighPriority)
|
getCurrentExceptionMsg(), Warning, HighPriority)
|
||||||
|
|
@ -436,9 +457,6 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
removeFile(binDir / bin.changeFileExt("cmd"))
|
removeFile(binDir / bin.changeFileExt("cmd"))
|
||||||
removeFile(binDir / bin.changeFileExt(""))
|
removeFile(binDir / bin.changeFileExt(""))
|
||||||
# TODO: Remove this later.
|
|
||||||
# Remove .bat file too from previous installs.
|
|
||||||
removeFile(binDir / bin.changeFileExt("bat"))
|
|
||||||
else:
|
else:
|
||||||
removeFile(binDir / bin)
|
removeFile(binDir / bin)
|
||||||
|
|
||||||
|
|
@ -456,6 +474,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
||||||
pkgInfo.mypath)
|
pkgInfo.mypath)
|
||||||
filesInstalled.incl copyFileD(pkgInfo.mypath, dest)
|
filesInstalled.incl copyFileD(pkgInfo.mypath, dest)
|
||||||
|
|
||||||
|
var binariesInstalled = initSet[string]()
|
||||||
if pkgInfo.bin.len > 0:
|
if pkgInfo.bin.len > 0:
|
||||||
# Make sure ~/.nimble/bin directory is created.
|
# Make sure ~/.nimble/bin directory is created.
|
||||||
createDir(binDir)
|
createDir(binDir)
|
||||||
|
|
@ -470,12 +489,10 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
||||||
setFilePermissions(pkgDestDir / bin, currentPerms + {fpUserExec})
|
setFilePermissions(pkgDestDir / bin, currentPerms + {fpUserExec})
|
||||||
let cleanBin = bin.extractFilename
|
let cleanBin = bin.extractFilename
|
||||||
when defined(unix):
|
when defined(unix):
|
||||||
# TODO: Verify that we are removing an old bin of this package, not
|
|
||||||
# some other package's binary!
|
|
||||||
if existsFile(binDir / cleanBin): removeFile(binDir / cleanBin)
|
|
||||||
display("Creating", "symlink: $1 -> $2" %
|
display("Creating", "symlink: $1 -> $2" %
|
||||||
[pkgDestDir / bin, binDir / cleanBin], priority = MediumPriority)
|
[pkgDestDir / bin, binDir / cleanBin], priority = MediumPriority)
|
||||||
createSymlink(pkgDestDir / bin, binDir / cleanBin)
|
createSymlink(pkgDestDir / bin, binDir / cleanBin)
|
||||||
|
binariesInstalled.incl(cleanBin)
|
||||||
elif defined(windows):
|
elif defined(windows):
|
||||||
# There is a bug on XP, described here:
|
# There is a bug on XP, described here:
|
||||||
# http://stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called
|
# http://stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called
|
||||||
|
|
@ -487,6 +504,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
||||||
"Can't detect OS version: GetVersionExA call failed")
|
"Can't detect OS version: GetVersionExA call failed")
|
||||||
let fixChcp = osver.dwMajorVersion <= 5
|
let fixChcp = osver.dwMajorVersion <= 5
|
||||||
|
|
||||||
|
# Create cmd.exe/powershell stub.
|
||||||
let dest = binDir / cleanBin.changeFileExt("cmd")
|
let dest = binDir / cleanBin.changeFileExt("cmd")
|
||||||
display("Creating", "stub: $1 -> $2" % [pkgDestDir / bin, dest],
|
display("Creating", "stub: $1 -> $2" % [pkgDestDir / bin, dest],
|
||||||
priority = MediumPriority)
|
priority = MediumPriority)
|
||||||
|
|
@ -497,18 +515,21 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
|
||||||
else: contents.add "chcp 65001 > nul\n@"
|
else: contents.add "chcp 65001 > nul\n@"
|
||||||
contents.add "\"" & pkgDestDir / bin & "\" %*\n"
|
contents.add "\"" & pkgDestDir / bin & "\" %*\n"
|
||||||
writeFile(dest, contents)
|
writeFile(dest, contents)
|
||||||
|
binariesInstalled.incl(dest.extractFilename)
|
||||||
# For bash on Windows (Cygwin/Git bash).
|
# For bash on Windows (Cygwin/Git bash).
|
||||||
let bashDest = dest.changeFileExt("")
|
let bashDest = dest.changeFileExt("")
|
||||||
display("Creating", "Cygwin stub: $1 -> $2" %
|
display("Creating", "Cygwin stub: $1 -> $2" %
|
||||||
[pkgDestDir / bin, bashDest], priority = MediumPriority)
|
[pkgDestDir / bin, bashDest], priority = MediumPriority)
|
||||||
writeFile(bashDest, "\"" & pkgDestDir / bin & "\" \"$@\"\n")
|
writeFile(bashDest, "\"" & pkgDestDir / bin & "\" \"$@\"\n")
|
||||||
|
binariesInstalled.incl(bashDest.extractFilename)
|
||||||
else:
|
else:
|
||||||
{.error: "Sorry, your platform is not supported.".}
|
{.error: "Sorry, your platform is not supported.".}
|
||||||
|
|
||||||
let vcsRevision = vcsRevisionInDir(realDir)
|
let vcsRevision = vcsRevisionInDir(realDir)
|
||||||
|
|
||||||
# Save a nimblemeta.json file.
|
# Save a nimblemeta.json file.
|
||||||
saveNimbleMeta(pkgDestDir, url, vcsRevision, filesInstalled)
|
saveNimbleMeta(pkgDestDir, url, vcsRevision, filesInstalled,
|
||||||
|
binariesInstalled)
|
||||||
|
|
||||||
# Save the nimble data (which might now contain reverse deps added in
|
# Save the nimble data (which might now contain reverse deps added in
|
||||||
# processDeps).
|
# processDeps).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue