Skip to content

Commit

Permalink
Merge branch 'nim-lang:master' into path
Browse files Browse the repository at this point in the history
  • Loading branch information
Nycto authored Feb 12, 2025
2 parents 7fcddc7 + 20e2e4d commit f991b94
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1802,13 +1802,26 @@ 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()
let pkgInfo = getPkgInfo(currentDir, options, true)
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)
Expand Down
10 changes: 6 additions & 4 deletions src/nimblepkg/downloadnim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
13 changes: 13 additions & 0 deletions tests/inconsistentdeps/inconsistentdeps.nimble
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions tests/inconsistentdeps/src/inconsistentdeps.nim
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/inconsistentdeps/src/inconsistentdeps/submodule.nim
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 12 additions & 0 deletions tests/inconsistentdeps/tests/test1.nim
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/tcheckcommand.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
3 changes: 3 additions & 0 deletions tests/tdeclarativeparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ suite "Declarative parsing":
let (output, exitCode) = execNimble("--parser:declarative", "install", "nimlangserver")
echo output
check exitCode == QuitSuccess


# suite "Declarative parser features":

0 comments on commit f991b94

Please sign in to comment.