Skip to content

Commit 22b0764

Browse files
authored
Improvements towards supporting big packages (nwaku) (#1532)
* Add PackageNotFoundError for specific error handling - Add PackageNotFoundError exception type in common.nim - Use PackageNotFoundError in download.nim when package is not found - Catch PackageNotFoundError instead of CatchableError in nimblesat.nim validation to only skip versions for truly missing packages * Fix git checkout for version tags with v prefix Some packages use 'v' prefixed tags (e.g., v0.1.0) while the version in nimble is without prefix (0.1.0). When checkout fails, try again with 'v' prefix as fallback. * Prefer tagged releases over HEAD revision Add specialized addUnique for PackageMinimalInfo that compares by name and version only. This ensures when multiple nimble file revisions exist for the same version tag, we keep the first one. Change processing order in getPackageMinimalVersionsFromRepo and getPackageMinimalVersionsFromRepoAsync to: 1. Process tagged versions first (added to result) 2. Add HEAD version last using addUnique This ensures tagged releases take precedence over HEAD when both have the same version, providing more reliable package metadata. * Move updateSubmodules outside of the cache. Its faster and more reliable (old pkgs may trigger potential errors) * Improves SAT solver so it process versions on ascending order. Adds version discovery option * Some installation fixes. * Adds a tests that proofs that waku's deps can be solved * Fixes CI test
1 parent 80c5afd commit 22b0764

File tree

6 files changed

+3248
-78
lines changed

6 files changed

+3248
-78
lines changed

src/nimblepkg/common.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type
1313

1414
BuildFailed* = object of NimbleError
1515

16+
PackageNotFoundError* = object of NimbleError
17+
## Raised when a package cannot be found in any repository
18+
1619
## Same as quit(QuitSuccess) or quit(QuitFailure), but allows cleanup.
1720
## Inheriting from `Defect` is workaround to avoid accidental catching of
1821
## `NimbleQuit` by `CatchableError` handlers.

src/nimblepkg/download.nim

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ type
1515
version: Version
1616
vcsRevision: Sha1Hash
1717

18-
proc updateSubmodules(dir: string) =
18+
proc updateSubmodules*(dir: string) =
19+
## Updates git submodules in the given directory.
20+
## Called during installation to ensure submodules are populated
21+
## even if the package was cached without them during version discovery.
1922
discard tryDoCmdEx(
2023
&"git -C {dir.quoteShell} submodule update --init --recursive --depth 1")
2124

@@ -37,7 +40,10 @@ proc doCheckout*(meth: DownloadMethod, downloadDir, branch: string, options: Opt
3740
# Force is used here because local changes may appear straight after a clone
3841
# has happened. Like in the case of git on Windows where it messes up the
3942
# damn line endings.
40-
discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} checkout --force {branch.quoteShell}")
43+
let (_, exitCode) = doCmdEx(&"git -C {downloadDir.quoteShell} checkout --force {branch.quoteShell}")
44+
if exitCode != 0 and not branch.startsWith("v"):
45+
# Try with 'v' prefix as fallback (common convention for version tags)
46+
discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} checkout --force v{branch.quoteShell}")
4147
if not options.ignoreSubmodules:
4248
downloadDir.updateSubmodules
4349
of DownloadMethod.hg:
@@ -50,7 +56,10 @@ proc doCheckoutAsync*(meth: DownloadMethod, downloadDir, branch: string, options
5056
# Force is used here because local changes may appear straight after a clone
5157
# has happened. Like in the case of git on Windows where it messes up the
5258
# damn line endings.
53-
discard await tryDoCmdExAsync(&"git -C {downloadDir.quoteShell} checkout --force {branch.quoteShell}")
59+
let (_, exitCode) = await doCmdExAsync(&"git -C {downloadDir.quoteShell} checkout --force {branch.quoteShell}")
60+
if exitCode != 0 and not branch.startsWith("v"):
61+
# Try with 'v' prefix as fallback (common convention for version tags)
62+
discard await tryDoCmdExAsync(&"git -C {downloadDir.quoteShell} checkout --force v{branch.quoteShell}")
5463
if not options.ignoreSubmodules:
5564
await downloadDir.updateSubmodulesAsync()
5665
of DownloadMethod.hg:
@@ -1046,7 +1055,7 @@ proc getDownloadInfo*(
10461055
# Also ignore the package cache so the old info isn't used
10471056
return getDownloadInfo(pv, options, false, true)
10481057
else:
1049-
raise nimbleError(pkgNotFoundMsg(pv))
1058+
raise newNimbleError[PackageNotFoundError](pkgNotFoundMsg(pv))
10501059

10511060
when isMainModule:
10521061
import unittest

0 commit comments

Comments
 (0)