From 9f4081e8888958a065d993b13bb5ae31ad6075e3 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Mon, 10 Sep 2018 00:24:20 +0100 Subject: [PATCH] Softened package structure rules when srcDir is not specified. Fixes #469. --- src/nimblepkg/packageparser.nim | 16 +++++++++++++--- tests/packageStructure/softened/myPkg.nim | 0 tests/packageStructure/softened/myPkg.nimble | 15 +++++++++++++++ .../softened/myPkg/submodule.nim | 0 tests/packageStructure/softened/tests/mytest.nim | 0 tests/tester.nim | 2 +- 6 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/packageStructure/softened/myPkg.nim create mode 100644 tests/packageStructure/softened/myPkg.nimble create mode 100644 tests/packageStructure/softened/myPkg/submodule.nim create mode 100644 tests/packageStructure/softened/tests/mytest.nim diff --git a/src/nimblepkg/packageparser.nim b/src/nimblepkg/packageparser.nim index 04a5730..8448286 100644 --- a/src/nimblepkg/packageparser.nim +++ b/src/nimblepkg/packageparser.nim @@ -286,6 +286,16 @@ proc inferInstallRules(pkgInfo: var PackageInfo, options: Options) = if installInstructions == 0 and pkgInfo.bin.len > 0: pkgInfo.skipExt.add("nim") + # When a package doesn't specify a `srcDir` it's fair to assume that + # the .nim files are in the root of the package. So we can explicitly select + # them and prevent the installation of anything else. The user can always + # override this with `installFiles`. + if pkgInfo.srcDir == "": + if dirExists(pkgInfo.getRealDir() / pkgInfo.name): + pkgInfo.installDirs.add(pkgInfo.name) + if fileExists(pkgInfo.getRealDir() / pkgInfo.name.addFileExt("nim")): + pkgInfo.installFiles.add(pkgInfo.name.addFileExt("nim")) + proc readPackageInfo(nf: NimbleFile, options: Options, onlyMinimalInfo=false): PackageInfo = ## Reads package info from the specified Nimble file. @@ -360,12 +370,12 @@ proc readPackageInfo(nf: NimbleFile, options: Options, if version.kind == verSpecial: result.specialVersion = minimalInfo.version - if not result.isMinimal: - options.pkgInfoCache[nf] = result - # Apply rules to infer which files should/shouldn't be installed. See #469. inferInstallRules(result, options) + if not result.isMinimal: + options.pkgInfoCache[nf] = result + # Validate the rest of the package info last. if not options.disableValidation: validateVersion(result.version) diff --git a/tests/packageStructure/softened/myPkg.nim b/tests/packageStructure/softened/myPkg.nim new file mode 100644 index 0000000..e69de29 diff --git a/tests/packageStructure/softened/myPkg.nimble b/tests/packageStructure/softened/myPkg.nimble new file mode 100644 index 0000000..525080d --- /dev/null +++ b/tests/packageStructure/softened/myPkg.nimble @@ -0,0 +1,15 @@ +# Package + +version = "0.1.0" +author = "Dominik Picheta" +description = "Correctly structured package myPkg. See #469." +license = "MIT" + +# This is inferred implicitly by Nimble: +# installDirs = @["myPkg"] +# installFiles = @["myPkg.nim"] + +# Dependencies + +requires "nim >= 0.15.0" + diff --git a/tests/packageStructure/softened/myPkg/submodule.nim b/tests/packageStructure/softened/myPkg/submodule.nim new file mode 100644 index 0000000..e69de29 diff --git a/tests/packageStructure/softened/tests/mytest.nim b/tests/packageStructure/softened/tests/mytest.nim new file mode 100644 index 0000000..e69de29 diff --git a/tests/tester.nim b/tests/tester.nim index c408777..8ec6f22 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -92,7 +92,7 @@ test "can build with #head and versioned package (#289)": test "can validate package structure (#144)": # Test that no warnings are produced for correctly structured packages. - for package in ["a", "b", "c", "validBinary"]: + for package in ["a", "b", "c", "validBinary", "softened"]: cd "packageStructure/" & package: let (output, exitCode) = execNimble(["install", "-y"]) check exitCode == QuitSuccess