This commit is contained in:
tormund 2016-05-23 14:52:50 +03:00
commit 07e9ac0972

View file

@ -369,100 +369,102 @@ proc installFromDir(dir: string, latest: bool, options: Options,
# Dependencies need to be processed before the creation of the pkg dir. # Dependencies need to be processed before the creation of the pkg dir.
result.paths = processDeps(pkginfo, deps_options) result.paths = processDeps(pkginfo, deps_options)
if not options.depsOnly: if options.depsOnly:
echo("Installing ", pkginfo.name, "-", pkginfo.version) result.pkg = pkgInfo
return result
# Build before removing an existing package (if one exists). This way echo("Installing ", pkginfo.name, "-", pkginfo.version)
# if the build fails then the old package will still be installed.
if pkgInfo.bin.len > 0: buildFromDir(pkgInfo, result.paths, true)
let versionStr = (if latest: "" else: '-' & pkgInfo.version) # Build before removing an existing package (if one exists). This way
let pkgDestDir = pkgsDir / (pkgInfo.name & versionStr) # if the build fails then the old package will still be installed.
if existsDir(pkgDestDir) and existsFile(pkgDestDir / "nimblemeta.json"): if pkgInfo.bin.len > 0: buildFromDir(pkgInfo, result.paths, true)
if not options.prompt(pkgInfo.name & versionStr &
" already exists. Overwrite?"):
quit(QuitSuccess)
removePkgDir(pkgDestDir, options)
# Remove any symlinked binaries
for bin in pkgInfo.bin:
# TODO: Check that this binary belongs to the package being installed.
when defined(windows):
removeFile(binDir / bin.changeFileExt("cmd"))
removeFile(binDir / bin.changeFileExt(""))
# TODO: Remove this later.
# Remove .bat file too from previous installs.
removeFile(binDir / bin.changeFileExt("bat"))
else:
removeFile(binDir / bin)
## Will contain a list of files which have been installed. let versionStr = (if latest: "" else: '-' & pkgInfo.version)
var filesInstalled: HashSet[string] let pkgDestDir = pkgsDir / (pkgInfo.name & versionStr)
if existsDir(pkgDestDir) and existsFile(pkgDestDir / "nimblemeta.json"):
if not options.prompt(pkgInfo.name & versionStr &
" already exists. Overwrite?"):
quit(QuitSuccess)
removePkgDir(pkgDestDir, options)
# Remove any symlinked binaries
for bin in pkgInfo.bin:
# TODO: Check that this binary belongs to the package being installed.
when defined(windows):
removeFile(binDir / bin.changeFileExt("cmd"))
removeFile(binDir / bin.changeFileExt(""))
# TODO: Remove this later.
# Remove .bat file too from previous installs.
removeFile(binDir / bin.changeFileExt("bat"))
else:
removeFile(binDir / bin)
createDir(pkgDestDir) ## Will contain a list of files which have been installed.
if pkgInfo.bin.len > 0: var filesInstalled: HashSet[string]
createDir(binDir)
# Copy all binaries and files that are not skipped
filesInstalled = copyFilesRec(realDir, realDir, pkgDestDir, options,
pkgInfo)
# Set file permissions to +x for all binaries built,
# and symlink them on *nix OS' to $nimbleDir/bin/
for bin in pkgInfo.bin:
if not existsFile(pkgDestDir / bin):
filesInstalled.incl copyFileD(pkgInfo.getOutputDir(bin),
pkgDestDir / bin)
let currentPerms = getFilePermissions(pkgDestDir / bin) createDir(pkgDestDir)
setFilePermissions(pkgDestDir / bin, currentPerms + {fpUserExec}) if pkgInfo.bin.len > 0:
let cleanBin = bin.extractFilename createDir(binDir)
when defined(unix): # Copy all binaries and files that are not skipped
# TODO: Verify that we are removing an old bin of this package, not filesInstalled = copyFilesRec(realDir, realDir, pkgDestDir, options,
# some other package's binary! pkgInfo)
if existsFile(binDir / cleanBin): removeFile(binDir / cleanBin) # Set file permissions to +x for all binaries built,
echo("Creating symlink: ", pkgDestDir / bin, " -> ", binDir / cleanBin) # and symlink them on *nix OS' to $nimbleDir/bin/
createSymlink(pkgDestDir / bin, binDir / cleanBin) for bin in pkgInfo.bin:
elif defined(windows): if not existsFile(pkgDestDir / bin):
# There is a bug on XP, described here: filesInstalled.incl copyFileD(pkgInfo.getOutputDir(bin),
# http://stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called pkgDestDir / bin)
# But this workaround brokes code page on newer systems, so we need to detect OS version
var osver = OSVERSIONINFO()
osver.dwOSVersionInfoSize = cast[DWORD](sizeof(OSVERSIONINFO))
if GetVersionExA(osver) == WINBOOL(0):
raise newException(NimbleError,
"Can't detect OS version: GetVersionExA call failed")
let fixChcp = osver.dwMajorVersion <= 5
let dest = binDir / cleanBin.changeFileExt("cmd") let currentPerms = getFilePermissions(pkgDestDir / bin)
echo("Creating stub: ", pkgDestDir / bin, " -> ", dest) setFilePermissions(pkgDestDir / bin, currentPerms + {fpUserExec})
var contents = "@" let cleanBin = bin.extractFilename
if options.config.chcp: when defined(unix):
if fixChcp: # TODO: Verify that we are removing an old bin of this package, not
contents.add "chcp 65001 > nul && " # some other package's binary!
else: contents.add "chcp 65001 > nul\n@" if existsFile(binDir / cleanBin): removeFile(binDir / cleanBin)
contents.add "\"" & pkgDestDir / bin & "\" %*\n" echo("Creating symlink: ", pkgDestDir / bin, " -> ", binDir / cleanBin)
writeFile(dest, contents) createSymlink(pkgDestDir / bin, binDir / cleanBin)
# For bash on Windows (Cygwin/Git bash). elif defined(windows):
let bashDest = dest.changeFileExt("") # There is a bug on XP, described here:
echo("Creating Cygwin stub: ", pkgDestDir / bin, " -> ", bashDest) # http://stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called
writeFile(bashDest, "\"$(cygpath '" & pkgDestDir / bin & "')\" \"$@\"\l") # But this workaround brokes code page on newer systems, so we need to detect OS version
else: var osver = OSVERSIONINFO()
{.error: "Sorry, your platform is not supported.".} osver.dwOSVersionInfoSize = cast[DWORD](sizeof(OSVERSIONINFO))
else: if GetVersionExA(osver) == WINBOOL(0):
filesInstalled = copyFilesRec(realDir, realDir, pkgDestDir, options, raise newException(NimbleError,
pkgInfo) "Can't detect OS version: GetVersionExA call failed")
let fixChcp = osver.dwMajorVersion <= 5
# Save a nimblemeta.json file. let dest = binDir / cleanBin.changeFileExt("cmd")
saveNimbleMeta(pkgDestDir, url, filesInstalled) echo("Creating stub: ", pkgDestDir / bin, " -> ", dest)
var contents = "@"
if options.config.chcp:
if fixChcp:
contents.add "chcp 65001 > nul && "
else: contents.add "chcp 65001 > nul\n@"
contents.add "\"" & pkgDestDir / bin & "\" %*\n"
writeFile(dest, contents)
# For bash on Windows (Cygwin/Git bash).
let bashDest = dest.changeFileExt("")
echo("Creating Cygwin stub: ", pkgDestDir / bin, " -> ", bashDest)
writeFile(bashDest, "\"$(cygpath '" & pkgDestDir / bin & "')\" \"$@\"\l")
else:
{.error: "Sorry, your platform is not supported.".}
else:
filesInstalled = copyFilesRec(realDir, realDir, pkgDestDir, options,
pkgInfo)
# Save the nimble data (which might now contain reverse deps added in # Save a nimblemeta.json file.
# processDeps). saveNimbleMeta(pkgDestDir, url, filesInstalled)
saveNimbleData(options)
echo(pkgInfo.name & " installed successfully.") # Save the nimble data (which might now contain reverse deps added in
# Return the paths to the dependencies of this package. # processDeps).
result.paths.add pkgDestDir saveNimbleData(options)
# Return the paths to the dependencies of this package.
result.paths.add pkgDestDir
result.pkg = pkgInfo result.pkg = pkgInfo
echo(pkgInfo.name & " installed successfully.")
proc getNimbleTempDir(): string = proc getNimbleTempDir(): string =
## Returns a path to a temporary directory. ## Returns a path to a temporary directory.