1919sys .path .append (os .path .join (rust_dir , "src" , "bootstrap" ))
2020import bootstrap
2121
22+
2223class Option :
2324 def __init__ (self , name , rustbuild , desc , value ):
2425 self .name = name
2526 self .rustbuild = rustbuild
2627 self .desc = desc
2728 self .value = value
2829
30+
2931options = []
3032
33+
3134def o (* args ):
3235 options .append (Option (* args , value = False ))
3336
37+
3438def v (* args ):
3539 options .append (Option (* args , value = True ))
3640
41+
3742o ("debug" , "rust.debug" , "debug mode; disables optimization unless `--enable-optimize` given" )
3843o ("docs" , "build.docs" , "build standard library documentation" )
3944o ("compiler-docs" , "build.compiler-docs" , "build compiler documentation" )
@@ -136,13 +141,16 @@ def v(*args):
136141
137142v ("set" , None , "set arbitrary key/value pairs in TOML configuration" )
138143
144+
139145def p (msg ):
140146 print ("configure: " + msg )
141147
148+
142149def err (msg ):
143150 print ("configure: error: " + msg )
144151 sys .exit (1 )
145152
153+
146154if '--help' in sys .argv or '-h' in sys .argv :
147155 print ('Usage: ./configure [options]' )
148156 print ('' )
@@ -208,7 +216,7 @@ def err(msg):
208216 continue
209217
210218 found = True
211- if not option .name in known_args :
219+ if option .name not in known_args :
212220 known_args [option .name ] = []
213221 known_args [option .name ].append ((option , value ))
214222 break
@@ -227,27 +235,30 @@ def err(msg):
227235# TOML we're going to write out
228236config = {}
229237
238+
230239def build ():
231240 if 'build' in known_args :
232241 return known_args ['build' ][0 ][1 ]
233242 return bootstrap .default_build_triple ()
234243
244+
235245def 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+
251262
252263for key in known_args :
253264 # The `set` option is special and can be passed a bunch of times
@@ -345,6 +356,7 @@ def set(key, value):
345356 targets [target ] = sections ['target' ][:]
346357 targets [target ][0 ] = targets [target ][0 ].replace ("x86_64-unknown-linux-gnu" , target )
347358
359+
348360# Here we walk through the constructed configuration we have from the parsed
349361# command line arguemnts. We then apply each piece of configuration by
350362# basically just doing a `sed` to change the various configuration line to what
@@ -362,6 +374,7 @@ def to_toml(value):
362374 else :
363375 raise 'no toml'
364376
377+
365378def configure_section (lines , config ):
366379 for key in config :
367380 value = config [key ]
@@ -375,9 +388,10 @@ def configure_section(lines, config):
375388 if not found :
376389 raise RuntimeError ("failed to find config line for {}" .format (key ))
377390
391+
378392for section_key in config :
379393 section_config = config [section_key ]
380- if not section_key in sections :
394+ if section_key not in sections :
381395 raise RuntimeError ("config key {} not in sections" .format (key ))
382396
383397 if section_key == 'target' :
0 commit comments