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 an issue with lock where subsequents runs generates empty deps. useSystemNim excludes nim from the lock file #1334

Merged
merged 12 commits into from
Jan 22, 2025
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ jobs:
run: nimble install -y
- name: Run nim c -r tester
run: |
cd tests
nim c -r tester
# there's no need to add nimblepkg unit tests --
# they are run by tmoduletests.nim
nimble test
- run: ./src/nimble install -y
- name: Build nimble with `-d:nimNimbleBootstrap`
run: |
Expand Down
11 changes: 9 additions & 2 deletions nimble.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ before install:
exec "git submodule update --init"

task test, "Run the Nimble tester!":
withDir "tests":
exec "nim c -r tester"
#Find params that are a test name
var extraParams = ""
for i in 0 .. paramCount():
if "::" in paramStr(i):
extraParams = "test "
extraParams.addQuoted paramStr(i)

withDir "tests":
exec "nim c -r tester " & extraParams
21 changes: 14 additions & 7 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ proc processFreeDependenciesSAT(rootPkgInfo: PackageInfo, options: Options): Has
for name, lockedPkg in rootPkgInfo.lockedDeps[""]:
for pkg in pkgList:
if name notin upgradeVersions and name == pkg.basicInfo.name and
(isUpgrading and lockedPkg.vcsRevision != pkg.metaData.vcsRevision or
(isUpgrading and lockedPkg.vcsRevision != pkg.metaData.vcsRevision or
not isUpgrading and lockedPkg.vcsRevision == pkg.metaData.vcsRevision):
toRemoveFromLocked.add pkg

Expand All @@ -116,7 +116,10 @@ proc processFreeDependenciesSAT(rootPkgInfo: PackageInfo, options: Options): Has
continue #Dont add nim from the solution as we will use system nim
result.incl pkg
for nonLocked in toRemoveFromLocked:
result.excl nonLocked
#only remove if the vcsRevision is different
for pkg in result:
if pkg.basicInfo.name == nonLocked.basicInfo.name and pkg.metaData.vcsRevision != nonLocked.metaData.vcsRevision:
result.excl nonLocked
result =
result.toSeq
.deleteStaleDependencies(rootPkgInfo, options)
Expand Down Expand Up @@ -1895,21 +1898,26 @@ proc getDependenciesForLocking(pkgInfo: PackageInfo, options: Options):

proc lock(options: Options) =
## Generates a lock file for the package in the current directory or updates
## it if it already exists.
## it if it already exists.
let
currentDir = getCurrentDir()
pkgInfo = getPkgInfo(currentDir, options)
currentLockFile = options.lockFile(currentDir)
lockExists = displayLockOperationStart(currentLockFile)

var
baseDeps =
if options.useSATSolver:
processFreeDependenciesSAT(pkgInfo, options).toSeq
processFreeDependenciesSAT(pkgInfo, options).toSeq
else:
pkgInfo.getDependenciesForLocking(options) # Deps shared by base and tasks
baseDepNames: HashSet[string] = baseDeps.mapIt(it.name).toHashSet

if options.useSystemNim:
baseDeps = baseDeps.filterIt(not it.name.isNim)

let baseDepNames: HashSet[string] = baseDeps.mapIt(it.name).toHashSet
pkgInfo.validateDevelopDependenciesVersionRanges(baseDeps, options)

# We need to separate the graph into separate tasks later
var
errors = validateDevModeDepsWorkingCopiesBeforeLock(pkgInfo, options)
Expand All @@ -1918,7 +1926,6 @@ proc lock(options: Options) =
lockDeps: AllLockFileDeps

lockDeps[noTask] = LockFileDeps()

# Add each individual tasks as partial sub graphs
for task in pkgInfo.taskRequires.keys:
var taskOptions = options
Expand Down
53 changes: 2 additions & 51 deletions tests/tlockfile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ license = "MIT"
requires "nim >= 1.5.1"
"""
additionalFileContent = "proc foo() =\n echo \"foo\"\n"
alternativeAdditionalFileContent = "proc bar() =\n echo \"bar\"\n"
# alternativeAdditionalFileContent = "proc bar() =\n echo \"bar\"\n"

definePackageConstants(PkgIdent.main)
definePackageConstants(PkgIdent.dep1)
Expand Down Expand Up @@ -168,7 +168,6 @@ requires "nim >= 1.5.1"

proc testLockedVcsRevisions(deps: seq[tuple[name, path: string]], lockFileName = defaultLockFileName) =
check lockFileName.fileExists

let json = lockFileName.readFile.parseJson
for (depName, depPath) in deps:
let expectedVcsRevision = depPath.getVcsRevision
Expand Down Expand Up @@ -235,7 +234,7 @@ requires "nim >= 1.5.1"
result = lockFileName.readFile.parseJson{$lfjkPackages}{dep}{$lfjkPkgVcsRevision}.str

proc addAdditionalFileAndPushToRemote(
repoPath, remoteName, remotePath, fileContent: string) =
repoPath, remoteName, remotePath, fileContent: string) {.used.} =
cdNewDir remotePath:
initRepo(isBare = true)
cd repoPath:
Expand Down Expand Up @@ -508,54 +507,6 @@ requires "nim >= 1.5.1"
errorMessage = getValidationErrorMessage(dep1PkgName, error)
check output.processOutput.inLines(errorMessage)

test "cannot sync because the working copy needs merge":
cleanUp()
withPkgListFile:
initNewNimblePackage(mainPkgOriginRepoPath, mainPkgRepoPath,
@[dep1PkgName])
initNewNimblePackage(dep1PkgOriginRepoPath, dep1PkgRepoPath)

cd mainPkgOriginRepoPath:
testLockFile(@[(dep1PkgName, dep1PkgOriginRepoPath)], isNew = true)
addFiles(defaultLockFileName)
commit("Add the lock file to version control")

cd mainPkgRepoPath:
# Pull the lock file.
pull("origin")
# Create develop file. On this command also a sync file will be
# generated.
let (_, exitCode) = execNimble("develop", &"-a:{dep1PkgRepoPath}")
check exitCode == QuitSuccess

addAdditionalFileAndPushToRemote(
dep1PkgRepoPath, dep1PkgRemoteName, dep1PkgRemotePath,
additionalFileContent)

addAdditionalFileAndPushToRemote(
dep1PkgOriginRepoPath, dep1PkgOriginRemoteName, dep1PkgOriginRemotePath,
alternativeAdditionalFileContent)

cd mainPkgOriginRepoPath:
writeDevelopFile(developFileName, @[], @[dep1PkgOriginRepoPath])
# Update the origin lock file.
testLockFile(@[(dep1PkgName, dep1PkgOriginRepoPath)], isNew = false)
addFiles(defaultLockFileName)
commit("Modify the lock file")

cd mainPkgRepoPath:
# Pull modified origin lock file. At this point the revisions in the
# lock file, sync file and develop mode dependency working copy should
# be different from one another.
pull("origin")
let (output, exitCode) = execNimbleYes("sync")
check exitCode == QuitFailure
let
error = ValidationError(kind: vekWorkingCopyNeedsMerge,
path: dep1PkgRepoPath)
errorMessage = getValidationErrorMessage(dep1PkgName, error)
check output.processOutput.inLines(errorMessage)

test "check fails because the working copy needs sync":
outOfSyncDepsTest(""):
let (output, exitCode) = execNimble("check")
Expand Down
Loading