Skip to content

Commit

Permalink
fixing vendor deps integration
Browse files Browse the repository at this point in the history
  • Loading branch information
elcritch committed Apr 7, 2024
1 parent 37f4462 commit b9258cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/atlas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 24 additions & 7 deletions src/depgraphs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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, _) =
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/gitops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit b9258cb

Please sign in to comment.