Skip to content

Commit

Permalink
when solving local packages systemnim is preferred
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Dec 4, 2024
1 parent 37024df commit d14aed6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
31 changes: 17 additions & 14 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,23 @@ proc processFreeDependenciesSAT(rootPkgInfo: PackageInfo, options: Options): Has
not isUpgrading and lockedPkg.vcsRevision == pkg.metaData.vcsRevision):
toRemoveFromLocked.add pkg

# result = solveLocalPackages(rootPkgInfo, pkgList, solvedPkgs, options)
# if solvedPkgs.len > 0:
# displaySatisfiedMsg(solvedPkgs, pkgsToInstall, options)
# addReverseDeps(solvedPkgs, allPkgsInfo, options)
# for pkg in allPkgsInfo:
# result.incl pkg
# for nonLocked in toRemoveFromLocked:
# result.excl nonLocked
# result =
# result.toSeq
# .deleteStaleDependencies(rootPkgInfo, options)
# .toHashSet
# satProccesedPackages = result
# return result
var systemNimCompatible = options.nimBin.isSome
result = solveLocalPackages(rootPkgInfo, pkgList, solvedPkgs, systemNimCompatible, options)
if solvedPkgs.len > 0:
displaySatisfiedMsg(solvedPkgs, pkgsToInstall, options)
addReverseDeps(solvedPkgs, allPkgsInfo, options)
for pkg in allPkgsInfo:
if pkg.basicInfo.name.isNim and systemNimCompatible:
continue #Dont add nim from the solution as we will use system nim
result.incl pkg
for nonLocked in toRemoveFromLocked:
result.excl nonLocked
result =
result.toSeq
.deleteStaleDependencies(rootPkgInfo, options)
.toHashSet
satProccesedPackages = result
return result

var output = ""
result = solvePackages(rootPkgInfo, pkgList, pkgsToInstall, options, output, solvedPkgs)
Expand Down
34 changes: 16 additions & 18 deletions src/nimblepkg/nimblesat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -607,31 +607,28 @@ proc topologicalSort*(solvedPkgs: seq[SolvedPackage]): seq[SolvedPackage] =
if inDegree[neighbor] == 0:
zeroInDegree.add(neighbor)

proc solveLocalPackages*(rootPkgInfo: PackageInfo, pkgList: seq[PackageInfo], solvedPkgs: var seq[SolvedPackage], options: Options): HashSet[PackageInfo] =
proc areSystemNimCompatible*(solvedPkgs: seq[SolvedPackage], options: Options): bool =
for solvedPkg in solvedPkgs:
for req in solvedPkg.requirements:
if req.isNim and options.nimBin.isSome and not options.nimBin.get.version.withinRange(req.ver):
return false
true

proc solveLocalPackages*(rootPkgInfo: PackageInfo, pkgList: seq[PackageInfo], solvedPkgs: var seq[SolvedPackage], systemNimCompatible: var bool, options: Options): HashSet[PackageInfo] =
var root = rootPkgInfo.getMinimalInfo(options)
root.isRoot = true
var pkgVersionTable = initTable[string, PackageVersions]()
pkgVersionTable[root.name] = PackageVersions(pkgName: root.name, versions: @[root])
fillPackageTableFromPreferred(pkgVersionTable, pkgList.mapIt(it.getMinimalInfo(options)))
var output = ""
solvedPkgs = pkgVersionTable.getSolvedPackages(output)
#Verify that system Nim is compatible with all selected packages
var systemNimCompatible = true
for solvedPkg in solvedPkgs:
var isPkgCompatibleWithNim = false
if solvedPkg.pkgName.isNim and options.nimBin.isSome:
for req in solvedPkg.requirements:
if req.isNim and options.nimBin.get.version.withinRange(req.ver):
isPkgCompatibleWithNim = true
if not isPkgCompatibleWithNim:
systemNimCompatible = false
break

systemNimCompatible = solvedPkgs.areSystemNimCompatible(options)

for solvedPkg in solvedPkgs:
if solvedPkg.pkgName.isNim and systemNimCompatible:
continue #Dont add nim from the solution as we will use system nim
for pkgInfo in pkgList:
if pkgInfo.basicInfo.name == solvedPkg.pkgName and pkgInfo.basicInfo.version == solvedPkg.version:
if solvedPkg.pkgName.isNim and systemNimCompatible:
continue
result.incl pkgInfo

proc solvePackages*(rootPkg: PackageInfo, pkgList: seq[PackageInfo], pkgsToInstall: var seq[(string, Version)], options: Options, output: var string, solvedPkgs: var seq[SolvedPackage]): HashSet[PackageInfo] =
Expand All @@ -641,7 +638,8 @@ proc solvePackages*(rootPkg: PackageInfo, pkgList: seq[PackageInfo], pkgsToInsta
pkgVersionTable[root.name] = PackageVersions(pkgName: root.name, versions: @[root])
collectAllVersions(pkgVersionTable, root, options, downloadMinimalPackage, pkgList.mapIt(it.getMinimalInfo(options)))
solvedPkgs = pkgVersionTable.getSolvedPackages(output).topologicalSort()

let systemNimCompatible = solvedPkgs.areSystemNimCompatible(options)

for solvedPkg in solvedPkgs:
if solvedPkg.pkgName == root.name: continue
var foundInList = false
Expand All @@ -650,8 +648,8 @@ proc solvePackages*(rootPkg: PackageInfo, pkgList: seq[PackageInfo], pkgsToInsta
result.incl pkgInfo
foundInList = true
if not foundInList:
if solvedPkg.pkgName.isNim and options.nimBin.isSome and options.nimBin.get.version == solvedPkg.version:
continue #Skip systemnim as its already installed
if solvedPkg.pkgName.isNim and systemNimCompatible:
continue #Skips systemNim
pkgsToInstall.addUnique((solvedPkg.pkgName, solvedPkg.version))

proc getPackageInfo*(name: string, pkgs: seq[PackageInfo], version: Option[Version] = none(Version)): Option[PackageInfo] =
Expand Down

0 comments on commit d14aed6

Please sign in to comment.