atlas: added --cfgHere switch [backport] (#18873)

This commit is contained in:
Andreas Rumpf 2021-09-20 13:32:33 +02:00 • committed by GitHub
commit 928ea6bb4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,8 @@ Command:
Options: Options:
--keepCommits do not perform any `git checkouts` --keepCommits do not perform any `git checkouts`
--cfgHere also create/maintain a nim.cfg in the current
working directory
--version show the version --version show the version
--help show this help --help show this help
""" """
@ -58,6 +60,7 @@ type
projectDir, workspace: string projectDir, workspace: string
hasPackageList: bool hasPackageList: bool
keepCommits: bool keepCommits: bool
cfgHere: bool
p: Table[string, string] # name -> url mapping p: Table[string, string] # name -> url mapping
processed: HashSet[string] # the key is (url / commit) processed: HashSet[string] # the key is (url / commit)
errors: int errors: int
@ -353,7 +356,7 @@ proc clone(c: var AtlasContext; start: string): seq[string] =
error c, toName(start), "cannot resolve package name" error c, toName(start), "cannot resolve package name"
return return
c.projectDir = work[0].name.string c.projectDir = c.workspace / work[0].name.string
result = @[] result = @[]
var i = 0 var i = 0
while i < work.len: while i < work.len:
@ -376,8 +379,14 @@ const
configPatternBegin = "############# begin Atlas config section ##########\n" configPatternBegin = "############# begin Atlas config section ##########\n"
configPatternEnd = "############# end Atlas config section ##########\n" configPatternEnd = "############# end Atlas config section ##########\n"
proc patchNimCfg(c: var AtlasContext; deps: seq[string]) = proc patchNimCfg(c: var AtlasContext; deps: seq[string]; cfgHere: bool) =
var paths = "--noNimblePath\n" var paths = "--noNimblePath\n"
if cfgHere:
let cwd = getCurrentDir()
for d in deps:
let x = relativePath(c.workspace / d, cwd, '/')
paths.add "--path:\"" & x & "\"\n"
else:
for d in deps: for d in deps:
paths.add "--path:\"../" & d.replace("\\", "/") & "\"\n" paths.add "--path:\"../" & d.replace("\\", "/") & "\"\n"
@ -387,7 +396,8 @@ proc patchNimCfg(c: var AtlasContext; deps: seq[string]) =
assert readFile(TestsDir / "nim.cfg") == cfgContent assert readFile(TestsDir / "nim.cfg") == cfgContent
c.mockupSuccess = true c.mockupSuccess = true
else: else:
let cfg = c.projectDir / "nim.cfg" let cfg = if cfgHere: getCurrentDir() / "nim.cfg"
else: c.projectDir / "nim.cfg"
if not fileExists(cfg): if not fileExists(cfg):
writeFile(cfg, cfgContent) writeFile(cfg, cfgContent)
else: else:
@ -437,6 +447,7 @@ proc main =
of "help", "h": writeHelp() of "help", "h": writeHelp()
of "version", "v": writeVersion() of "version", "v": writeVersion()
of "keepcommits": c.keepCommits = true of "keepcommits": c.keepCommits = true
of "cfghere": c.cfgHere = true
else: writeHelp() else: writeHelp()
of cmdEnd: assert false, "cannot happen" of cmdEnd: assert false, "cannot happen"
@ -449,7 +460,9 @@ proc main =
of "clone": of "clone":
singleArg() singleArg()
let deps = clone(c, args[0]) let deps = clone(c, args[0])
patchNimCfg c, deps patchNimCfg c, deps, false
if c.cfgHere:
patchNimCfg c, deps, true
when MockupRun: when MockupRun:
if not c.mockupSuccess: if not c.mockupSuccess:
error "There were problems." error "There were problems."