19
19
sys .path .append (os .path .join (rust_dir , "src" , "bootstrap" ))
20
20
import bootstrap
21
21
22
+
22
23
class Option :
23
24
def __init__ (self , name , rustbuild , desc , value ):
24
25
self .name = name
25
26
self .rustbuild = rustbuild
26
27
self .desc = desc
27
28
self .value = value
28
29
30
+
29
31
options = []
30
32
33
+
31
34
def o (* args ):
32
35
options .append (Option (* args , value = False ))
33
36
37
+
34
38
def v (* args ):
35
39
options .append (Option (* args , value = True ))
36
40
41
+
37
42
o ("debug" , "rust.debug" , "debug mode; disables optimization unless `--enable-optimize` given" )
38
43
o ("docs" , "build.docs" , "build standard library documentation" )
39
44
o ("compiler-docs" , "build.compiler-docs" , "build compiler documentation" )
@@ -136,13 +141,16 @@ def v(*args):
136
141
137
142
v ("set" , None , "set arbitrary key/value pairs in TOML configuration" )
138
143
144
+
139
145
def p (msg ):
140
146
print ("configure: " + msg )
141
147
148
+
142
149
def err (msg ):
143
150
print ("configure: error: " + msg )
144
151
sys .exit (1 )
145
152
153
+
146
154
if '--help' in sys .argv or '-h' in sys .argv :
147
155
print ('Usage: ./configure [options]' )
148
156
print ('' )
@@ -208,7 +216,7 @@ def err(msg):
208
216
continue
209
217
210
218
found = True
211
- if not option .name in known_args :
219
+ if option .name not in known_args :
212
220
known_args [option .name ] = []
213
221
known_args [option .name ].append ((option , value ))
214
222
break
@@ -227,27 +235,30 @@ def err(msg):
227
235
# TOML we're going to write out
228
236
config = {}
229
237
238
+
230
239
def build ():
231
240
if 'build' in known_args :
232
241
return known_args ['build' ][0 ][1 ]
233
242
return bootstrap .default_build_triple ()
234
243
244
+
235
245
def set (key , value ):
236
- s = "{:20} := {}" .format (key , value )
237
- if len (s ) < 70 :
238
- p (s )
239
- else :
240
- p (s [:70 ] + " ..." )
241
-
242
- arr = config
243
- parts = key .split ('.' )
244
- for i , part in enumerate (parts ):
245
- if i == len (parts ) - 1 :
246
- arr [part ] = value
247
- else :
248
- if not part in arr :
249
- arr [part ] = {}
250
- arr = arr [part ]
246
+ s = "{:20} := {}" .format (key , value )
247
+ if len (s ) < 70 :
248
+ p (s )
249
+ else :
250
+ p (s [:70 ] + " ..." )
251
+
252
+ arr = config
253
+ parts = key .split ('.' )
254
+ for i , part in enumerate (parts ):
255
+ if i == len (parts ) - 1 :
256
+ arr [part ] = value
257
+ else :
258
+ if part not in arr :
259
+ arr [part ] = {}
260
+ arr = arr [part ]
261
+
251
262
252
263
for key in known_args :
253
264
# The `set` option is special and can be passed a bunch of times
@@ -345,6 +356,7 @@ def set(key, value):
345
356
targets [target ] = sections ['target' ][:]
346
357
targets [target ][0 ] = targets [target ][0 ].replace ("x86_64-unknown-linux-gnu" , target )
347
358
359
+
348
360
# Here we walk through the constructed configuration we have from the parsed
349
361
# command line arguments. We then apply each piece of configuration by
350
362
# basically just doing a `sed` to change the various configuration line to what
@@ -362,6 +374,7 @@ def to_toml(value):
362
374
else :
363
375
raise RuntimeError ('no toml' )
364
376
377
+
365
378
def configure_section (lines , config ):
366
379
for key in config :
367
380
value = config [key ]
@@ -375,9 +388,10 @@ def configure_section(lines, config):
375
388
if not found :
376
389
raise RuntimeError ("failed to find config line for {}" .format (key ))
377
390
391
+
378
392
for section_key in config :
379
393
section_config = config [section_key ]
380
- if not section_key in sections :
394
+ if section_key not in sections :
381
395
raise RuntimeError ("config key {} not in sections" .format (section_key ))
382
396
383
397
if section_key == 'target' :
0 commit comments