Fixes aporia install. See nim-lang/aporia#136. Refs #311.

This commit is contained in:
Dominik Picheta 2017-01-08 18:15:36 +01:00
commit d78af3acf1
3 changed files with 38 additions and 34 deletions

View file

@ -227,7 +227,7 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[string] =
"dependencies for $1@$2" % [pkginfo.name, pkginfo.specialVersion], "dependencies for $1@$2" % [pkginfo.name, pkginfo.specialVersion],
priority = HighPriority) priority = HighPriority)
let pkglist = getInstalledPkgsMin(options.getPkgsDir(), options) var pkgList = getInstalledPkgsMin(options.getPkgsDir(), options)
var reverseDeps: seq[tuple[name, version: string]] = @[] var reverseDeps: seq[tuple[name, version: string]] = @[]
for dep in pkginfo.requires: for dep in pkginfo.requires:
if dep.name == "nimrod" or dep.name == "nim": if dep.name == "nimrod" or dep.name == "nim":
@ -255,6 +255,9 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[string] =
result.add(paths) result.add(paths)
pkg = installedPkg # For addRevDep pkg = installedPkg # For addRevDep
# This package has been installed so we add it to our pkgList.
pkgList.add((pkg, readMetaData(pkg.getRealDir())))
else: else:
display("Info:", "Dependency on $1 already satisfied" % $dep, display("Info:", "Dependency on $1 already satisfied" % $dep,
priority = HighPriority) priority = HighPriority)
@ -441,9 +444,10 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
filesInstalled.incl copyFileD(file, dest) filesInstalled.incl copyFileD(file, dest)
# Copy the .nimble file. # Copy the .nimble file.
let dest = changeRoot(pkgInfo.mypath.splitFile.dir, pkgDestDir, let dest = changeRoot(pkgInfo.myPath.splitFile.dir, pkgDestDir,
pkgInfo.mypath) pkgInfo.myPath)
filesInstalled.incl copyFileD(pkgInfo.mypath, dest) filesInstalled.incl copyFileD(pkgInfo.myPath, dest)
pkgInfo.myPath = dest
var binariesInstalled = initSet[string]() var binariesInstalled = initSet[string]()
if pkgInfo.bin.len > 0: if pkgInfo.bin.len > 0:
@ -518,6 +522,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
# Return the paths to the dependencies of this package. # Return the paths to the dependencies of this package.
result.paths.add pkgDestDir result.paths.add pkgDestDir
result.pkg = pkgInfo result.pkg = pkgInfo
result.pkg.isInstalled = true
display("Success:", pkgInfo.name & " installed successfully.", display("Success:", pkgInfo.name & " installed successfully.",
Success, HighPriority) Success, HighPriority)

View file

@ -51,7 +51,8 @@ proc isSpecial*(ver: Version): bool =
proc `<`*(ver: Version, ver2: Version): bool = proc `<`*(ver: Version, ver2: Version): bool =
# Handling for special versions such as "#head" or "#branch". # Handling for special versions such as "#head" or "#branch".
if ver.isSpecial or ver2.isSpecial: if ver.isSpecial or ver2.isSpecial:
return false # TODO: This may need to be reverted. See #311.
return ($ver2).normalize == "#head" and ($ver).normalize != "#head"
# Handling for normal versions such as "0.1.0" or "1.0". # Handling for normal versions such as "0.1.0" or "1.0".
var sVer = string(ver).split('.') var sVer = string(ver).split('.')
@ -103,32 +104,23 @@ proc `==`*(range1: VersionRange, range2: VersionRange): bool =
of verAny: true of verAny: true
proc withinRange*(ver: Version, ran: VersionRange): bool = proc withinRange*(ver: Version, ran: VersionRange): bool =
if ver.isSpecial: case ran.kind
case ran.kind of verLater:
of verLater, verEarlier, verEqLater, verEqEarlier, verEq, verIntersect: return ver > ran.ver
return false of verEarlier:
of verSpecial: return ver < ran.ver
return ver == ran.spe of verEqLater:
of verAny: return ver >= ran.ver
return true of verEqEarlier:
else: return ver <= ran.ver
case ran.kind of verEq:
of verLater: return ver == ran.ver
return ver > ran.ver of verSpecial:
of verEarlier: return ver == ran.spe
return ver < ran.ver of verIntersect:
of verEqLater: return withinRange(ver, ran.verILeft) and withinRange(ver, ran.verIRight)
return ver >= ran.ver of verAny:
of verEqEarlier: return true
return ver <= ran.ver
of verEq:
return ver == ran.ver
of verSpecial:
return false
of verIntersect:
return withinRange(ver, ran.verILeft) and withinRange(ver, ran.verIRight)
of verAny:
return true
proc contains*(ran: VersionRange, ver: Version): bool = proc contains*(ran: VersionRange, ver: Version): bool =
return withinRange(ver, ran) return withinRange(ver, ran)
@ -342,9 +334,10 @@ when isMainModule:
doAssert newVersion("#head") in parseVersionRange("#head") doAssert newVersion("#head") in parseVersionRange("#head")
# TODO: It may be worth changing this in the future, although we can't be # We assume that #head > 0.1.0, in practice this shouldn't be a problem.
# certain that #head is in fact newer than v0.1.0. doAssert(newVersion("#head") > newVersion("0.1.0"))
doAssert(not(newVersion("#head") > newVersion("0.1.0"))) doAssert(not(newVersion("#head") > newVersion("#head")))
doAssert(withinRange(newVersion("#head"), parseVersionRange(">= 0.5.0")))
# An empty version range should give verAny # An empty version range should give verAny
doAssert parseVersionRange("").kind == verAny doAssert parseVersionRange("").kind == verAny

View file

@ -42,6 +42,12 @@ proc inLines(lines: seq[string], line: string): bool =
for i in lines: for i in lines:
if line.normalize in i.normalize: return true if line.normalize in i.normalize: return true
test "picks #head when looking for packages":
cd "versionClashes" / "aporiaScenario":
check execNimble("install", "-y", "--verbose").exitCode == QuitSuccess
check execNimble("remove", "aporiascenario", "-y").exitCode == QuitSuccess
check execNimble("remove", "packagea", "-y").exitCode == QuitSuccess
test "can distinguish package reading in nimbleDir vs. other dirs (#304)": test "can distinguish package reading in nimbleDir vs. other dirs (#304)":
cd "issue304" / "package-test": cd "issue304" / "package-test":
check execNimble("tasks").exitCode == QuitSuccess check execNimble("tasks").exitCode == QuitSuccess