diff --git a/src/nimblepkg/packageparser.nim b/src/nimblepkg/packageparser.nim index 17f4464..04a5730 100644 --- a/src/nimblepkg/packageparser.nim +++ b/src/nimblepkg/packageparser.nim @@ -277,6 +277,15 @@ proc readPackageInfoFromNimble(path: string; result: var PackageInfo) = else: raise newException(ValueError, "Cannot open package info: " & path) +proc inferInstallRules(pkgInfo: var PackageInfo, options: Options) = + # Binary packages shouldn't install .nim files by default. + # (As long as the package info doesn't explicitly specify what should be + # installed.) + let installInstructions = + pkgInfo.installDirs.len + pkgInfo.installExt.len + pkgInfo.installFiles.len + if installInstructions == 0 and pkgInfo.bin.len > 0: + pkgInfo.skipExt.add("nim") + proc readPackageInfo(nf: NimbleFile, options: Options, onlyMinimalInfo=false): PackageInfo = ## Reads package info from the specified Nimble file. @@ -354,6 +363,9 @@ proc readPackageInfo(nf: NimbleFile, options: Options, if not result.isMinimal: options.pkgInfoCache[nf] = result + # Apply rules to infer which files should/shouldn't be installed. See #469. + inferInstallRules(result, options) + # Validate the rest of the package info last. if not options.disableValidation: validateVersion(result.version) diff --git a/tests/packageStructure/validBinary/y.nim b/tests/packageStructure/validBinary/y.nim new file mode 100644 index 0000000..e69de29 diff --git a/tests/packageStructure/validBinary/y.nimble b/tests/packageStructure/validBinary/y.nimble new file mode 100644 index 0000000..087141b --- /dev/null +++ b/tests/packageStructure/validBinary/y.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "Dominik Picheta" +description = "Correctly structured package Y" +license = "MIT" + +bin = @["y"] + +# Dependencies + +requires "nim >= 0.15.0" + diff --git a/tests/packageStructure/validBinary/yWrong/foobar.nim b/tests/packageStructure/validBinary/yWrong/foobar.nim new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/packageStructure/validBinary/yWrong/foobar.nim @@ -0,0 +1 @@ + diff --git a/tests/packageStructure/y/y.nimble b/tests/packageStructure/y/y.nimble index 0ce52f9..4eb3ba5 100644 --- a/tests/packageStructure/y/y.nimble +++ b/tests/packageStructure/y/y.nimble @@ -5,6 +5,7 @@ author = "Dominik Picheta" description = "Incorrectly structured package Y" license = "MIT" +installExt = @["nim"] bin = @["y"] # Dependencies diff --git a/tests/tester.nim b/tests/tester.nim index c26bb00..c408777 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"]: + for package in ["a", "b", "c", "validBinary"]: cd "packageStructure/" & package: let (output, exitCode) = execNimble(["install", "-y"]) check exitCode == QuitSuccess