Skip to content

Commit ce4e377

Browse files
jmgomezjmgomez
andauthored
WIP CI green for vnext (#1408)
* Fix regression * Removes unused import * develop progress: handles reverse deps for develop * Fixes an issue where babel root packages failed to install. `uninstall ci` green * tlocal green * Declarative parser by default (enables vnext) * Fixes a rebase issue and disables vnext * Removes unusued import. Adds debug logging * Enables vnext * Only MacOs tests * Fix develop regression * Fixes test * Prompt to refresh the package list in vnext when it cant found a package * Fixes tlocal. Disables lock and issues to remove noise * Disables lock and issues * FIxes an issue with develop * picks #head when looking for packages * Adds support for `noRebuild` * Adds support for submodules in vnext * tmisc green except 1 * Fixes last test from tmisc * clean up * Adds log to debug one failing test that only fails in the CI * tlocaldeps green * Dont reinstall pkgs. tmulti green * tnimscript green * Implements to run deps binaries in vnext * Pass compiler flags for actionRun and others * truncommand green * fixes flawed test * Fixes an issue with binaries not being properly updated. ttwobinaryversions green * tuninstall green * Declarative parser fails when taskRequires is detected * Skips one test. Fixes "Develop file is used" * Fixes a regression in local dev. Comments a task deps test * Removes unnecessary logging * For build action: Only the root package is built (fixes tforgeinstall, although the declarative parser doesnt support it yet) * Tests if package already exists before installing * Improves TNimInstall test * Since the installation process changed, we need to adds srcDir to the paths as well * Comment failing taskdeps tests * Removes unused import. Fixes test * fixes "should fallback to a previous version of a dependency when is unsatisfable" * comments unused vars * Reenables lin and win CI * comments out develop suite for lin * reeanbles tdevelop. Disables lin and win * green: Task dependencies from lock file are used * Suite green: Task level dependencies * Adjust tests * Remove unused vars * Removes unused var * WIP tlockfile. Multiple locks fixes * vnext detects when a nimble file changed after a lock and rerun the solver if necessary * Improves `lock`: Dont use the legacy dependency graph which was done in the times of the greedy solver * Fix another tlockfile test * Progress in tlockfile. Also comment some failing tests * Fixes regression in develop * Improves locking, improves tdevelop test and clearer error msg * uncomment some tlockfile tests * Adds support to `shelf` and `shelfEnv` in vnext * Implements locking for task deps in vnext * Comment two tlock failing tests * Fixes an issue with the package validation in vnext: declarative parser cant validate develop packages * Mark test as used. Improves fragile test * Improves test * Better nim handling * Fixes a regression * green: can upgrade a dependency. * updates tlocker * Starts to handle upgrading develop dependencies for locking * Green: can upgrade: the new version of the package has a new dep * green: can upgrade: upgrade minimal set of deps * uncomments tissues * All "can upgrade" tests are green (adds support for adding/removing dependencies based on the upgrade package changing its requires) * clean comments * All tests from tlockfile green except `can generate lock file for nim as dep` * Removes unnecessary logs * Nim locking * Ignore the way nim locked via develop for vnext (too convoluted) * Uncomments tissues * Green: issue #1251. Should use the system nim when --useSystemNim flag is on * test * Fixes issue 399 in vnext * green: can validate package structure (#144) * Green "issues #280 and #524" * reenables ubuntu and win ci * Disables win * Better file handling * makes vnext respects the package file name for the module. * MacOs and Linux green CI. Enables win * Fix win compilation issue in test * Sets the right verbosity for shellenv * Removes unnecesary log * Fixes CI * Fixes CI * Makes the old codepath the default * removes log * dont lock root --------- Co-authored-by: jmgomez <[email protected]>
1 parent 8c6a84b commit ce4e377

25 files changed

+983
-369
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
strategy:
1212
matrix:
1313
os:
14+
- ubuntu-latest
1415
- windows-latest
1516
- macos-latest
16-
- ubuntu-latest
1717
nimversion:
1818
# - devel
1919
- stable
@@ -38,7 +38,14 @@ jobs:
3838
- name: Run nim c -r tester
3939
run: |
4040
nimble test
41-
- run: ./src/nimble install -y
41+
- name: Install nimble
42+
run: |
43+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
44+
./src/nimble install -y --nimbleDir:C:/nimbleDir
45+
else
46+
./src/nimble install -y
47+
fi
48+
shell: bash
4249
- name: Build nimble with `-d:nimNimbleBootstrap`
4350
run: |
4451
nim c -d:release -r tests/private/clone.nim

src/nimble.nim

Lines changed: 201 additions & 55 deletions
Large diffs are not rendered by default.

src/nimblepkg/declarativeparser.nim

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import compiler/[ast, idents, msgs, syntaxes, options, pathutils, lineinfos]
77
import compiler/[renderer]
88
from compiler/nimblecmd import getPathVersionChecksum
99

10-
import version, packageinfotypes, packageinfo, options, packageparser, cli
11-
import sha1hashes
10+
import version, packageinfotypes, packageinfo, options, packageparser, cli,
11+
packagemetadatafile
12+
import sha1hashes, vcstools
1213
import std/[tables, sequtils, strscans, strformat, os, options]
1314

1415
type NimbleFileInfo* = object
@@ -56,12 +57,22 @@ proc validateNoNestedRequires(nfl: var NimbleFileInfo, n: PNode, conf: ConfigRef
5657
for child in n:
5758
validateNoNestedRequires(nfl, child, conf, hasErrors, nestedRequires, true)
5859
of nkCallKinds:
59-
if n[0].kind == nkIdent and n[0].ident.s == "requires":
60-
if inControlFlow:
60+
if n[0].kind == nkIdent:
61+
if n[0].ident.s == "requires":
62+
if inControlFlow:
63+
nestedRequires = true
64+
let errorLine = &"{nfl.nimbleFile}({n.info.line}, {n.info.col}) 'requires' cannot be nested inside control flow statements"
65+
nfl.declarativeParserErrorLines.add errorLine
66+
hasErrors = true
67+
elif n[0].ident.s == "taskRequires":
68+
# taskRequires is not supported in declarative parser yet
6169
nestedRequires = true
62-
let errorLine = &"{nfl.nimbleFile}({n.info.line}, {n.info.col}) 'requires' cannot be nested inside control flow statements"
70+
let errorLine = &"{nfl.nimbleFile}({n.info.line}, {n.info.col}) 'taskRequires' is not supported in declarative parser"
6371
nfl.declarativeParserErrorLines.add errorLine
6472
hasErrors = true
73+
else:
74+
for child in n:
75+
validateNoNestedRequires(nfl, child, conf, hasErrors, nestedRequires, inControlFlow)
6576
else:
6677
for child in n:
6778
validateNoNestedRequires(nfl, child, conf, hasErrors, nestedRequires, inControlFlow)
@@ -400,7 +411,9 @@ proc toRequiresInfo*(pkgInfo: PackageInfo, options: Options, nimbleFileInfo: Opt
400411
return result
401412
else:
402413
displayWarning &"Package {pkgInfo.basicInfo.name} is a babel package, skipping declarative parser", priority = HighPriority
403-
return getPkgInfo(pkgInfo.myPath.parentDir, options)
414+
result = getPkgInfo(pkgInfo.myPath.parentDir, options)
415+
fillMetaData(result, result.getRealDir(), false, options)
416+
return result
404417

405418
let nimbleFileInfo = nimbleFileInfo.get(extractRequiresInfo(pkgInfo.myPath))
406419
result.requires = getRequires(nimbleFileInfo, result.activeFeatures)
@@ -424,6 +437,17 @@ proc toRequiresInfo*(pkgInfo: PackageInfo, options: Options, nimbleFileInfo: Opt
424437
# echo "Fallback to VM parser for package: ", pkgInfo.basicInfo.name
425438
# echo "Requires: ", result.requires
426439
result.features = getFeatures(nimbleFileInfo)
440+
result.srcDir = nimbleFileInfo.srcDir
441+
fillMetaData(result, result.getRealDir(), false, options)
442+
443+
# For develop mode dependencies, ensure VCS revision is set
444+
if result.isLink and result.metaData.vcsRevision == notSetSha1Hash:
445+
try:
446+
result.metaData.vcsRevision = getVcsRevision(result.getRealDir())
447+
except CatchableError:
448+
# If we can't get VCS revision, leave it as notSetSha1Hash
449+
discard
450+
427451
if pkgInfo.infoKind == pikRequires:
428452
result.bin = nimbleFileInfo.bin #Noted that we are not parsing namedBins here, they are only parsed wit full info
429453

@@ -438,14 +462,11 @@ proc fillPkgBasicInfo(pkgInfo: var PackageInfo, nimbleFileInfo: NimbleFileInfo)
438462
pkgInfo.basicInfo.checksum = sha1Checksum
439463
pkgInfo.myPath = nimbleFileInfo.nimbleFile
440464
pkgInfo.basicInfo.version = newVersion nimbleFileInfo.version
465+
pkgInfo.srcDir = nimbleFileInfo.srcDir
441466

442467
proc getPkgInfoFromDirWithDeclarativeParser*(dir: string, options: Options): PackageInfo =
443468
let nimbleFile = findNimbleFile(dir, true, options)
444469
let nimbleFileInfo = extractRequiresInfo(nimbleFile)
445470
result = initPackageInfo()
446471
fillPkgBasicInfo(result, nimbleFileInfo)
447-
result = toRequiresInfo(result, options, some nimbleFileInfo)
448-
449-
when isMainModule:
450-
for x in tokenizeRequires("jester@#head >= 1.5 & <= 1.8"):
451-
echo x
472+
result = toRequiresInfo(result, options, some nimbleFileInfo)

src/nimblepkg/developfile.nim

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ proc validatePackage(pkgPath: Path, options: Options):
173173

174174
try:
175175
if options.isVnext: #TODO add and test fallback to nimVM parser (i.e. dev pkgList would need to be reloaded)
176-
result.pkgInfo = getPkgInfoFromDirWithDeclarativeParser(string(pkgPath), options)
176+
if options.satResult.pass == satNimSelection:
177+
result.pkgInfo = getPkgInfoFromDirWithDeclarativeParser(string(pkgPath), options)
178+
#TODO find a way to validate the package, for now just mark the declarativeParser as failed
179+
#as we dont have Nim selected yet.
180+
options.satResult.declarativeParseFailed = true
181+
else:
182+
result.pkgInfo = getPkgInfo(string(pkgPath), options, true)
177183
else:
178184
result.pkgInfo = getPkgInfo(string(pkgPath), options, true)
179185
except CatchableError as error:
@@ -734,13 +740,16 @@ proc processDevelopDependencies*(dependentPkg: PackageInfo, options: Options):
734740
seq[PackageInfo] =
735741
## Returns a sequence with the develop mode dependencies of the `dependentPkg`
736742
## and recursively all of their develop mode dependencies.
737-
743+
738744
let loadGlobalDeps = not dependentPkg.getPkgDevFilePath.fileExists
739745
var cache = DevelopCache()
740746
let data = load(cache, dependentPkg, options, true, true, loadGlobalDeps)
741747
result = newSeqOfCap[PackageInfo](data.nameToPkg.len)
742748
for _, pkg in data.nameToPkg:
743749
result.add pkg[]
750+
# echo "PROCESS DEVELOP DEPENDENCIES ", result.mapIt(it.basicInfo.name)
751+
# echo "SAT RESULT ", options.satResult.pkgs.mapIt(it.basicInfo.name)
752+
# options.debugSATResult()
744753

745754
proc getDevelopDependencies*(dependentPkg: PackageInfo, options: Options, raiseOnValidationErrors = true):
746755
Table[string, ref PackageInfo] =
@@ -869,6 +878,8 @@ proc workingCopyNeeds*(dependencyPkg, dependentPkg: PackageInfo,
869878
syncFileVcsRev = syncFile.getDepVcsRevision(dependencyPkg.basicInfo.name)
870879
workingCopyVcsRev = getVcsRevision(dependencyPkg.getNimbleFileDir)
871880

881+
882+
872883
if lockFileVcsRev == syncFileVcsRev and syncFileVcsRev == workingCopyVcsRev:
873884
# When all revisions are matching nothing have to be done.
874885
return needsNone
@@ -897,8 +908,17 @@ proc workingCopyNeeds*(dependencyPkg, dependentPkg: PackageInfo,
897908
lockFileVcsRev != workingCopyVcsRev and
898909
syncFileVcsRev != workingCopyVcsRev:
899910
# When all revisions are different from one another this indicates that
900-
# there are local changes which are conflicting with remote changes. The
911+
# there are local changes which are in conflict with the remote changes. The
901912
# user have to resolve them manually by merging or rebasing.
913+
914+
# However, there's a special case: if the sync file is empty/uninitialized,
915+
# this might be because develop dependencies were added after lock file creation.
916+
# In this case, we should default to needsSync rather than needsMerge.
917+
if syncFileVcsRev == notSetSha1Hash or $syncFileVcsRev == "":
918+
# With empty sync file, default to sync for the common case where
919+
# develop dependencies are added after lock file creation
920+
return needsSync
921+
902922
return needsMerge
903923

904924
assert false, "Here all cases are covered and the program " &
@@ -921,8 +941,15 @@ proc findValidationErrorsOfDevDepsWithLockFile*(
921941
dependentPkg.assertIsLoaded
922942

923943
let developDependencies = processDevelopDependencies(dependentPkg, options)
944+
945+
let rootRequiredNames = dependentPkg.requires.mapIt(it.name.toLowerAscii()).toHashSet()
924946

925947
for depPkg in developDependencies:
948+
# Skip validation for packages that are not actual dependencies
949+
#TODO REVIEW THIS
950+
if depPkg.basicInfo.name.toLowerAscii() notin rootRequiredNames:
951+
continue
952+
926953
if depPkg.pkgDirIsNotUnderVersionControl:
927954
addError(vekDirIsNotUnderVersionControl)
928955
elif depPkg.workingCopyIsNotClean:

src/nimblepkg/download.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ proc doClone(meth: DownloadMethod, url, downloadDir: string, branch = "",
4242
discard tryDoCmdEx(
4343
"git clone --config core.autocrlf=false --config core.eol=lf " &
4444
&"{submoduleFlag} {depthArg} {branchArg} {url} {downloadDir}")
45+
if not options.ignoreSubmodules:
46+
downloadDir.updateSubmodules
4547
of DownloadMethod.hg:
4648
let
4749
tipArg = if onlyTip: "-r tip " else: ""
@@ -90,7 +92,7 @@ proc getTagsListRemote*(url: string, meth: DownloadMethod): seq[string] =
9092
var (output, exitCode) = doCmdEx(&"git ls-remote --tags {url}")
9193
if exitCode != QuitSuccess:
9294
raise nimbleError("Unable to query remote tags for " & url &
93-
". Git returned: " & output)
95+
" . Git returned: " & output)
9496
for i in output.splitLines():
9597
let refStart = i.find("refs/tags/")
9698
# git outputs warnings, empty lines, etc
@@ -196,10 +198,12 @@ proc isGitHubRepo(url: string): bool =
196198

197199
proc downloadTarball(url: string, options: Options): bool =
198200
## Determines whether to download the repository as a tarball.
201+
## Tarballs don't include git submodules, so we must use git clone when submodules are needed.
199202
options.enableTarballs and
200203
not options.forceFullClone and
201204
url.isGitHubRepo and
202-
hasTar()
205+
hasTar() and
206+
options.ignoreSubmodules # Only use tarballs when ignoring submodules
203207

204208
proc removeTrailingGitString*(url: string): string =
205209
## Removes ".git" from an URL.

src/nimblepkg/nimblesat.nim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,9 @@ proc getSolvedPackages*(pkgVersionTable: Table[string, PackageVersions], output:
499499
proc getCacheDownloadDir*(url: string, ver: VersionRange, options: Options): string =
500500
options.pkgCachePath / getDownloadDirName(url, ver, notSetSha1Hash)
501501

502-
proc getPackageDownloadInfo*(pv: PkgTuple, options: Options): PackageDownloadInfo =
502+
proc getPackageDownloadInfo*(pv: PkgTuple, options: Options, doPrompt = false): PackageDownloadInfo =
503503
let (meth, url, metadata) =
504-
getDownloadInfo(pv, options, doPrompt = false, ignorePackageCache = false)
504+
getDownloadInfo(pv, options, doPrompt, ignorePackageCache = false)
505505
let subdir = metadata.getOrDefault("subdir")
506506
let downloadDir = getCacheDownloadDir(url, pv.ver, options)
507507
PackageDownloadInfo(meth: meth, url: url, subdir: subdir, downloadDir: downloadDir, pv: pv)
@@ -511,12 +511,12 @@ proc downloadFromDownloadInfo*(dlInfo: PackageDownloadInfo, options: Options): (
511511
dlInfo.downloadDir, vcsRevision = notSetSha1Hash)
512512
(downloadRes, dlInfo.meth)
513513

514-
proc downloadPkgFromUrl*(pv: PkgTuple, options: Options): (DownloadPkgResult, DownloadMethod) =
515-
let dlInfo = getPackageDownloadInfo(pv, options)
514+
proc downloadPkgFromUrl*(pv: PkgTuple, options: Options, doPrompt = false): (DownloadPkgResult, DownloadMethod) =
515+
let dlInfo = getPackageDownloadInfo(pv, options, doPrompt)
516516
downloadFromDownloadInfo(dlInfo, options)
517517

518-
proc downloadPkInfoForPv*(pv: PkgTuple, options: Options): PackageInfo =
519-
let downloadRes = downloadPkgFromUrl(pv, options)
518+
proc downloadPkInfoForPv*(pv: PkgTuple, options: Options, doPrompt = false): PackageInfo =
519+
let downloadRes = downloadPkgFromUrl(pv, options, doPrompt)
520520
if options.satResult.pass in {satNimSelection, satFallbackToVmParser}:
521521
getPkgInfoFromDirWithDeclarativeParser(downloadRes[0].dir, options)
522522
else:
@@ -600,12 +600,12 @@ proc getPackageMinimalVersionsFromRepo*(repoDir: string, pkg: PkgTuple, version:
600600

601601
if not tagVersion.withinRange(pkg[1]):
602602
displayInfo(&"Ignoring {name}:{tagVersion} because out of range {pkg[1]}")
603-
break
603+
continue
604604

605605
doCheckout(downloadMethod, tempDir, tag, options)
606606
let nimbleFile = findNimbleFile(tempDir, true, options)
607607
if options.satResult.pass in {satNimSelection, satFallbackToVmParser}:
608-
result.addUnique getPkgInfoFromDirWithDeclarativeParser(repoDir, options).getMinimalInfo(options)
608+
result.addUnique getPkgInfoFromDirWithDeclarativeParser(tempDir, options).getMinimalInfo(options)
609609
elif options.useDeclarativeParser:
610610
result.addUnique getMinimalInfo(nimbleFile, name, options)
611611
else:

0 commit comments

Comments
 (0)