Fixes version conflicts when building between special&non-special.

Refs #289. Aporia still cannot be installed. In addition,
the myVersion vs. version should be refactored into version vs.
specialVersion.
This commit is contained in:
Dominik Picheta 2016-12-27 00:42:05 +00:00
commit d192de6511
7 changed files with 47 additions and 11 deletions

View file

@ -296,12 +296,13 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[string] =
# in the path.
var pkgsInPath: StringTableRef = newStringTable(modeCaseSensitive)
for p in result:
let (name, version) = getNameVersion(p)
if pkgsInPath.hasKey(name) and pkgsInPath[name] != version:
let pkgInfo = getPkgInfo(p, options)
if pkgsInPath.hasKey(pkgInfo.name) and
pkgsInPath[pkgInfo.name] != pkgInfo.myVersion:
raise newException(NimbleError,
"Cannot satisfy the dependency on $1 $2 and $1 $3" %
[name, version, pkgsInPath[name]])
pkgsInPath[name] = version
[pkgInfo.name, pkgInfo.myVersion, pkgsInPath[pkgInfo.name]])
pkgsInPath[pkgInfo.name] = pkgInfo.myVersion
# We add the reverse deps to the JSON file here because we don't want
# them added if the above errorenous condition occurs

View file

@ -14,14 +14,17 @@ when not defined(nimscript):
BuildFailed* = object of NimbleError
PackageInfo* = object
mypath*: string ## The path of this .nimble file
myPath*: string ## The path of this .nimble file
## The version specified in the .nimble file.Assuming info is non-minimal,
## it will always be a non-special version such as '0.1.4'
myVersion*: string
isNimScript*: bool ## Determines if this pkg info was read from a nims file
isMinimal*: bool
isInstalled*: bool ## Determines if the pkg this info belongs to is installed
postHooks*: HashSet[string] ## Useful to know so that Nimble doesn't execHook unnecessarily
preHooks*: HashSet[string]
name*: string
version*: string
version*: string ## Either `myVersion` or a special version such as #head.
author*: string
description*: string
license*: string

View file

@ -21,7 +21,8 @@ type
url*: string
proc initPackageInfo*(path: string): PackageInfo =
result.mypath = path
result.myPath = path
result.myVersion = ""
result.preHooks.init()
result.postHooks.init()
# reasonable default:

View file

@ -248,6 +248,8 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
## times on the same ``nf`` shouldn't require re-evaluation of the Nimble
## file.
assert fileExists(nf)
# Check the cache.
if options.pkgInfoCache.hasKey(nf):
return options.pkgInfoCache[nf]
@ -286,6 +288,7 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
raise newException(NimbleError, msg)
# Validate version ahead of time, we will be potentially overwriting it soon.
result.myVersion = result.version
validateVersion(result.version)
# The package directory name may include a "special" version
@ -301,11 +304,11 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
# Validate the rest of the package info last.
validatePackageInfo(result, options)
proc getPkgInfo*(dir: string, options: Options): PackageInfo =
## Find the .nimble file in ``dir`` and parses it, returning a PackageInfo.
let nimbleFile = findNimbleFile(dir, true)
proc getPkgInfoFromFile*(file: NimbleFile, options: Options): PackageInfo =
## Reads the specified .nimble file and returns its data as a PackageInfo
## object. Any validation errors are handled and displayed as warnings.
try:
result = readPackageInfo(nimbleFile, options)
result = readPackageInfo(file, options)
except ValidationError:
let exc = (ref ValidationError)(getCurrentException())
if exc.warnAll:
@ -314,6 +317,11 @@ proc getPkgInfo*(dir: string, options: Options): PackageInfo =
else:
raise
proc getPkgInfo*(dir: string, options: Options): PackageInfo =
## Find the .nimble file in ``dir`` and parses it, returning a PackageInfo.
let nimbleFile = findNimbleFile(dir, true)
getPkgInfoFromFile(nimbleFile, options)
proc getInstalledPkgs*(libsDir: string, options: Options):
seq[tuple[pkginfo: PackageInfo, meta: MetaData]] =
## Gets a list of installed packages.

View file

@ -0,0 +1 @@
echo 42

View file

@ -0,0 +1,14 @@
# Package
version = "0.1.0"
author = "Dominik Picheta"
description = "Package reproducing issues depending on #head and concrete version of the same package."
license = "MIT"
bin = @["issue289"]
# Dependencies
requires "nim >= 0.15.3", "https://github.com/nimble-test/packagea.git 0.6.0"
requires "https://github.com/nimble-test/packagea.git#head"

View file

@ -41,6 +41,14 @@ proc inLines(lines: seq[string], line: string): bool =
for i in lines:
if line.normalize in i.normalize: return true
test "can build with #head and versioned package (#289)":
# Clear nimble dir.
removeDir(installDir)
createDir(installDir)
cd "issue289":
check execNimble(["install", "-y"]).exitCode == QuitSuccess
test "can validate package structure (#144)":
# Clear nimble dir.
removeDir(installDir)