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

Adds requires flag which allows to add extra packages to the dependency resolution #1266

Merged
merged 3 commits into from
Oct 1, 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
6 changes: 5 additions & 1 deletion src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ proc processFreeDependenciesSAT(rootPkgInfo: PackageInfo, options: Options): Has
return satProccesedPackages
var solvedPkgs = newSeq[SolvedPackage]()
var pkgsToInstall: seq[(string, Version)] = @[]
var rootPkgInfo = rootPkgInfo
rootPkgInfo.requires &= options.extraRequires
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
Expand Down Expand Up @@ -153,12 +155,14 @@ proc processFreeDependencies(pkgInfo: PackageInfo,
## during build phase.
assert not pkgInfo.isMinimal,
"processFreeDependencies needs pkgInfo.requires"

var requirements = requirements
var pkgList {.global.}: seq[PackageInfo]
once:
pkgList = initPkgList(pkgInfo, options)
if options.useSatSolver:
return processFreeDependenciesSAT(pkgInfo, options)
else:
requirements.add options.extraRequires

display("Verifying", "dependencies for $1@$2" %
[pkgInfo.basicInfo.name, $pkgInfo.basicInfo.version],
Expand Down
4 changes: 4 additions & 0 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type
# 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
extraRequires*: seq[PkgTuple] # extra requires parsed from the command line

ActionType* = enum
actionNil, actionRefresh, actionInit, actionDump, actionPublish, actionUpgrade
Expand Down Expand Up @@ -245,6 +246,7 @@ Nimble Options:
--useSystemNim Use system nim and ignore nim from the lock
file if any
--solver:sat|legacy Use the SAT solver or the legacy (default) for dependency resolution.
--requires Add extra packages to the dependency resolution. Uses the same syntax as the Nimble file. Example: nimble install --requires "pkg1; pkg2 >= 1.2"

For more information read the GitHub readme:
https://github.com/nim-lang/nimble#readme
Expand Down Expand Up @@ -566,6 +568,8 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
result.useSatSolver = false
else:
raise nimbleError("Unknown solver option: " & val)
of "requires":
result.extraRequires = val.split(";").mapIt(it.strip.parseRequires())
else: isGlobalFlag = false

var wasFlagHandled = true
Expand Down
6 changes: 6 additions & 0 deletions tests/requireflag/requireflag.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version = "0.1.0"
author = "Ivan Yonchovski"
description = "Nim package manager."
license = "BSD"

requires "timezones == 0.5.4"
1 change: 1 addition & 0 deletions tests/requireflag/src/def.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "def727"
1 change: 1 addition & 0 deletions tests/tester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import tuninstall
import ttaskdeps
import tsat
import tniminstall
import trequireflag
# nonim tests are very slow and (often) break the CI.

# import tnonim
21 changes: 21 additions & 0 deletions tests/trequireflag.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{.used.}
import unittest, os
import testscommon
from nimblepkg/common import cd

suite "requires flag":
test "can add additional requirements to package with legacy solver":
cleanDir(installDir)
cd "requireflag":
let (outp, exitCode) = execNimble("--requires: stew; results > 0.1", "--solver:legacy", "install")
check exitCode == QuitSuccess
check outp.processOutput.inLines("Success: results installed successfully.")
check outp.processOutput.inLines("Success: stew installed successfully.")

test "can add additional requirements to package with sat solver":
cleanDir(installDir)
cd "requireflag":
let (outp, exitCode) = execNimble("--requires: stew; results > 0.1", "--solver:sat", "install")
check exitCode == QuitSuccess
check outp.processOutput.inLines("Success: results installed successfully.")
check outp.processOutput.inLines("Success: stew installed successfully.")