From fe21329f3d657539fb007483ab3536b406814c71 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Sat, 1 Sep 2018 23:01:16 +0100 Subject: [PATCH] Fixes #531. Fixes #393. Replaces #465. --- src/nimble.nim | 25 ++++++++----------------- src/nimblepkg/packageinfo.nim | 13 +++++++++++-- tests/tester.nim | 22 ++++++++++++++++------ 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index 66f0607..49232f8 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -190,11 +190,6 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[PackageInfo] = else: display("Info:", "Dependency on $1 already satisfied" % $dep, priority = HighPriority) - if pkg.isLinked: - # TODO (#393): This can be optimised since the .nimble-link files have - # a secondary line that specifies the srcDir. - pkg = pkg.toFullInfo(options) - result.add(pkg) # Process the dependencies of this dependency. result.add(processDeps(pkg.toFullInfo(options), options)) @@ -627,23 +622,19 @@ proc listPaths(options: Options) = raise newException(NimbleError, "A package name needs to be specified") var errors = 0 + let pkgs = getInstalledPkgsMin(options.getPkgsDir(), options) for name, version in options.action.packages.items: var installed: seq[VersionAndPath] = @[] # There may be several, list all available ones and sort by version. - for kind, path in walkDir(options.getPkgsDir): - if kind != pcDir or not path.startsWith(options.getPkgsDir / name & "-"): - continue - - var nimbleFile = findNimbleFile(path, false) - if nimbleFile.existsFile: - var pkgInfo = getPkgInfo(path, options) + for x in pkgs.items(): + let + pName = x.pkginfo.name + pVer = x.pkginfo.specialVersion + if name == pName: var v: VersionAndPath - v.version = newVersion(pkgInfo.specialVersion) - v.path = pkgInfo.getRealDir() + v.version = newVersion(pVer) + v.path = x.pkginfo.getRealDir() installed.add(v) - else: - display("Warning:", "No .nimble file found for " & path, Warning, - MediumPriority) if installed.len > 0: sort(installed, cmp[VersionAndPath], Descending) diff --git a/src/nimblepkg/packageinfo.nim b/src/nimblepkg/packageinfo.nim index 6306840..a9e2b97 100644 --- a/src/nimblepkg/packageinfo.nim +++ b/src/nimblepkg/packageinfo.nim @@ -336,8 +336,17 @@ proc getInstalledPkgsMin*(libsDir: string, options: Options): pkg.specialVersion = version pkg.isMinimal = true pkg.isInstalled = true - pkg.isLinked = - cmpPaths(nimbleFile.splitFile().dir, path) != 0 + let nimbleFileDir = nimbleFile.splitFile().dir + pkg.isLinked = cmpPaths(nimbleFileDir, path) != 0 + + # Read the package's 'srcDir' (this is stored in the .nimble-link so + # we can easily grab it) + if pkg.isLinked: + let nimbleLinkPath = path / name.addFileExt("nimble-link") + let realSrcPath = readNimbleLink(nimbleLinkPath).packageDir + assert realSrcPath.startsWith(nimbleFileDir) + pkg.srcDir = realSrcPath.replace(nimbleFileDir) + pkg.srcDir.removePrefix(DirSep) result.add((pkg, meta)) proc withinRange*(pkgInfo: PackageInfo, verRange: VersionRange): bool = diff --git a/tests/tester.nim b/tests/tester.nim index 6f7b549..efcb619 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -595,8 +595,8 @@ suite "develop feature": check fileExists(path) let split = readFile(path).processOutput() check split.len == 2 - check split[0].endsWith("develop/hybrid/hybrid.nimble") - check split[1].endsWith("develop/hybrid") + check split[0].endsWith("develop" / "hybrid" / "hybrid.nimble") + check split[1].endsWith("develop" / "hybrid") test "can develop with srcDir": cd "develop/srcdirtest": @@ -610,11 +610,11 @@ suite "develop feature": check fileExists(path) let split = readFile(path).processOutput() check split.len == 2 - check split[0].endsWith("develop/srcdirtest/srcdirtest.nimble") - check split[1].endsWith("develop/srcdirtest/src") + check split[0].endsWith("develop" / "srcdirtest" / "srcdirtest.nimble") + check split[1].endsWith("develop" / "srcdirtest" / "src") cd "develop/dependent": - let (output, exitCode) = execNimble("c", "-r", "src/dependent.nim") + let (output, exitCode) = execNimble("c", "-r", "src" / "dependent.nim") checkpoint output check(output.processOutput.inLines("hello")) check exitCode == QuitSuccess @@ -644,10 +644,20 @@ suite "develop feature": check exitCode == QuitSuccess (output, exitCode) = execNimble("path", "srcdirtest") + checkpoint output check exitCode == QuitSuccess check output.strip() == getCurrentDir() / "src" +suite "path command": + test "can get correct path for srcDir (#531)": + check execNimble("uninstall", "srcdirtest", "-y").exitCode == QuitSuccess + cd "develop/srcdirtest": + let (output, exitCode) = execNimble("install", "-y") + check exitCode == QuitSuccess + let (output, exitCode) = execNimble("path", "srcdirtest") + check output.strip() == installDir / "pkgs" / "srcdirtest-1.0" + suite "test command": test "Runs passing unit tests": cd "testCommand/testsPass": @@ -735,4 +745,4 @@ suite "Module tests": test "cli": cd "..": - check execCmdEx("nim c -r src/nimblepkg/cli").exitCode == QuitSuccess \ No newline at end of file + check execCmdEx("nim c -r src/nimblepkg/cli").exitCode == QuitSuccess