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

enable sat by default #1273

Merged
merged 3 commits into from
Oct 10, 2024
Merged
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
31 changes: 18 additions & 13 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ proc checkSatisfied(options: Options, dependencies: seq[PackageInfo]) =
[pkgInfo.basicInfo.name, $currentVer, $pkgsInPath[pkgInfo.basicInfo.name]])
pkgsInPath[pkgInfo.basicInfo.name] = currentVer

proc displaySatisfiedMsg(solvedPkgs: seq[SolvedPackage], pkgToInstall: seq[(string, Version)]) {.used.}=
for pkg in solvedPkgs:
if pkg.pkgName notin pkgToInstall.mapIt(it[0]):
for req in pkg.requirements:
displayInfo(pkgDepsAlreadySatisfiedMsg(req))
proc displaySatisfiedMsg(solvedPkgs: seq[SolvedPackage], pkgToInstall: seq[(string, Version)], options: Options) =
if options.verbosity >= LowPriority:
for pkg in solvedPkgs:
if pkg.pkgName notin pkgToInstall.mapIt(it[0]):
for req in pkg.requirements:
displayInfo(pkgDepsAlreadySatisfiedMsg(req))

proc addReverseDeps(solvedPkgs: seq[SolvedPackage], allPkgsInfo: seq[PackageInfo], options: Options) =
for pkg in solvedPkgs:
Expand All @@ -81,24 +82,25 @@ proc processFreeDependenciesSAT(rootPkgInfo: PackageInfo, options: Options): Has
var pkgList = initPkgList(rootPkgInfo, options).mapIt(it.toFullInfo(options))
var allPkgsInfo: seq[PackageInfo] = pkgList & rootPkgInfo
#Remove from the pkglist the packages that exists in lock file and has a different vcsRevision
var toUpgradeNames: seq[string]
var upgradeVersions = initTable[string, VersionRange]()
var isUpgrading = options.action.typ == actionUpgrade
if isUpgrading:
toUpgradeNames = options.action.packages.mapIt(it[0])
pkgList = pkgList.filterIt(it.basicInfo.name notin toUpgradeNames)

for pkg in options.action.packages:
upgradeVersions[pkg.name] = pkg.ver
pkgList = pkgList.filterIt(it.basicInfo.name notin upgradeVersions)

var toRemoveFromLocked = newSeq[PackageInfo]()
if rootPkgInfo.lockedDeps.hasKey(""):
for name, lockedPkg in rootPkgInfo.lockedDeps[""]:
for pkg in pkgList:
if name notin toUpgradeNames and name == pkg.basicInfo.name and
if name notin upgradeVersions and name == pkg.basicInfo.name and
(isUpgrading and lockedPkg.vcsRevision != pkg.metaData.vcsRevision or
not isUpgrading and lockedPkg.vcsRevision == pkg.metaData.vcsRevision):
toRemoveFromLocked.add pkg

result = solveLocalPackages(rootPkgInfo, pkgList, solvedPkgs)
if solvedPkgs.len > 0:
# displaySatisfiedMsg(solvedPkgs, pkgsToInstall)
displaySatisfiedMsg(solvedPkgs, pkgsToInstall, options)
addReverseDeps(solvedPkgs, allPkgsInfo, options)
for pkg in allPkgsInfo:
result.incl pkg
Expand All @@ -113,10 +115,13 @@ proc processFreeDependenciesSAT(rootPkgInfo: PackageInfo, options: Options): Has

var output = ""
result = solvePackages(rootPkgInfo, pkgList, pkgsToInstall, options, output, solvedPkgs)
# displaySatisfiedMsg(solvedPkgs, pkgsToInstall)
displaySatisfiedMsg(solvedPkgs, pkgsToInstall, options)
var solved = solvedPkgs.len > 0 #A pgk can be solved and still dont return a set of PackageInfo
for (name, ver) in pkgsToInstall:
let resolvedDep = ((name: name, ver: ver.toVersionRange)).resolveAlias(options)
var versionRange = ver.toVersionRange
if name in upgradeVersions:
versionRange = upgradeVersions[name]
let resolvedDep = ((name: name, ver: versionRange)).resolveAlias(options)
let (packages, _) = install(@[resolvedDep], options,
doPrompt = false, first = false, fromLockFile = false, preferredPackages = @[])
for pkg in packages:
Expand Down
5 changes: 3 additions & 2 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type
# If not provided by default it applies to the current directory package.
# For now, it is used only by the run action and it is ignored by others.
pkgCachePath*: string # Cache used to store package downloads
useSatSolver*: bool
useSatSolver*: bool = true
extraRequires*: seq[PkgTuple] # extra requires parsed from the command line

ActionType* = enum
Expand Down Expand Up @@ -398,7 +398,8 @@ proc getBinDir*(options: Options): string =
proc setPackageCache(options: var Options, baseDir: string) =
if options.useSatSolver:
options.pkgCachePath = baseDir / "pkgcache"
display("Info:", "Package cache path " & options.pkgCachePath, priority = HighPriority)
if options.verbosity >= LowPriority:
display("Info:", "Package cache path " & options.pkgCachePath, priority = LowPriority)

proc setNimbleDir*(options: var Options) =
var
Expand Down
10 changes: 5 additions & 5 deletions tests/tdevelopfeature.nim
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ suite "develop feature":

cd "pkg1":
cleanFile "pkg1".addFileExt(ExeExt)
let (output, exitCode) = execNimble("run", "-n")
let (output, exitCode) = execNimble("run", "-n", "--verbose")
check exitCode == QuitSuccess
var lines = output.processOutput
check lines.inLinesOrdered(
Expand Down Expand Up @@ -697,15 +697,15 @@ suite "develop feature":

cd "pkg1":
cleanFile "pkg1".addFileExt(ExeExt)
let (output, exitCode) = execNimble("run", "-n")
let (output, exitCode) = execNimble("run", "-n", "--verbose")
check exitCode == QuitSuccess
var lines = output.processOutput
check lines.inLinesOrdered(
pkgDepsAlreadySatisfiedMsg(("pkg2", anyVersion)))
check lines.inLinesOrdered(
pkgDepsAlreadySatisfiedMsg(("pkg3", anyVersion)))
check lines.inLinesOrdered(
pkgDepsAlreadySatisfiedMsg(("pkg3", anyVersion)))
pkgDepsAlreadySatisfiedMsg(("pkg2", anyVersion)))
check lines.inLinesOrdered(
pkgDepsAlreadySatisfiedMsg(("pkg3", anyVersion)))

test "version clash with not used included develop dependencies":
# +--------------------------+ +--------------------------+
Expand Down
Loading