From 3f6ef3ae55f662a611e10ed94ed333fe698216f4 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 29 Dec 2015 17:30:32 +0000 Subject: [PATCH] Fixed reverse deps issues + some tests. Fixes #113. Fixes #168. --- src/nimble.nim | 13 +++++- tests/issue113/a/a.nimble | 11 +++++ tests/issue113/b/b.nimble | 11 +++++ tests/issue113/buildfail/buildfail.nim | 1 + tests/issue113/buildfail/buildfail.nimble | 13 ++++++ tests/issue113/c/c.nimble | 11 +++++ tests/tester.nim | 51 +++++++++++++++++------ 7 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 tests/issue113/a/a.nimble create mode 100644 tests/issue113/b/b.nimble create mode 100644 tests/issue113/buildfail/buildfail.nim create mode 100644 tests/issue113/buildfail/buildfail.nimble create mode 100644 tests/issue113/c/c.nimble diff --git a/src/nimble.nim b/src/nimble.nim index 41be28c..97e3027 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -214,6 +214,7 @@ proc addRevDep(options: Options, dep: tuple[name, version: string], proc removeRevDep(options: Options, pkg: PackageInfo) = ## Removes ``pkg`` from the reverse dependencies of every package. + assert(not pkg.isMinimal) proc remove(options: Options, pkg: PackageInfo, depTup: PkgTuple, thisDep: JsonNode) = for ver, val in thisDep: @@ -294,9 +295,9 @@ proc processDeps(pkginfo: PackageInfo, options: Options): seq[string] = # We add the reverse deps to the JSON file here because we don't want # them added if the above errorenous condition occurs # (unsatisfiable dependendencies). + # N.B. NimbleData is saved in installFromDir. for i in reverseDeps: addRevDep(options, i, pkginfo) - saveNimbleData(options) proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string], forRelease: bool) = ## Builds a package as specified by ``pkgInfo``. @@ -448,6 +449,10 @@ proc installFromDir(dir: string, latest: bool, options: Options, # Save a nimblemeta.json file. saveNimbleMeta(pkgDestDir, url, filesInstalled) + # Save the nimble data (which might now contain reverse deps added in + # processDeps). + saveNimbleData(options) + # Return the paths to the dependencies of this package. result.paths.add pkgDestDir result.pkg = pkgInfo @@ -839,7 +844,11 @@ proc uninstall(options: Options) = for pkg in pkgsToDelete: # If we reach this point then the package can be safely removed. - removeRevDep(options, pkg) + + # removeRevDep needs the package dependency info, so we can't just pass + # a minimal pkg info. + let pkgFull = readPackageInfo(pkg.mypath, options, false) + removeRevDep(options, pkgFull) removePkgDir(options.getPkgsDir / (pkg.name & '-' & pkg.version), options) echo("Removed ", pkg.name, " (", $pkg.version, ")") diff --git a/tests/issue113/a/a.nimble b/tests/issue113/a/a.nimble new file mode 100644 index 0000000..2f22f38 --- /dev/null +++ b/tests/issue113/a/a.nimble @@ -0,0 +1,11 @@ +# Package + +version = "0.1.0" +author = "Dominik Picheta" +description = "Root package, depends on b." +license = "MIT" + +# Dependencies + +requires "nim >= 0.12.1", "b" + diff --git a/tests/issue113/b/b.nimble b/tests/issue113/b/b.nimble new file mode 100644 index 0000000..f5ce98d --- /dev/null +++ b/tests/issue113/b/b.nimble @@ -0,0 +1,11 @@ +# Package + +version = "0.1.0" +author = "Dominik Picheta" +description = "Second dep. Depended by a and depends on c." +license = "MIT" + +# Dependencies + +requires "nim >= 0.12.1", "c" + diff --git a/tests/issue113/buildfail/buildfail.nim b/tests/issue113/buildfail/buildfail.nim new file mode 100644 index 0000000..3820449 --- /dev/null +++ b/tests/issue113/buildfail/buildfail.nim @@ -0,0 +1 @@ +var x: string = 42 diff --git a/tests/issue113/buildfail/buildfail.nimble b/tests/issue113/buildfail/buildfail.nimble new file mode 100644 index 0000000..e60f126 --- /dev/null +++ b/tests/issue113/buildfail/buildfail.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "Dominik Picheta" +description = "Testing issue 113." +license = "MIT" + +bin = @["buildfail"] + +# Dependencies + +requires "nim >= 0.12.1", "c" + diff --git a/tests/issue113/c/c.nimble b/tests/issue113/c/c.nimble new file mode 100644 index 0000000..6ed1e7d --- /dev/null +++ b/tests/issue113/c/c.nimble @@ -0,0 +1,11 @@ +# Package + +version = "0.1.0" +author = "Dominik Picheta" +description = "Third dep. Depended by b." +license = "MIT" + +# Dependencies + +requires "nim >= 0.12.1" + diff --git a/tests/tester.nim b/tests/tester.nim index d85da8b..950c911 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -18,6 +18,33 @@ template cd*(dir: string, body: stmt) = proc processOutput(output: string): seq[string] = output.strip.splitLines().filter((x: string) => (x.len > 0)) +proc inLines(lines: seq[string], line: string): bool = + for i in lines: + if line.normalize in i.normalize: return true + +test "issue 113 (uninstallation problems)": + cd "issue113/c": + check execCmdEx("../../" & path & " install -y").exitCode == QuitSuccess + cd "issue113/b": + check execCmdEx("../../" & path & " install -y").exitCode == QuitSuccess + cd "issue113/a": + check execCmdEx("../../" & path & " install -y").exitCode == QuitSuccess + + # Try to remove c. + let (output, exitCode) = execCmdEx(path & " remove -y c") + let lines = output.strip.splitLines() + check exitCode != QuitSuccess + check "cannot uninstall c (0.1.0) because b (0.1.0) depends on it" in + lines[^1].normalize + + check execCmdEx(path & " remove -y a").exitCode == QuitSuccess + check execCmdEx(path & " remove -y b").exitCode == QuitSuccess + + cd "issue113/buildfail": + check execCmdEx("../../" & path & " install -y").exitCode != QuitSuccess + + check execCmdEx(path & " remove -y c").exitCode == QuitSuccess + test "can refresh with default urls": check execCmdEx(path & " refresh").exitCode == QuitSuccess @@ -39,12 +66,12 @@ test "can refresh with custom urls": let (output, exitCode) = execCmdEx(path & " refresh") let lines = output.strip.splitLines() check exitCode == QuitSuccess - check "reading from config file" in lines[0].normalize - check "downloading \"official\" package list" in lines[1].normalize - check "trying http://google.com" in lines[2].normalize - check "packages.json file is invalid" in lines[3].normalize - check "404 not found" in lines[5].normalize - check "done" in lines[^1].normalize + check inLines(lines, "reading from config file") + check inLines(lines, "downloading \"official\" package list") + check inLines(lines, "trying http://google.com") + check inLines(lines, "packages.json file is invalid") + check inLines(lines, "404 not found") + check inLines(lines, "done") # Restore config if fileExists(configBakFile): @@ -114,16 +141,16 @@ test "issue #27": test "issue #126": cd "issue126/a": - let (output, exitCode) = execCmdEx("../../" & path & " install") + let (output, exitCode) = execCmdEx("../../" & path & " install -y") let lines = output.strip.splitLines() - check exitCode != QuitSuccess - check "issue-126 is an invalid package name: cannot contain '-'" in lines[^1] + check exitCode != QuitSuccess # TODO + check inLines(lines, "issue-126 is an invalid package name: cannot contain '-'") cd "issue126/b": - let (output1, exitCode1) = execCmdEx("../../" & path & " install") + let (output1, exitCode1) = execCmdEx("../../" & path & " install -y") let lines1 = output1.strip.splitLines() - check exitCode1 != QuitSuccess - check "The .nimble file name must match name specified inside".normalize in lines1[^1].normalize + check exitCode1 == QuitSuccess + check inLines(lines1, "The .nimble file name must match name specified inside") test "issue #108": cd "issue108":