summary refs log tree commit diff stats
path: root/compiler/nim.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2019-12-19 14:53:01 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-12-19 14:53:01 +0100
commit206a4cee7787af34865b07ff078df33967af184d (patch)
treea1239457e096a8bc47f919aa51fdee96ffb72a53 /compiler/nim.nim
parentcb0a20b9b4521be066f5878f77c224540f73f779 (diff)
downloadNim-206a4cee7787af34865b07ff078df33967af184d.tar.gz
fix cmdline bugs affecting nimBetterRun correctness (#12933) [backport]
Diffstat (limited to 'compiler/nim.nim')
-rw-r--r--compiler/nim.nim18
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/nim.nim b/compiler/nim.nim
index ec7e8b8dc..cc1dc2fe7 100644
--- a/compiler/nim.nim
+++ b/compiler/nim.nim
@@ -40,19 +40,31 @@ proc prependCurDir(f: AbsoluteFile): AbsoluteFile =
   else:
     result = f
 
+proc addCmdPrefix*(result: var string, kind: CmdLineKind) =
+  # consider moving this to std/parseopt
+  case kind
+  of cmdLongOption: result.add "--"
+  of cmdShortOption: result.add "-"
+  of cmdArgument, cmdEnd: discard
+
 proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
   var p = parseopt.initOptParser(cmd)
   var argsCount = 0
+
+  config.commandLine.setLen 0
+    # bugfix: otherwise, config.commandLine ends up duplicated
+
   while true:
     parseopt.next(p)
     case p.kind
     of cmdEnd: break
     of cmdLongOption, cmdShortOption:
       config.commandLine.add " "
-      config.commandLine.add p.key
+      config.commandLine.addCmdPrefix p.kind
+      config.commandLine.add p.key.quoteShell # quoteShell to be future proof
       if p.val.len > 0:
         config.commandLine.add ':'
-        config.commandLine.add p.val
+        config.commandLine.add p.val.quoteShell
 
       if p.key == " ":
         p.key = "-"
@@ -61,7 +73,7 @@ proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
         processSwitch(pass, p, config)
     of cmdArgument:
       config.commandLine.add " "
-      config.commandLine.add p.key
+      config.commandLine.add p.key.quoteShell
       if processArgument(pass, p, argsCount, config): break
   if pass == passCmd2:
     if {optRun, optWasNimscript} * config.globalOptions == {} and
ass='oid'>372367f5 ^
6112864a ^
































3350c34a ^
6112864a ^
d3a9db3a ^




3350c34a ^
d3a9db3a ^
6112864a ^
ec32c11d ^
3350c34a ^
ec32c11d ^
3350c34a ^

ec32c11d ^
3350c34a ^
ec32c11d ^
6112864a ^


372367f5 ^
6112864a ^


dd60a1d7 ^
d3a9db3a ^
3350c34a ^

ec32c11d ^
6112864a ^



d3a9db3a ^
3350c34a ^

ec32c11d ^
6112864a ^
d3a9db3a ^
ec32c11d ^
6112864a ^
d3a9db3a ^
ec32c11d ^
dd60a1d7 ^
3350c34a ^
6112864a ^

3350c34a ^
6112864a ^

3d1c4216 ^
6112864a ^

dd60a1d7 ^
d3a9db3a ^
6112864a ^




d3a9db3a ^
3350c34a ^
ec32c11d ^

3350c34a ^
d3a9db3a ^
3350c34a ^
372367f5 ^
3350c34a ^
ec32c11d ^
3350c34a ^

d3a9db3a ^
3350c34a ^





d3a9db3a ^
3350c34a ^





f6eba676 ^
6112864a ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153