Rev 3107 | Rev 4341 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3107 | Rev 4340 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #!/usr/bin/env python |
1 | #!/usr/bin/env python |
2 | # |
2 | # |
3 | # Copyright (c) 2006 Ondrej Palkovsky |
3 | # Copyright (c) 2006 Ondrej Palkovsky |
- | 4 | # Copyright (c) 2009 Martin Decky |
|
4 | # All rights reserved. |
5 | # All rights reserved. |
5 | # |
6 | # |
6 | # Redistribution and use in source and binary forms, with or without |
7 | # Redistribution and use in source and binary forms, with or without |
7 | # modification, are permitted provided that the following conditions |
8 | # modification, are permitted provided that the following conditions |
8 | # are met: |
9 | # are met: |
Line 25... | Line 26... | ||
25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | # |
29 | # |
29 | """ |
30 | """ |
30 | HelenOS configuration script |
31 | HelenOS configuration system |
31 | """ |
32 | """ |
32 | import sys |
33 | import sys |
33 | import os |
34 | import os |
34 | import re |
35 | import re |
35 | import commands |
36 | import commands |
- | 37 | import xtui |
|
36 | 38 | ||
37 | INPUT = sys.argv[1] |
39 | INPUT = sys.argv[1] |
38 | OUTPUT = 'Makefile.config' |
40 | OUTPUT = 'Makefile.config' |
39 | TMPOUTPUT = 'Makefile.config.tmp' |
- | |
40 | 41 | ||
469 | 242 | ||
470 | def main(): |
243 | def main(): |
471 | defaults = {} |
244 | defaults = {} |
472 | try: |
- | |
473 | dlg = Dialog() |
245 | ask_names = [] |
474 | except NotImplementedError: |
- | |
475 | dlg = NoDialog() |
- | |
476 | 246 | ||
477 | if len(sys.argv) >= 3 and sys.argv[2]=='default': |
- | |
478 | defmode = True |
247 | # Parse configuration file |
479 | else: |
- | |
480 | defmode = False |
248 | parse_config(INPUT, ask_names) |
481 | 249 | ||
482 | # Default run will update the configuration file |
- | |
483 | # with newest options |
250 | # Read defaults from previous run |
484 | if os.path.exists(OUTPUT): |
251 | if os.path.exists(OUTPUT): |
485 | read_defaults(OUTPUT, defaults) |
252 | read_defaults(OUTPUT, defaults) |
486 | 253 | ||
487 | # Get ARCH from command line if specified |
254 | # Default mode: only check defaults and regenerate configuration |
488 | if len(sys.argv) >= 4: |
255 | if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')): |
489 | defaults['ARCH'] = sys.argv[3] |
256 | if (check_choices(defaults, ask_names)): |
490 | defaults['PLATFORM'] = sys.argv[3] |
257 | create_output(OUTPUT, defaults, ask_names) |
- | 258 | return 0 |
|
491 | 259 | ||
492 | # Get COMPILER from command line if specified |
260 | screen = xtui.screen_init() |
- | 261 | try: |
|
493 | if len(sys.argv) >= 5: |
262 | selname = None |
494 | defaults['COMPILER'] = sys.argv[4] |
263 | while True: |
495 | 264 | ||
496 | # Get CONFIG_DEBUG from command line if specified |
265 | options = [] |
497 | if len(sys.argv) >= 6: |
266 | opt2row = {} |
- | 267 | position = None |
|
- | 268 | cnt = 0 |
|
498 | defaults['CONFIG_DEBUG'] = sys.argv[5] |
269 | for varname, vartype, name, choices, cond in ask_names: |
499 | 270 | ||
500 | # Get MACHINE/IMAGE from command line if specified |
271 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
- | 272 | continue |
|
- | 273 | ||
501 | if len(sys.argv) >= 7: |
274 | if (varname == selname): |
- | 275 | position = cnt |
|
- | 276 | ||
502 | defaults['MACHINE'] = sys.argv[6] |
277 | if (not defaults.has_key(varname)): |
- | 278 | default = None |
|
- | 279 | else: |
|
503 | defaults['IMAGE'] = sys.argv[6] |
280 | default = defaults[varname] |
504 | 281 | ||
505 | # Dry run only with defaults |
282 | if (vartype == 'choice'): |
506 | varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults) |
283 | # Check if the default is an acceptable value |
507 | # If not in default mode, present selection of all possibilities |
284 | if ((default) and (not default in [choice[0] for choice in choices])): |
508 | if not defmode: |
285 | default = None |
- | 286 | defaults.pop(varname) |
|
- | 287 | ||
509 | defopt = 0 |
288 | # If there is just one option, use it |
510 | while 1: |
289 | if (len(choices) == 1): |
- | 290 | default = choices[0][0] |
|
- | 291 | defaults[varname] = default |
|
- | 292 | ||
511 | # varnames contains variable names that were in the |
293 | options.append(" %s [%s] --> " % (name, default)) |
- | 294 | elif (vartype == 'y/n'): |
|
512 | # last question set |
295 | if (default == None): |
- | 296 | default = 'y' |
|
513 | choices = [ (x[1],defaults[x[0]]) for x in varnames ] |
297 | defaults[varname] = default |
514 | res = dlg.menu('Configuration',choices,('save','Save'),defopt) |
298 | options.append(" <%s> %s " % (yes_no(default), name)) |
515 | if res == 'save': |
299 | elif (vartype == 'n/y'): |
- | 300 | if (default == None): |
|
- | 301 | default = 'n' |
|
- | 302 | defaults[varname] = default |
|
516 | parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults) |
303 | options.append(" <%s> %s " % (yes_no(default), name)) |
517 | break |
304 | else: |
518 | # transfer description back to varname |
305 | raise RuntimeError("Unknown variable type: %s" % vartype) |
- | 306 | ||
519 | for i,(vname,descr) in enumerate(varnames): |
307 | opt2row[cnt] = (varname, vartype, name, choices) |
- | 308 | ||
- | 309 | cnt += 1 |
|
- | 310 | ||
- | 311 | (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position) |
|
- | 312 | ||
520 | if res == descr: |
313 | if (button == 'cancel'): |
521 | defopt = i |
314 | return 'Configuration canceled' |
- | 315 | ||
522 | break |
316 | if (not opt2row.has_key(value)): |
523 | # Ask the user a simple question, produce output |
317 | raise RuntimeError("Error selecting value: %s" % value) |
- | 318 | ||
524 | # as if the user answered all the other questions |
319 | (selname, seltype, name, choices) = opt2row[value] |
- | 320 | ||
- | 321 | if (not defaults.has_key(selname)): |
|
- | 322 | default = None |
|
- | 323 | else: |
|
525 | # with default answer |
324 | default = defaults[selname] |
- | 325 | ||
526 | varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults, |
326 | if (button == 'done'): |
527 | askonly=varnames[i][0]) |
327 | if (check_choices(defaults, ask_names)): |
- | 328 | break |
|
528 | 329 | else: |
|
- | 330 | xtui.error_dialog(screen, 'Error', 'Some options have still undefined values.') |
|
- | 331 | continue |
|
529 | 332 | ||
530 | if os.path.exists(OUTPUT): |
333 | if (seltype == 'choice'): |
- | 334 | defaults[selname] = subchoice(screen, name, choices, default) |
|
- | 335 | elif ((seltype == 'y/n') or (seltype == 'n/y')): |
|
531 | os.unlink(OUTPUT) |
336 | if (defaults[selname] == 'y'): |
532 | os.rename(TMPOUTPUT, OUTPUT) |
337 | defaults[selname] = 'n' |
533 | 338 | else: |
|
534 | if not defmode and dlg.yesno('Rebuild everything?') == 'y': |
339 | defaults[selname] = 'y' |
- | 340 | finally: |
|
- | 341 | xtui.screen_done(screen) |
|
- | 342 | ||
535 | os.execlp('make','make','clean','build') |
343 | create_output(OUTPUT, defaults, ask_names) |
- | 344 | return 0 |
|
536 | 345 | ||
537 | if __name__ == '__main__': |
346 | if __name__ == '__main__': |
538 | main() |
347 | exit(main()) |