diff --git a/src/nimble.nim b/src/nimble.nim index c5b0491..0300158 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -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 diff --git a/src/nimblepkg/common.nim b/src/nimblepkg/common.nim index 1f5c39a..9d1002d 100644 --- a/src/nimblepkg/common.nim +++ b/src/nimblepkg/common.nim @@ -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 diff --git a/src/nimblepkg/packageinfo.nim b/src/nimblepkg/packageinfo.nim index 9de81ba..cdbe4ff 100644 --- a/src/nimblepkg/packageinfo.nim +++ b/src/nimblepkg/packageinfo.nim @@ -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: diff --git a/src/nimblepkg/packageparser.nim b/src/nimblepkg/packageparser.nim index b860228..3d4a6b4 100644 --- a/src/nimblepkg/packageparser.nim +++ b/src/nimblepkg/packageparser.nim @@ -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. diff --git a/tests/issue289/issue289.nim b/tests/issue289/issue289.nim new file mode 100644 index 0000000..10c5f66 --- /dev/null +++ b/tests/issue289/issue289.nim @@ -0,0 +1 @@ +echo 42 diff --git a/tests/issue289/issue289.nimble b/tests/issue289/issue289.nimble new file mode 100644 index 0000000..ab9aec8 --- /dev/null +++ b/tests/issue289/issue289.nimble @@ -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" + diff --git a/tests/tester.nim b/tests/tester.nim index 2c4be73..266811b 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -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)