From b9258cb231f235a6b8dfa59036e13ce7b57dc7f3 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Sun, 7 Apr 2024 16:38:21 +0300 Subject: [PATCH] fixing vendor deps integration --- src/atlas.nim | 4 +++- src/depgraphs.nim | 31 ++++++++++++++++++++++++------- src/gitops.nim | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/atlas.nim b/src/atlas.nim index 7210ef5..fee2c6f 100644 --- a/src/atlas.nim +++ b/src/atlas.nim @@ -223,8 +223,10 @@ proc installDependencies(c: var AtlasContext; nc: var NimbleContext; nimbleFile: # 2. install deps from .nimble let (dir, pkgname, _) = splitFile(nimbleFile) info c, pkgname, "installing dependencies for " & pkgname & ".nimble" - var g = createGraph(c, createUrlSkipPatterns(dir)) + debug c, pkgname, "installing dependencies using nimble at " & $absolutePath(nimbleFile) + var g = createGraph(c, createUrlSkipPatterns(dir), nimbleFile=nimbleFile.some, ondisk=dir.absolutePath()) trace c, pkgname, "traversing depency loop" + trace c, pkgname, "traversing depency loop: " & $g.nodes let paths = traverseLoop(c, nc, g) trace c, pkgname, "done traversing depencies" let cfgPath = if CfgHere in c.flags: CfgPath c.currentDir else: findCfgDir(c) diff --git a/src/depgraphs.nim b/src/depgraphs.nim index b2546cc..c4cfcdc 100644 --- a/src/depgraphs.nim +++ b/src/depgraphs.nim @@ -35,7 +35,7 @@ type nimbleFile*: Option[string] DepGraph* = object - nodes: seq[Dependency] + nodes*: seq[Dependency] reqs: seq[Requirements] packageToDependency: Table[PkgUrl, int] ondisk: OrderedTable[string, string] # URL -> dirname mapping @@ -76,10 +76,15 @@ proc readOnDisk(c: var AtlasContext; result: var DepGraph) = except: error c, configFile, "cannot read: " & configFile -proc createGraph*(c: var AtlasContext; s: PkgUrl, readConfig = true): DepGraph = +proc createGraph*(c: var AtlasContext; s: PkgUrl; + readConfig = true, + nimbleFile = string.none, + ondisk = ""): DepGraph = result = DepGraph(nodes: @[], reqs: defaultReqs()) result.packageToDependency[s] = result.nodes.len - result.nodes.add Dependency(pkg: s, versions: @[], isRoot: true, isTopLevel: true, activeVersion: -1) + result.nodes.add Dependency(pkg: s, versions: @[], + isRoot: true, isTopLevel: true, activeVersion: -1, + nimbleFile: nimbleFile, ondisk: ondisk) if readConfig: readOnDisk(c, result) @@ -275,13 +280,21 @@ type proc pkgUrlToDirname(c: var AtlasContext; g: var DepGraph; d: var Dependency): (string, PackageAction) = # XXX implement namespace support here - var dest = g.ondisk.getOrDefault(d.pkg.url) - trace c, d.pkg.projectName, "using dirname: " & $dest & " for url: " & $d.pkg.url + var dest = if d.ondisk.len() > 0: d.ondisk + else: g.ondisk.getOrDefault(d.pkg.url) + trace c, d.pkg.projectName, "using dirname: `" & $absolutePath(dest) & "` for url: " & $d.pkg.url if dest.len == 0: if d.isTopLevel: + debug c, d.pkg.projectName, "using toplevel dirname: `" & $c.workspace dest = c.workspace else: - let depsDir = if d.isRoot: c.workspace else: c.depsDir + let depsDir = + if d.isRoot: + debug c, d.pkg.projectName, "using root dirname: `" & $c.workspace + c.workspace + else: + debug c, d.pkg.projectName, "using depsDir dirname: `" & $c.depsDir + c.depsDir dest = depsDir / d.pkg.projectName result = (dest, if dirExists(dest): DoNothing else: DoClone) @@ -292,10 +305,13 @@ proc expand*(c: var AtlasContext; g: var DepGraph; nc: NimbleContext; m: Travers ## Expand the graph by adding all dependencies. var processed = initHashSet[PkgUrl]() var i = 0 + trace c, "atlas:expanding", "nodes count: " & $g.nodes.len + for node in g.nodes: + trace c, "expand", "nodes: " & $node while i < g.nodes.len: if not processed.containsOrIncl(g.nodes[i].pkg): let (dest, todo) = pkgUrlToDirname(c, g, g.nodes[i]) - trace c, $g.nodes[i].pkg.projectName, "expanded destination dir: " & $dest + trace c, $g.nodes[i].pkg.projectName, "expanded destination dir: " & $dest & " todo: " & $todo g.nodes[i].ondisk = dest if todo == DoClone: let (status, _) = @@ -306,6 +322,7 @@ proc expand*(c: var AtlasContext; g: var DepGraph; nc: NimbleContext; m: Travers g.nodes[i].status = status if g.nodes[i].status == Ok: + debug c, "atlas:expand", "node status: " & $g.nodes[i].status g.nodes[i].nimbleFile = c.findNimbleFile(g.nodes[i].pkg, dest) withDir c, dest: traverseDependency(c, nc, g, i, m) diff --git a/src/gitops.nim b/src/gitops.nim index be9f939..c4f96f8 100644 --- a/src/gitops.nim +++ b/src/gitops.nim @@ -105,6 +105,7 @@ proc lookupFileHashes*(c: var Reporter; nimbleFile: string): seq[string] = result.add line else: warn c, nimbleFile, "error looking up git hash history: " & outp + raise newException(Exception, "error looking up git hash history: " & outp) result.reverse() proc getLastTaggedCommit*(c: var Reporter): string =