Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1277 Tagged versions (i.e. #head) behaves like any except when matched against another tag #1279

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
- macos-latest
- ubuntu-latest
nimversion:
- devel
# - stable
# - devel
- stable
name: ${{ matrix.os }} - ${{ matrix.nimversion }}
runs-on: ${{ matrix.os }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: jiro4989/setup-nim-action@v1
- uses: jiro4989/setup-nim-action@v2
with:
nim-version: ${{ matrix.nimversion }}
- run: nim --version
Expand Down
20 changes: 20 additions & 0 deletions changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@

# Nimble changelog

## 0.16.2

- Adds a `requires` flag which allows to add extra packages to the dependency resolution.
- Zero to hero: nimble is able to function without `nim` in the path.
- The SAT solver is now the default solver.

## 0.16.1

- Improves `nimDir`'s `nim` selection heuristic.
- Fixes a bug where the SAT cache downloaded packages in the wrong directory.
- Other fixes and improvements.

## 0.16.0

- Implemented a new experimental SAT solver for dependency resolution.
- Implemented support for self-bootstrapping when no Nim is present.
- Added support for package entry points.
- Improved Nim version management.
- Other fixes and improvements.

## 0.14.0

This is a major release containing four new features:
Expand Down
11 changes: 11 additions & 0 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ proc displaySatisfiedMsg(solvedPkgs: seq[SolvedPackage], pkgToInstall: seq[(stri
for req in pkg.requirements:
displayInfo(pkgDepsAlreadySatisfiedMsg(req))

proc displayUsingSpecialVersionWarning(solvedPkgs: seq[SolvedPackage], options: Options) =
var messages = newSeq[string]()
for pkg in solvedPkgs:
for req in pkg.requirements:
if req.ver.isSpecial:
nimblesat.addUnique(messages, &"Package {pkg.pkgName} lists an underspecified version of {req.name} ({req.ver})")

for msg in messages:
displayWarning(msg)

proc addReverseDeps(solvedPkgs: seq[SolvedPackage], allPkgsInfo: seq[PackageInfo], options: Options) =
for pkg in solvedPkgs:
let solvedPkg = getPackageInfo(pkg.pkgName, allPkgsInfo, some pkg.version)
Expand Down Expand Up @@ -116,6 +126,7 @@ proc processFreeDependenciesSAT(rootPkgInfo: PackageInfo, options: Options): Has
var output = ""
result = solvePackages(rootPkgInfo, pkgList, pkgsToInstall, options, output, solvedPkgs)
displaySatisfiedMsg(solvedPkgs, pkgsToInstall, options)
displayUsingSpecialVersionWarning(solvedPkgs, options)
var solved = solvedPkgs.len > 0 #A pgk can be solved and still dont return a set of PackageInfo
for (name, ver) in pkgsToInstall:
var versionRange = ver.toVersionRange
Expand Down
7 changes: 5 additions & 2 deletions src/nimblepkg/version.nim
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ proc initFromJson*(dst: var Version, jsonNode: JsonNode, jsonPath: var string) =
proc isSpecial*(ver: Version): bool =
return ($ver).len > 0 and ($ver)[0] == '#'

proc isSpecial*(verRange: VersionRange): bool =
return verRange.kind == verSpecial

proc `<`*(ver: Version, ver2: Version): bool =
# Handling for special versions such as "#head" or "#branch".
if ver.isSpecial or ver2.isSpecial:
Expand Down Expand Up @@ -141,8 +144,8 @@ proc withinRange*(ver: Version, ran: VersionRange): bool =
return ver <= ran.ver
of verEq:
return ver == ran.ver
of verSpecial:
return ver == ran.spe
of verSpecial: # special version is always within range
return ver.isSpecial and ver == ran.spe or not ver.isSpecial
of verIntersect, verTilde, verCaret:
return withinRange(ver, ran.verILeft) and withinRange(ver, ran.verIRight)
of verAny:
Expand Down
37 changes: 36 additions & 1 deletion tests/tsat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,39 @@ suite "SAT solver":
check pkgC.pkgName == "c" and pkgC.version == newVersion "0.1.0"
check "random" in pkgVersionTable

removeDir(options.pkgCachePath)
removeDir(options.pkgCachePath)

test "should treat #head and tags as any version":
let pkgVersionTable = {
"a": PackageVersions(pkgName: "a", versions: @[
PackageMinimalInfo(name: "a", version: newVersion "3.0", requires: @[
(name:"b", ver: parseVersionRange "#head")
], isRoot:true),
]),
"b": PackageVersions(pkgName: "b", versions: @[
PackageMinimalInfo(name: "b", version: newVersion "0.1.0")
])
}.toTable()
var graph = pkgVersionTable.toDepGraph()
let form = toFormular(graph)
var packages = initTable[string, Version]()
var output = ""
check solve(graph, form, packages, output)
check packages.len == 2

test "should not match other tags":
let pkgVersionTable = {
"a": PackageVersions(pkgName: "a", versions: @[
PackageMinimalInfo(name: "a", version: newVersion "3.0", requires: @[
(name:"b", ver: parseVersionRange "#head")
], isRoot:true),
]),
"b": PackageVersions(pkgName: "b", versions: @[
PackageMinimalInfo(name: "b", version: newVersion "#someOtherTag")
])
}.toTable()
var graph = pkgVersionTable.toDepGraph()
let form = toFormular(graph)
var packages = initTable[string, Version]()
var output = ""
check not solve(graph, form, packages, output)
Loading