Skip to content

Commit 206a4ce

Browse files
timotheecourAraq
authored andcommitted
fix cmdline bugs affecting nimBetterRun correctness (#12933) [backport]
1 parent cb0a20b commit 206a4ce

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

compiler/nim.nim

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,31 @@ proc prependCurDir(f: AbsoluteFile): AbsoluteFile =
4040
else:
4141
result = f
4242

43+
proc addCmdPrefix*(result: var string, kind: CmdLineKind) =
44+
# consider moving this to std/parseopt
45+
case kind
46+
of cmdLongOption: result.add "--"
47+
of cmdShortOption: result.add "-"
48+
of cmdArgument, cmdEnd: discard
49+
4350
proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
4451
var p = parseopt.initOptParser(cmd)
4552
var argsCount = 0
53+
54+
config.commandLine.setLen 0
55+
# bugfix: otherwise, config.commandLine ends up duplicated
56+
4657
while true:
4758
parseopt.next(p)
4859
case p.kind
4960
of cmdEnd: break
5061
of cmdLongOption, cmdShortOption:
5162
config.commandLine.add " "
52-
config.commandLine.add p.key
63+
config.commandLine.addCmdPrefix p.kind
64+
config.commandLine.add p.key.quoteShell # quoteShell to be future proof
5365
if p.val.len > 0:
5466
config.commandLine.add ':'
55-
config.commandLine.add p.val
67+
config.commandLine.add p.val.quoteShell
5668

5769
if p.key == " ":
5870
p.key = "-"
@@ -61,7 +73,7 @@ proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
6173
processSwitch(pass, p, config)
6274
of cmdArgument:
6375
config.commandLine.add " "
64-
config.commandLine.add p.key
76+
config.commandLine.add p.key.quoteShell
6577
if processArgument(pass, p, argsCount, config): break
6678
if pass == passCmd2:
6779
if {optRun, optWasNimscript} * config.globalOptions == {} and

0 commit comments

Comments
 (0)