Subversion Repositories HelenOS

Rev

Rev 3017 | Rev 3804 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3017 Rev 3803
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 snack
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
 
243
 
470
def main():
244
def main():
471
    defaults = {}
245
    defaults = {}
472
    try:
-
 
473
        dlg = Dialog()
246
    ask_names = []
474
    except NotImplementedError:
-
 
475
        dlg = NoDialog()
-
 
476
 
247
   
477
    if len(sys.argv) >= 3 and sys.argv[2]=='default':
-
 
478
        defmode = True
248
    # Parse configuration file
479
    else:
-
 
480
        defmode = False
249
    parse_config(INPUT, ask_names)
481
 
250
   
482
    # Default run will update the configuration file
-
 
483
    # with newest options
251
    # Read defaults from previous run
484
    if os.path.exists(OUTPUT):
252
    if os.path.exists(OUTPUT):
485
        read_defaults(OUTPUT, defaults)
253
        read_defaults(OUTPUT, defaults)
486
 
254
   
487
    # Get ARCH from command line if specified
255
    # Default mode: only check defaults and regenerate configuration
488
    if len(sys.argv) >= 4:
256
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
489
        defaults['ARCH'] = sys.argv[3]
257
        if (check_choices(defaults, ask_names)):
490
        defaults['PLATFORM'] = sys.argv[3]
258
            create_output(OUTPUT, defaults, ask_names)
-
 
259
            return 0
491
   
260
   
492
    # Get COMPILER from command line if specified
261
    screen = snack.SnackScreen()
-
 
262
    try:
493
    if len(sys.argv) >= 5:
263
        selname = None
494
        defaults['COMPILER'] = sys.argv[4]
264
        while True:
495
   
265
           
-
 
266
            options = []
-
 
267
            opt2row = {}
-
 
268
            position = None
-
 
269
            cnt = 0
496
    # Get CONFIG_DEBUG from command line if specified
270
            for row in ask_names:
-
 
271
               
497
    if len(sys.argv) >= 6:
272
                varname = row[0]
-
 
273
                vartype = row[1]
-
 
274
                name = row[2]
498
        defaults['CONFIG_DEBUG'] = sys.argv[5]
275
                choices = row[3]
-
 
276
                cond = row[4]
499
   
277
               
500
    # Get MACHINE/IMAGE from command line if specified
278
                if ((cond) and (not check_condition(cond, defaults, ask_names))):
-
 
279
                    continue
-
 
280
               
501
    if len(sys.argv) >= 7:
281
                if (varname == selname):
-
 
282
                    position = cnt
-
 
283
               
502
        defaults['MACHINE'] = sys.argv[6]
284
                if (not defaults.has_key(varname)):
-
 
285
                    default = None
-
 
286
                else:
503
        defaults['IMAGE'] = sys.argv[6]
287
                    default = defaults[varname]
504
 
288
               
505
    # Dry run only with defaults
289
                if (vartype == 'choice'):
506
    varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
290
                    # Check if the default is an acceptable value
507
    # If not in default mode, present selection of all possibilities
291
                    if ((default) and (not default in [choice[0] for choice in choices])):
508
    if not defmode:
292
                        default = None
509
        defopt = 0
293
                        defaults.pop(varname)
510
        while 1:
294
                   
511
            # varnames contains variable names that were in the
295
                    # If there is just one option, use it
512
            # last question set
296
                    if (len(choices) == 1):
-
 
297
                        default = choices[0][0]
513
            choices = [ (x[1],defaults[x[0]]) for x in varnames ]
298
                        defaults[varname] = default
-
 
299
                   
514
            res = dlg.menu('Configuration',choices,('save','Save'),defopt)
300
                    options.append("     %s [%s] --> " % (name, default))
515
            if res == 'save':
301
                elif (vartype == 'y/n'):
516
                parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
302
                    if (default == None):
517
                break
303
                        default = 'y'
518
            # transfer description back to varname
304
                        defaults[varname] = default
519
            for i,(vname,descr) in enumerate(varnames):
305
                    options.append(" <%s> %s " % (yes_no(default), name))
520
                if res == descr:
306
                elif (vartype == 'n/y'):
521
                    defopt = i
307
                    if (default == None):
522
                    break
308
                        default = 'n'
-
 
309
                        defaults[varname] = default
523
            # Ask the user a simple question, produce output
310
                    options.append(" <%s> %s " % (yes_no(default), name))
-
 
311
                else:
524
            # as if the user answered all the other questions
312
                    raise RuntimeError("Unknown variable type: %s" % vartype)
-
 
313
               
-
 
314
                opt2row[cnt] = row
-
 
315
               
-
 
316
                cnt += 1
-
 
317
           
-
 
318
            retval = snack.ListboxChoiceWindow(screen, 'HelenOS configuration', 'Choose configuration option', options, default = position)
-
 
319
           
-
 
320
            if (retval[0] == 'cancel'):
525
            # with default answer
321
                return 'Configuration canceled'
-
 
322
           
-
 
323
            row = opt2row[retval[1]]
-
 
324
            if (row == None):
526
            varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults,
325
                raise RuntimeError("Error selecting value: %s" % retval[1])
-
 
326
           
-
 
327
            selname = row[0]
-
 
328
            seltype = row[1]
-
 
329
            name = row[2]
-
 
330
            choices = row[3]
-
 
331
           
-
 
332
            if (retval[0] == 'ok'):
527
                                    askonly=varnames[i][0])
333
                if (check_choices(defaults, ask_names)):
-
 
334
                    break
528
       
335
                else:
-
 
336
                    snack.ButtonChoiceWindow(screen, 'Error', 'Some options have still undefined values.', ['Ok']);
-
 
337
                    continue
529
   
338
           
530
    if os.path.exists(OUTPUT):
339
            if (seltype == 'choice'):
-
 
340
                defaults[selname] = subchoice(screen, name, choices)
-
 
341
            elif ((seltype == 'y/n') or (seltype == 'n/y')):
531
        os.unlink(OUTPUT)
342
                if (defaults[selname] == 'y'):
532
    os.rename(TMPOUTPUT, OUTPUT)
343
                    defaults[selname] = 'n'
533
   
344
                else:
534
    if not defmode and dlg.yesno('Rebuild everything?') == 'y':
345
                    defaults[selname] = 'y'
-
 
346
    finally:
-
 
347
        screen.finish()
-
 
348
   
535
        os.execlp('make','make','clean','build')
349
    create_output(OUTPUT, defaults, ask_names)
-
 
350
    return 0
536
 
351
 
537
if __name__ == '__main__':
352
if __name__ == '__main__':
538
    main()
353
    exit(main())