Changes in tools/config.py [3ef901d0:3f1a481] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config.py

    r3ef901d0 r3f1a481  
    4242import random
    4343
    44 RULES_FILE = sys.argv[1]
     44ARGPOS_RULES = 1
     45ARGPOS_PRESETS_DIR = 2
     46ARGPOS_CHOICE = 3
     47ARGPOS_PRESET = 4
     48ARGPOS_MASK_PLATFORM = 3
     49
     50RULES_FILE = sys.argv[ARGPOS_RULES]
    4551MAKEFILE = 'Makefile.config'
    4652MACROS = 'config.h'
    47 PRESETS_DIR = 'defaults'
     53PRESETS_DIR = sys.argv[ARGPOS_PRESETS_DIR]
    4854
    4955class BinaryOp:
     
    532538
    533539        try:
    534                 version = subprocess.Popen(['git', 'log', '-1', '--pretty=%h'], stdout = subprocess.PIPE).communicate()[0].decode().strip()
     540                version = subprocess.Popen(['git', '-C', os.path.dirname(RULES_FILE), 'log', '-1', '--pretty=%h'], stdout = subprocess.PIPE).communicate()[0].decode().strip()
    535541                sys.stderr.write("ok\n")
    536542        except:
     
    586592        outmk.write('TIMESTAMP_UNIX = %d\n' % timestamp_unix)
    587593        outmc.write('#define TIMESTAMP_UNIX %d\n' % timestamp_unix)
    588         defs += ' "-DTIMESTAMP_UNIX=%d"\n' % timestamp_unix
     594        defs += ' "-DTIMESTAMP_UNIX=%d"' % timestamp_unix
    589595
    590596        outmk.write('TIMESTAMP = %s\n' % timestamp)
    591597        outmc.write('#define TIMESTAMP %s\n' % timestamp)
    592         defs += ' "-DTIMESTAMP=%s"\n' % timestamp
    593 
    594         outmk.write(defs)
     598        defs += ' "-DTIMESTAMP=%s"' % timestamp
     599
     600        outmk.write('%s\n' % defs)
    595601
    596602        outmk.close()
     
    676682        parse_rules(RULES_FILE, rules)
    677683
     684        if len(sys.argv) > ARGPOS_CHOICE:
     685                choice = sys.argv[ARGPOS_CHOICE]
     686        else:
     687                choice = None
     688
     689        if len(sys.argv) > ARGPOS_PRESET:
     690                preset = sys.argv[ARGPOS_PRESET]
     691        else:
     692                preset = None
     693
     694        mask_platform = (len(sys.argv) > ARGPOS_MASK_PLATFORM and sys.argv[ARGPOS_MASK_PLATFORM] == "--mask-platform")
     695
    678696        # Input configuration file can be specified on command line
    679697        # otherwise configuration from previous run is used.
    680         if len(sys.argv) >= 4:
    681                 profile = parse_profile_name(sys.argv[3])
     698        if preset is not None:
     699                profile = parse_profile_name(preset)
    682700                read_presets(profile, config)
    683701        elif os.path.exists(MAKEFILE):
     
    685703
    686704        # Default mode: check values and regenerate configuration files
    687         if (len(sys.argv) >= 3) and (sys.argv[2] == 'default'):
     705        if choice == 'default':
    688706                if (infer_verify_choices(config, rules)):
    689707                        preprocess_config(config, rules)
     
    693711        # Hands-off mode: check values and regenerate configuration files,
    694712        # but no interactive fallback
    695         if (len(sys.argv) >= 3) and (sys.argv[2] == 'hands-off'):
    696                 # We deliberately test sys.argv >= 4 because we do not want
     713        if choice == 'hands-off':
     714                # We deliberately test this because we do not want
    697715                # to read implicitly any possible previous run configuration
    698                 if len(sys.argv) < 4:
     716                if preset is None:
    699717                        sys.stderr.write("Configuration error: No presets specified\n")
    700718                        return 2
     
    709727
    710728        # Check mode: only check configuration
    711         if (len(sys.argv) >= 3) and (sys.argv[2] == 'check'):
     729        if choice == 'check':
    712730                if infer_verify_choices(config, rules):
    713731                        return 0
     
    715733
    716734        # Random mode
    717         if (len(sys.argv) == 3) and (sys.argv[2] == 'random'):
     735        if choice == 'random':
    718736                ok = random_choices(config, rules, 0)
    719737                if not ok:
     
    741759                        options = []
    742760                        opt2row = {}
    743                         cnt = 1
    744 
    745                         options.append("  --- Load preconfigured defaults ... ")
     761                        cnt = 0
     762
     763                        if not mask_platform:
     764                                cnt += 1
     765                                options.append("  --- Load preconfigured defaults ... ")
    746766
    747767                        for rule in rules:
     
    750770                                if cond and not cond.evaluate(config):
    751771                                        continue
     772
     773                                if mask_platform and (varname == "PLATFORM" or varname == "MACHINE" or varname == "COMPILER"):
     774                                        rule = varname, vartype, "(locked) " + name, choices, cond
    752775
    753776                                if varname == selname:
     
    797820                                        continue
    798821
    799                         if value == 0:
     822                        if value == 0 and not mask_platform:
    800823                                profile = choose_profile(PRESETS_DIR, MAKEFILE, screen, config)
    801824                                if profile != None:
     
    814837                        else:
    815838                                value = config[selname]
     839
     840                        if mask_platform and (selname == "PLATFORM" or selname == "MACHINE" or selname == "COMPILER"):
     841                                        continue
    816842
    817843                        if seltype == 'choice':
Note: See TracChangeset for help on using the changeset viewer.