Skip to content

Commit 2f553f9

Browse files
authored
Adds legacy flag (defaults to true) (#1409)
1 parent ce4e377 commit 2f553f9

File tree

9 files changed

+43
-32
lines changed

9 files changed

+43
-32
lines changed

src/nimble.nim

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
834834
# their local file system directories and other packages from the Nimble
835835
# cache. If a package with required checksum is missing from the local cache
836836
# installs it by downloading it from its repository.
837-
if options.isVNext:
837+
if not options.isLegacy:
838838
return options.satResult.pkgs
839839

840840
let developModeDeps = getDevelopDependencies(pkgInfo, options, raiseOnValidationErrors = false)
@@ -1046,15 +1046,15 @@ proc execBackend(pkgInfo: PackageInfo, options: Options) =
10461046
nimScriptHint(pkgInfo)
10471047

10481048
let deps =
1049-
if options.isVNext:
1049+
if not options.isLegacy:
10501050
options.satResult.pkgs
10511051
else:
10521052
pkgInfo.processAllDependencies(options)
10531053
if not execHook(options, options.action.typ, true):
10541054
raise nimbleError("Pre-hook prevented further execution.")
10551055

10561056
var args = @["-d:NimblePkgVersion=" & $pkgInfo.basicInfo.version]
1057-
if options.isVNext:
1057+
if not options.isLegacy:
10581058
for path in options.getPathsAllPkgs():
10591059
args.add("--path:" & path.quoteShell)
10601060
else:
@@ -1726,7 +1726,7 @@ proc updateSyncFile(dependentPkg: PackageInfo, options: Options)
17261726

17271727
proc updatePathsFile(pkgInfo: PackageInfo, options: Options) =
17281728
let paths =
1729-
if options.isVNext:
1729+
if not options.isLegacy:
17301730
#TODO improve this (or better the alternative, getDependenciesPaths, so it returns the same type)
17311731
var pathsPaths = initHashSet[seq[string]]()
17321732
for path in options.getPathsAllPkgs():
@@ -2029,11 +2029,11 @@ proc lock(options: var Options) =
20292029
# Clear package info cache to ensure we read the latest nimble file
20302030
# This is important when the nimble file has been modified since the last read
20312031
# In vnext mode, the cache clearing is done before runVNext is called
2032-
if not options.isVNext:
2032+
if options.isLegacy:
20332033
options.pkgInfoCache.clear()
20342034

20352035
let
2036-
pkgInfo = if options.isVNext:
2036+
pkgInfo = if not options.isLegacy:
20372037
options.satResult.rootPackage
20382038
else:
20392039
getPkgInfo(currentDir, options)
@@ -2042,7 +2042,7 @@ proc lock(options: var Options) =
20422042

20432043
var
20442044
baseDeps =
2045-
if options.isVNext:
2045+
if not options.isLegacy:
20462046
options.satResult.pkgs.toSeq
20472047
elif options.useSATSolver:
20482048
processFreeDependenciesSAT(pkgInfo, options).toSeq
@@ -2081,7 +2081,7 @@ proc lock(options: var Options) =
20812081
# Now build graph for all dependencies
20822082
taskOptions.checkSatisfied(taskDeps)
20832083

2084-
if options.isVNext:
2084+
if not options.isLegacy:
20852085
# vnext path: generate lockfile from solved packages
20862086
# Check for develop dependency validation errors
20872087
# Create a minimal graph for error checking - only include actual dependencies, not root package
@@ -2312,7 +2312,7 @@ proc sync(options: Options) =
23122312

23132313
let currentDir = getCurrentDir()
23142314
let pkgInfo =
2315-
if options.isVNext:
2315+
if not options.isLegacy:
23162316
options.satResult.rootPackage
23172317
else:
23182318
getPkgInfo(currentDir, options)
@@ -2457,12 +2457,12 @@ proc setup(options: Options) =
24572457
proc getAlteredPath(options: Options): string =
24582458

24592459
let pkgInfo =
2460-
if options.isVNext:
2460+
if not options.isLegacy:
24612461
options.satResult.rootPackage
24622462
else:
24632463
getPkgInfo(getCurrentDir(), options)
24642464
var pkgs =
2465-
if options.isVNext:
2465+
if not options.isLegacy:
24662466
options.satResult.pkgs.toSeq.toOrderedSet
24672467
else:
24682468
pkgInfo.processAllDependencies(options).toSeq.toOrderedSet
@@ -2507,7 +2507,7 @@ proc getPackageForAction(pkgInfo: PackageInfo, options: Options): PackageInfo =
25072507
if options.package.len == 0 or pkgInfo.basicInfo.name == options.package:
25082508
return pkgInfo
25092509

2510-
if options.isVNext:
2510+
if not options.isLegacy:
25112511
# Search through the SAT result packages as the packages are already solved
25122512
for pkg in options.satResult.pkgs:
25132513
if pkg.basicInfo.name == options.package:
@@ -2526,7 +2526,7 @@ proc getPackageForAction(pkgInfo: PackageInfo, options: Options): PackageInfo =
25262526

25272527
proc run(options: Options) =
25282528
var pkgInfo: PackageInfo
2529-
if options.isVNext: #At this point we already ran the solver
2529+
if not options.isLegacy: #At this point we already ran the solver
25302530
pkgInfo = options.satResult.rootPackage
25312531
pkgInfo = getPackageForAction(pkgInfo, options)
25322532
else:
@@ -2540,7 +2540,7 @@ proc run(options: Options) =
25402540
if binary notin pkgInfo.bin:
25412541
raise nimbleError(binaryNotDefinedInPkgMsg(binary, pkgInfo.basicInfo.name))
25422542

2543-
if options.isVNext:
2543+
if not options.isLegacy:
25442544
# In vnext path, build develop mode packages (similar to old code path)
25452545
if pkgInfo.isLink:
25462546
# Use vnext buildPkg for develop mode packages
@@ -2662,7 +2662,7 @@ proc doAction(options: var Options) =
26622662
of actionRefresh:
26632663
refresh(options)
26642664
of actionInstall:
2665-
if not options.isVNext:
2665+
if options.isLegacy:
26662666
let (_, pkgInfo) = install(options.action.packages, options,
26672667
doPrompt = true,
26682668
first = true,
@@ -2690,7 +2690,7 @@ proc doAction(options: var Options) =
26902690
of actionPath:
26912691
listPaths(options)
26922692
of actionBuild:
2693-
if not options.isVNext:
2693+
if options.isLegacy:
26942694
build(options)
26952695
of actionClean:
26962696
clean(options)
@@ -2744,7 +2744,7 @@ proc doAction(options: var Options) =
27442744
# Make sure we have dependencies for the task.
27452745
# We do that here to make sure that any binaries from dependencies
27462746
# are installed
2747-
if not optsCopy.isVNext:
2747+
if optsCopy.isLegacy:
27482748
discard pkgInfo.processAllDependencies(optsCopy)
27492749
# If valid task defined in nimscript, run it
27502750
var execResult: ExecutionResult[bool]
@@ -2881,7 +2881,7 @@ when isMainModule:
28812881
actionShellEnv, actionShell, actionUpgrade
28822882
}
28832883

2884-
if opt.isVNext and opt.action.typ in vNextSupportedActions:
2884+
if not opt.isLegacy and opt.action.typ in vNextSupportedActions:
28852885
# For actionCustom, set the task name before calling runVNext
28862886
if opt.action.typ == actionCustom:
28872887
opt.task = opt.action.command.normalize

src/nimblepkg/developfile.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ proc validatePackage(pkgPath: Path, options: Options):
172172
## not a valid package directory.
173173

174174
try:
175-
if options.isVnext: #TODO add and test fallback to nimVM parser (i.e. dev pkgList would need to be reloaded)
175+
if not options.isLegacy: #TODO add and test fallback to nimVM parser (i.e. dev pkgList would need to be reloaded)
176176
if options.satResult.pass == satNimSelection:
177177
result.pkgInfo = getPkgInfoFromDirWithDeclarativeParser(string(pkgPath), options)
178178
#TODO find a way to validate the package, for now just mark the declarativeParser as failed

src/nimblepkg/download.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ proc downloadPkg*(url: string, verRange: VersionRange,
524524
modUrl, downloadDir, verRange, downMethod, options, vcsRevision)
525525

526526
var pkgInfo: PackageInfo
527-
if validateRange and verRange.kind notin {verSpecial, verAny} or options.isVNext:
527+
if validateRange and verRange.kind notin {verSpecial, verAny} or not options.isLegacy:
528528
## Makes sure that the downloaded package's version satisfies the requested
529529
## version range.
530530
pkginfo = if options.satResult.pass in {satNimSelection, satFallbackToVmParser}: #TODO later when in vnext we should just use this code path and fallback inside the toRequires if we can

src/nimblepkg/nimblesat.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ proc getPackageMinimalVersionsFromRepo*(repoDir: string, pkg: PkgTuple, version:
615615
displayWarning(
616616
&"Error reading tag {tag}: for package {name}. This may not be relevant as it could be an old version of the package. \n {e.msg}",
617617
HighPriority)
618-
if not (options.isVNext and options.satResult.pass == satNimSelection and options.satResult.declarativeParseFailed):
618+
if not (not options.isLegacy and options.satResult.pass == satNimSelection and options.satResult.declarativeParseFailed):
619619
#Dont save tagged versions if we are in vNext and the declarative parser failed as this could cache the incorrect versions.
620620
#its suboptimal in the sense that next packages after failure wont be saved in the first past but there is a guarantee that there is a second pass in the case
621621
#the declarative parser fails so they will be saved then.

src/nimblepkg/options.nim

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type
7070
features*: seq[string] # Features to be activated. Only used when using the declarative parser
7171
ignoreSubmodules*: bool # Whether to ignore submodules when cloning a repository
7272
satResult*: SatResult
73+
legacy*: bool # Whether to use the legacy code path.
7374

7475
ActionType* = enum
7576
actionNil, actionRefresh, actionInit, actionDump, actionPublish, actionUpgrade
@@ -282,7 +283,7 @@ Nimble Options:
282283
--parser:declarative|nimvm Use the declarative parser or the nimvm parser (default).
283284
--features Activate features. Only used when using the declarative parser.
284285
--ignoreSubmodules Ignore submodules when cloning a repository.
285-
--vnext Temporary flag (not shipped) to use the new code path where we assume solver is SAT and declarative parser are enabled. Later on, when both are enabled `vnext` code path will be used.
286+
--legacy Use the legacy code path (pre nimble 1.0.0)
286287
For more information read the GitHub readme:
287288
https://github.com/nim-lang/nimble#readme
288289
"""
@@ -634,6 +635,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
634635
of "package", "p": result.package = val
635636
of "lockfile": result.lockFileName = val
636637
of "usesystemnim": result.useSystemNim = true
638+
of "legacy": result.legacy = true
637639
of "developfile":
638640
if result.developFile.len == 0:
639641
result.developFile = val.normalizedPath
@@ -798,6 +800,7 @@ proc initOptions*(): Options =
798800
maxTaggedVersions: 4,
799801
useSatSolver: true,
800802
useDeclarativeParser: false,
803+
legacy: true, #default to legacy code path for nimble < 1.0.0
801804
satResult: SatResult()
802805
)
803806

@@ -823,6 +826,10 @@ proc handleUnknownFlags(options: var Options) =
823826
for flag in unknownFlags:
824827
parseFlag(flag[1], flag[2], options, flag[0])
825828

829+
if not options.legacy:
830+
#default to declarative parser for new code path.
831+
options.useDeclarativeParser = true
832+
826833
# Any unhandled flags?
827834
if options.unknownFlags.len > 0:
828835
let flag = options.unknownFlags[0]
@@ -968,5 +975,9 @@ proc isDevelopment*(pkg: PackageInfo, options: Options): bool =
968975
### A development package is a root package that is not installed.
969976
not pkg.myPath.parentDir.startsWith(options.getPkgsDir())
970977

971-
proc isVNext*(options: Options): bool =
972-
options.useDeclarativeParser
978+
proc isLegacy*(options: Options): bool =
979+
let isVnext = not options.legacy or options.useDeclarativeParser
980+
if isVnext:
981+
once:
982+
displayWarning("Using the new code path. This is experimental and may break in the future.")
983+
return not isVnext

src/nimblepkg/packageinfo.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ proc iterInstallFiles*(realDir: string, pkgInfo: PackageInfo,
482482

483483
# Create a mapping of lowercase filesystem names to metadata names
484484
var metadataNameMap: Table[string, string]
485-
if options.isVNext:
485+
if not options.isLegacy:
486486
#in vnext we dont use the whitelist mode as we install all files since we want to build the package in the
487487
#install dir. BUT we need to respect package metadata naming for specific files.
488488
whitelistMode = false
@@ -554,7 +554,7 @@ proc iterInstallFiles*(realDir: string, pkgInfo: PackageInfo,
554554
let skip = pkgInfo.checkInstallFile(realDir, file)
555555
if skip:
556556
# In vnext mode, don't skip .nim files that are needed for binary compilation
557-
if options.isVNext and file.splitFile.ext == ".nim":
557+
if not options.isLegacy and file.splitFile.ext == ".nim":
558558
let fileName = file.splitFile.name
559559
var isNeededForBinary = false
560560
for binName, srcName in pkgInfo.bin:
@@ -568,7 +568,7 @@ proc iterInstallFiles*(realDir: string, pkgInfo: PackageInfo,
568568
continue
569569

570570
# In vnext mode, skip binary files that match package binary names to avoid conflicts
571-
if options.isVNext:
571+
if not options.isLegacy:
572572
let fileName = file.splitFile.name
573573
let fileExt = file.splitFile.ext
574574
var skipBinary = false
@@ -581,7 +581,7 @@ proc iterInstallFiles*(realDir: string, pkgInfo: PackageInfo,
581581
if skipBinary: continue
582582

583583
# For vnext: Handle symbolic links and case sensitivity
584-
if options.isVNext:
584+
if not options.isLegacy:
585585
let relativePath = file.relativePath(realDir)
586586
let normalizedPath = relativePath.toLowerAscii()
587587

@@ -609,7 +609,7 @@ proc needsRebuild*(pkgInfo: PackageInfo, bin: string, dir: string, options: Opti
609609
if options.action.typ != actionInstall:
610610
return true
611611

612-
if options.isVNext:
612+
if not options.isLegacy:
613613
if options.action.noRebuild:
614614
if not fileExists(bin):
615615
return true

src/nimblepkg/packageparser.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ proc inferInstallRules(pkgInfo: var PackageInfo, options: Options) =
261261
# installed.)
262262
let installInstructions =
263263
pkgInfo.installDirs.len + pkgInfo.installExt.len + pkgInfo.installFiles.len
264-
if installInstructions == 0 and pkgInfo.bin.len > 0 and pkgInfo.basicInfo.name != "nim" and not options.isVNext: #dont skip nim files for vnext. We build in the install directory
264+
if installInstructions == 0 and pkgInfo.bin.len > 0 and pkgInfo.basicInfo.name != "nim" and options.isLegacy: #dont skip nim files for vnext. We build in the install directory
265265
pkgInfo.skipExt.add("nim")
266266

267267
# When a package doesn't specify a `srcDir` it's fair to assume that

src/nimblepkg/topologicalsort.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ proc deleteStaleDependencies*(packages: seq[PackageInfo],
4242
# For lock operations in vnext mode, only include packages that are actual dependencies
4343
# This filters out packages in the develop file that are not real dependencies
4444
# Only apply this filtering for direct lock operations (no packages specified), not for upgrade operations
45-
if options.action.typ == actionLock and options.isVNext and options.action.packages.len == 0:
45+
if options.action.typ == actionLock and not options.isLegacy and options.action.packages.len == 0:
4646
let all = allDependencies(concat(rootPackage.requires,
4747
rootPackage.taskRequires.getOrDefault(options.task)),
4848
packages,

src/nimblepkg/vnext.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ proc getDepsPkgInfo(satResult: SATResult, pkgInfo: PackageInfo, options: Options
554554

555555
proc expandPaths*(pkgInfo: PackageInfo, options: Options): seq[string] =
556556
var pkgInfo = pkgInfo.toFullInfo(options) #TODO is this needed in VNEXT? I dont think so
557-
if options.isVNext:
557+
if not options.isLegacy:
558558
pkgInfo = pkgInfo.toRequiresInfo(options)
559559
let baseDir = pkgInfo.getRealDir()
560560
result = @[baseDir]

0 commit comments

Comments
 (0)