From 5a739b4c03a2edadf123eb669e4fadfacf9c6adc Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Fri, 8 Sep 2017 17:42:11 +0300 Subject: [PATCH 1/4] Fixes #403 --- src/nimble.nim | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index 883468a..a3d0096 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -615,15 +615,23 @@ proc listPaths(options: Options) = if kind != pcDir or not path.startsWith(options.getPkgsDir / name): continue - let - nimbleFile = path / name.addFileExt("nimble") - hasSpec = nimbleFile.existsFile + var nimbleFile = path / name.addFileExt("nimble") + var nimbleLinkTargetPath: string + if not nimbleFile.existsFile: + let nimbleLinkFile = path / name.addFileExt("nimble-link") + if fileExists(nimbleLinkFile): + let lns = readFile(nimbleLinkFile).splitLines() + nimbleFile = lns[0] + nimbleLinkTargetPath = lns[1] - if hasSpec: + if nimbleFile.existsFile: var pkgInfo = getPkgInfo(path, options) var v: VersionAndPath v.version = newVersion(pkgInfo.specialVersion) - v.path = options.getPkgsDir / (pkgInfo.name & '-' & pkgInfo.specialVersion) + if nimbleLinkTargetPath.len == 0: + v.path = options.getPkgsDir / (pkgInfo.name & '-' & pkgInfo.specialVersion) + else: + v.path = nimbleLinkTargetPath installed.add(v) else: display("Warning:", "No .nimble file found for " & path, Warning, From 9068e8e43a1bc2d2f250d3ce43d408073c159095 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Sat, 9 Sep 2017 23:15:08 +0300 Subject: [PATCH 2/4] Added a test --- tests/tester.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/tester.nim b/tests/tester.nim index 582e5ac..51328ea 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -560,6 +560,17 @@ suite "develop feature": let (_, exitCode) = execNimble("develop", "-y", url) check exitCode == QuitSuccess + test "nimble path points to develop": + cd "develop/srcdirtest": + var (output, exitCode) = execNimble("develop") + checkpoint output + check exitCode == QuitSuccess + + (output, exitCode) = execNimble("path", "srcdirtest") + checkpoint output + check exitCode == QuitSuccess + check output.strip() == getCurrentDir() / "src" + suite "test command": test "Runs passing unit tests": cd "testCommand/testsPass": From 88b4a9ed8a4833b9830180d0d6412ae95250a86d Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Sat, 9 Sep 2017 23:33:31 +0300 Subject: [PATCH 3/4] Introduced NimbleLink object with its read/write routines --- src/nimble.nim | 10 +++++----- src/nimblepkg/packageinfo.nim | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index a3d0096..9b9de0b 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -620,9 +620,9 @@ proc listPaths(options: Options) = if not nimbleFile.existsFile: let nimbleLinkFile = path / name.addFileExt("nimble-link") if fileExists(nimbleLinkFile): - let lns = readFile(nimbleLinkFile).splitLines() - nimbleFile = lns[0] - nimbleLinkTargetPath = lns[1] + let lnk = readNimbleLink(nimbleLinkFile) + nimbleFile = lnk.nimbleFilePath + nimbleLinkTargetPath = lnk.packageDir if nimbleFile.existsFile: var pkgInfo = getPkgInfo(path, options) @@ -873,9 +873,9 @@ proc developFromDir(dir: string, options: Options) = # need to be read. This will mean that users will need to re-run # `nimble develop` if they change their `srcDir` but I think it's a worthy # compromise. - let contents = pkgInfo.myPath & "\n" & pkgInfo.getRealDir() let nimbleLinkPath = pkgDestDir / pkgInfo.name.addFileExt("nimble-link") - writeFile(nimbleLinkPath, contents) + writeNimbleLink(nimbleLinkPath, + NimbleLink(nimbleFilePath: pkgInfo.myPath, packageDir: pkgInfo.getRealDir())) # Save a nimblemeta.json file. saveNimbleMeta(pkgDestDir, "file://" & dir, vcsRevisionInDir(dir), diff --git a/src/nimblepkg/packageinfo.nim b/src/nimblepkg/packageinfo.nim index 85821d5..fecdae0 100644 --- a/src/nimblepkg/packageinfo.nim +++ b/src/nimblepkg/packageinfo.nim @@ -27,6 +27,10 @@ type MetaData* = object url*: string + NimbleLink* = object + nimbleFilePath*: string + packageDir*: string + proc initPackageInfo*(path: string): PackageInfo = result.myPath = path result.specialVersion = "" @@ -141,6 +145,15 @@ proc readMetaData*(path: string): MetaData = let jsonmeta = parseJson(cont) result.url = jsonmeta["url"].str +proc readNimbleLink*(nimbleLinkPath: string): NimbleLink = + let s = readFile(nimbleLinkPath).splitLines() + result.nimbleFilePath = s[0] + result.packageDir = s[1] + +proc writeNimbleLink*(nimbleLinkPath: string, contents: NimbleLink) = + let c = contents.nimbleFilePath & "\n" & contents.packageDir + writeFile(nimbleLinkPath, c) + proc needsRefresh*(options: Options): bool = ## Determines whether a ``nimble refresh`` is needed. ## @@ -298,8 +311,7 @@ proc findNimbleFile*(dir: string; error: bool): string = if result.splitFile.ext == ".nimble-link": # Return the path of the real .nimble file. - let lines = readFile(result).splitLines() - result = lines[0] + result = readNimbleLink(result).nimbleFilePath if not fileExists(result): raiseNimbleError("The .nimble-link file is pointing to a missing" & " file: " & result) From a2470470899ac31a3dbf6631f6171179aeee870d Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 20 Sep 2017 18:18:22 +0300 Subject: [PATCH 4/4] Fixed nondeterminism in version sorting --- src/nimble.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/nimble.nim b/src/nimble.nim index 9b9de0b..0af471e 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -630,9 +630,13 @@ proc listPaths(options: Options) = v.version = newVersion(pkgInfo.specialVersion) if nimbleLinkTargetPath.len == 0: v.path = options.getPkgsDir / (pkgInfo.name & '-' & pkgInfo.specialVersion) + installed.add(v) else: + # If we have a nimble-developed package, this is really the path we're + # looking for. v.path = nimbleLinkTargetPath - installed.add(v) + installed = @[v] + break else: display("Warning:", "No .nimble file found for " & path, Warning, MediumPriority)