diff --git a/src/nimble.nim b/src/nimble.nim index 55f00c06..48cb70ce 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -1802,6 +1802,18 @@ proc validateDevelopDependenciesVersionRanges(dependentPkg: PackageInfo, if errors.len > 0: raise nimbleError(invalidDevelopDependenciesVersionsMsg(errors)) +proc validateParsedDependencies(pkgInfo: PackageInfo, options: Options) = + displayInfo(&"Validating dependencies for pkgInfo {pkgInfo.infoKind}", HighPriority) + var options = options + options.useDeclarativeParser = true + let declDeps = pkgInfo.toRequiresInfo(options).requires + + options.useDeclarativeParser = false + let vmDeps = pkgInfo.toFullInfo(options).requires + + if declDeps != vmDeps: + raise nimbleError(&"Parsed declarative and VM dependencies are not the same: {declDeps} != {vmDeps}") + proc check(options: Options) = try: let currentDir = getCurrentDir() @@ -1809,6 +1821,7 @@ proc check(options: Options) = validateDevelopFile(pkgInfo, options) let dependencies = pkgInfo.processAllDependencies(options).toSeq validateDevelopDependenciesVersionRanges(pkgInfo, dependencies, options) + validateParsedDependencies(pkgInfo, options) displaySuccess(&"The package \"{pkgInfo.basicInfo.name}\" is valid.") except CatchableError as error: displayError(error) diff --git a/src/nimblepkg/downloadnim.nim b/src/nimblepkg/downloadnim.nim index 871e6576..03614fff 100644 --- a/src/nimblepkg/downloadnim.nim +++ b/src/nimblepkg/downloadnim.nim @@ -123,10 +123,12 @@ proc getGccArch*(options: Options): int = return when defined(windows): 32 else: 64 proc isRosetta*(): bool = - let res = gorgeEx("sysctl -in sysctl.proc_translated") - if res.exitCode == 0: - return res.output.strip() == "1" - return false + try: + let res = execCmdEx("sysctl -in sysctl.proc_translated") + if res.exitCode == 0: + return res.output.strip() == "1" + except CatchableError: + return false proc getNightliesUrl*(parsedContents: JsonNode, arch: int): (string, string) = let os = diff --git a/tests/inconsistentdeps/inconsistentdeps.nimble b/tests/inconsistentdeps/inconsistentdeps.nimble new file mode 100644 index 00000000..22f5e1b3 --- /dev/null +++ b/tests/inconsistentdeps/inconsistentdeps.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "jmgomez" +description = "A new awesome nimble package" +license = "MIT" +srcDir = "src" + + +# Dependencies +requires "results" +if true: + requires "stew" diff --git a/tests/inconsistentdeps/src/inconsistentdeps.nim b/tests/inconsistentdeps/src/inconsistentdeps.nim new file mode 100644 index 00000000..b7a24803 --- /dev/null +++ b/tests/inconsistentdeps/src/inconsistentdeps.nim @@ -0,0 +1,7 @@ +# This is just an example to get you started. A typical library package +# exports the main API in this file. Note that you cannot rename this file +# but you can remove it if you wish. + +proc add*(x, y: int): int = + ## Adds two numbers together. + return x + y diff --git a/tests/inconsistentdeps/src/inconsistentdeps/submodule.nim b/tests/inconsistentdeps/src/inconsistentdeps/submodule.nim new file mode 100644 index 00000000..08682ef0 --- /dev/null +++ b/tests/inconsistentdeps/src/inconsistentdeps/submodule.nim @@ -0,0 +1,12 @@ +# This is just an example to get you started. Users of your library will +# import this file by writing ``import inconsistentdeps/submodule``. Feel free to rename or +# remove this file altogether. You may create additional modules alongside +# this file as required. + +type + Submodule* = object + name*: string + +proc initSubmodule*(): Submodule = + ## Initialises a new ``Submodule`` object. + Submodule(name: "Anonymous") diff --git a/tests/inconsistentdeps/tests/test1.nim b/tests/inconsistentdeps/tests/test1.nim new file mode 100644 index 00000000..c4419745 --- /dev/null +++ b/tests/inconsistentdeps/tests/test1.nim @@ -0,0 +1,12 @@ +# This is just an example to get you started. You may wish to put all of your +# tests into a single file, or separate them into multiple `test1`, `test2` +# etc. files (better names are recommended, just make sure the name starts with +# the letter 't'). +# +# To run these tests, simply execute `nimble test`. + +import unittest + +import inconsistentdeps +test "can add": + check add(5, 5) == 10 diff --git a/tests/tcheckcommand.nim b/tests/tcheckcommand.nim index 7326d83c..caf71a54 100644 --- a/tests/tcheckcommand.nim +++ b/tests/tcheckcommand.nim @@ -38,3 +38,9 @@ suite "check command": check exitCode == QuitSuccess check outp.processOutput.inLines("success") check outp.processOutput.inLines("\"x\" is valid") + + test "should fail if parsers parse different dependencies": + cd "inconsistentdeps": + let (outp, exitCode) = execNimble("check") + check exitCode == QuitFailure + check outp.processOutput.inLines("Parsed declarative and VM dependencies are not the same: @[results@any version] != @[results@any version, stew@any version]") diff --git a/tests/tdeclarativeparser.nim b/tests/tdeclarativeparser.nim index c1bd2d4c..679374a0 100644 --- a/tests/tdeclarativeparser.nim +++ b/tests/tdeclarativeparser.nim @@ -70,3 +70,6 @@ suite "Declarative parsing": let (output, exitCode) = execNimble("--parser:declarative", "install", "nimlangserver") echo output check exitCode == QuitSuccess + + + # suite "Declarative parser features":