Changeset a35b458 in mainline for tools/autotool.py


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/autotool.py

    r3061bc1 ra35b458  
    9393def read_config(fname, config):
    9494        "Read HelenOS build configuration"
    95        
     95
    9696        inf = open(fname, 'r')
    97        
     97
    9898        for line in inf:
    9999                res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
    100100                if (res):
    101101                        config[res.group(1)] = res.group(2)
    102        
     102
    103103        inf.close()
    104104
    105105def print_error(msg):
    106106        "Print a bold error message"
    107        
     107
    108108        sys.stderr.write("\n")
    109109        sys.stderr.write("######################################################################\n")
     
    113113        sys.stderr.write("######################################################################\n")
    114114        sys.stderr.write("\n")
    115        
     115
    116116        sys.exit(1)
    117117
    118118def print_warning(msg):
    119119        "Print a bold error message"
    120        
     120
    121121        sys.stderr.write("\n")
    122122        sys.stderr.write("######################################################################\n")
     
    126126        sys.stderr.write("######################################################################\n")
    127127        sys.stderr.write("\n")
    128        
     128
    129129        time.sleep(5)
    130130
    131131def sandbox_enter():
    132132        "Create a temporal sandbox directory for running tests"
    133        
     133
    134134        if (os.path.exists(SANDBOX)):
    135135                if (os.path.isdir(SANDBOX)):
     
    141141                        print_error(["Please inspect and remove unexpected directory,",
    142142                                     "entry \"%s\"." % SANDBOX])
    143        
     143
    144144        try:
    145145                os.mkdir(SANDBOX)
    146146        except:
    147147                print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
    148        
     148
    149149        owd = os.getcwd()
    150150        os.chdir(SANDBOX)
    151        
     151
    152152        return owd
    153153
    154154def sandbox_leave(owd):
    155155        "Leave the temporal sandbox directory"
    156        
     156
    157157        os.chdir(owd)
    158158
    159159def check_config(config, key):
    160160        "Check whether the configuration key exists"
    161        
     161
    162162        if (not key in config):
    163163                print_error(["Build configuration of HelenOS does not contain %s." % key,
     
    167167def check_common(common, key):
    168168        "Check whether the common key exists"
    169        
     169
    170170        if (not key in common):
    171171                print_error(["Failed to determine the value %s." % key,
     
    178178        target = None
    179179        cc_args = []
    180        
     180
    181181        if (config['PLATFORM'] == "abs32le"):
    182182                check_config(config, "CROSS_TARGET")
    183183                platform = config['CROSS_TARGET']
    184                
     184
    185185                if (config['CROSS_TARGET'] == "arm32"):
    186186                        gnu_target = "arm-linux-gnueabi"
    187187                        helenos_target = "arm-helenos-gnueabi"
    188                
     188
    189189                if (config['CROSS_TARGET'] == "ia32"):
    190190                        gnu_target = "i686-pc-linux-gnu"
    191191                        helenos_target = "i686-pc-helenos"
    192                
     192
    193193                if (config['CROSS_TARGET'] == "mips32"):
    194194                        cc_args.append("-mabi=32")
    195195                        gnu_target = "mipsel-linux-gnu"
    196196                        helenos_target = "mipsel-helenos"
    197        
     197
    198198        if (config['PLATFORM'] == "amd64"):
    199199                platform = config['PLATFORM']
    200200                gnu_target = "amd64-unknown-elf"
    201201                helenos_target = "amd64-helenos"
    202        
     202
    203203        if (config['PLATFORM'] == "arm32"):
    204204                platform = config['PLATFORM']
    205205                gnu_target = "arm-linux-gnueabi"
    206206                helenos_target = "arm-helenos-gnueabi"
    207        
     207
    208208        if (config['PLATFORM'] == "ia32"):
    209209                platform = config['PLATFORM']
    210210                gnu_target = "i686-pc-linux-gnu"
    211211                helenos_target = "i686-pc-helenos"
    212        
     212
    213213        if (config['PLATFORM'] == "ia64"):
    214214                platform = config['PLATFORM']
    215215                gnu_target = "ia64-pc-linux-gnu"
    216216                helenos_target = "ia64-pc-helenos"
    217        
     217
    218218        if (config['PLATFORM'] == "mips32"):
    219219                check_config(config, "MACHINE")
    220220                cc_args.append("-mabi=32")
    221                
     221
    222222                if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
    223223                        platform = config['PLATFORM']
    224224                        gnu_target = "mipsel-linux-gnu"
    225225                        helenos_target = "mipsel-helenos"
    226                
     226
    227227                if ((config['MACHINE'] == "bmalta")):
    228228                        platform = "mips32eb"
    229229                        gnu_target = "mips-linux-gnu"
    230230                        helenos_target = "mips-helenos"
    231        
     231
    232232        if (config['PLATFORM'] == "mips64"):
    233233                check_config(config, "MACHINE")
    234234                cc_args.append("-mabi=64")
    235                
     235
    236236                if (config['MACHINE'] == "msim"):
    237237                        platform = config['PLATFORM']
    238238                        gnu_target = "mips64el-linux-gnu"
    239239                        helenos_target = "mips64el-helenos"
    240        
     240
    241241        if (config['PLATFORM'] == "ppc32"):
    242242                platform = config['PLATFORM']
    243243                gnu_target = "ppc-linux-gnu"
    244244                helenos_target = "ppc-helenos"
    245        
     245
    246246        if (config['PLATFORM'] == "riscv64"):
    247247                platform = config['PLATFORM']
    248248                gnu_target = "riscv64-unknown-linux-gnu"
    249249                helenos_target = "riscv64-helenos"
    250        
     250
    251251        if (config['PLATFORM'] == "sparc64"):
    252252                platform = config['PLATFORM']
    253253                gnu_target = "sparc64-linux-gnu"
    254254                helenos_target = "sparc64-helenos"
    255        
     255
    256256        if (config['COMPILER'] == "gcc_helenos"):
    257257                target = helenos_target
    258258        else:
    259259                target = gnu_target
    260        
     260
    261261        return (platform, cc_args, target)
    262262
    263263def check_app(args, name, details):
    264264        "Check whether an application can be executed"
    265        
     265
    266266        try:
    267267                sys.stderr.write("Checking for %s ... " % args[0])
     
    273273                             "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
    274274                             "is installed in your system (%s)." % details])
    275        
     275
    276276        sys.stderr.write("ok\n")
    277277
    278278def check_app_alternatives(alts, args, name, details):
    279279        "Check whether an application can be executed (use several alternatives)"
    280        
     280
    281281        tried = []
    282282        found = None
    283        
     283
    284284        for alt in alts:
    285285                working = True
    286286                cmdline = [alt] + args
    287287                tried.append(" ".join(cmdline))
    288                
     288
    289289                try:
    290290                        sys.stderr.write("Checking for %s ... " % alt)
     
    293293                        sys.stderr.write("failed\n")
    294294                        working = False
    295                
     295
    296296                if (working):
    297297                        sys.stderr.write("ok\n")
    298298                        found = alt
    299299                        break
    300        
     300
    301301        if (found is None):
    302302                print_error(["%s is missing." % name,
     
    306306                             "",
    307307                             "The following alternatives were tried:"] + tried)
    308        
     308
    309309        return found
    310310
    311311def check_clang(path, prefix, common, details):
    312312        "Check for clang"
    313        
     313
    314314        common['CLANG'] = "%sclang" % prefix
    315        
     315
    316316        if (not path is None):
    317317                common['CLANG'] = "%s/%s" % (path, common['CLANG'])
    318        
     318
    319319        check_app([common['CLANG'], "--version"], "clang", details)
    320320
    321321def check_gcc(path, prefix, common, details):
    322322        "Check for GCC"
    323        
     323
    324324        common['GCC'] = "%sgcc" % prefix
    325        
     325
    326326        if (not path is None):
    327327                common['GCC'] = "%s/%s" % (path, common['GCC'])
    328        
     328
    329329        check_app([common['GCC'], "--version"], "GNU GCC", details)
    330330
    331331def check_binutils(path, prefix, common, details):
    332332        "Check for binutils toolchain"
    333        
     333
    334334        common['AS'] = "%sas" % prefix
    335335        common['LD'] = "%sld" % prefix
     
    338338        common['OBJDUMP'] = "%sobjdump" % prefix
    339339        common['STRIP'] = "%sstrip" % prefix
    340        
     340
    341341        if (not path is None):
    342342                for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
    343343                        common[key] = "%s/%s" % (path, common[key])
    344        
     344
    345345        check_app([common['AS'], "--version"], "GNU Assembler", details)
    346346        check_app([common['LD'], "--version"], "GNU Linker", details)
     
    352352def check_python():
    353353        "Check for Python dependencies"
    354        
     354
    355355        try:
    356356                sys.stderr.write("Checking for PyYAML ... ")
     
    361361                             "Please make sure that it is installed in your",
    362362                             "system (usually part of PyYAML package)."])
    363        
     363
    364364        sys.stderr.write("ok\n")
    365365
    366366def decode_value(value):
    367367        "Decode integer value"
    368        
     368
    369369        base = 10
    370        
     370
    371371        if ((value.startswith('$')) or (value.startswith('#'))):
    372372                value = value[1:]
    373        
     373
    374374        if (value.startswith('0x')):
    375375                value = value[2:]
    376376                base = 16
    377        
     377
    378378        return int(value, base)
    379379
    380380def probe_compiler(common, typesizes):
    381381        "Generate, compile and parse probing source"
    382        
     382
    383383        check_common(common, "CC")
    384        
     384
    385385        outf = open(PROBE_SOURCE, 'w')
    386386        outf.write(PROBE_HEAD)
    387        
     387
    388388        for typedef in typesizes:
    389389                if 'def' in typedef:
     
    392392                if 'def' in typedef:
    393393                        outf.write("#endif\n")
    394        
     394
    395395        outf.write(PROBE_TAIL)
    396396        outf.close()
    397        
     397
    398398        args = common['CC_AUTOGEN'].split(' ')
    399399        args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
    400        
     400
    401401        try:
    402402                sys.stderr.write("Checking compiler properties ... ")
     
    406406                print_error(["Error executing \"%s\"." % " ".join(args),
    407407                             "Make sure that the compiler works properly."])
    408        
     408
    409409        if (not os.path.isfile(PROBE_OUTPUT)):
    410410                sys.stderr.write("failed\n")
     
    415415                             output[0],
    416416                             output[1]])
    417        
     417
    418418        sys.stderr.write("ok\n")
    419        
     419
    420420        inf = open(PROBE_OUTPUT, 'r')
    421421        lines = inf.readlines()
    422422        inf.close()
    423        
     423
    424424        builtins = {}
    425        
     425
    426426        for j in range(len(lines)):
    427427                tokens = lines[j].strip().split("\t")
    428                
     428
    429429                if (len(tokens) > 0):
    430430                        if (tokens[0] == "AUTOTOOL_DECLARE"):
    431431                                if (len(tokens) < 8):
    432432                                        print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
    433                                
     433
    434434                                category = tokens[1]
    435435                                tag = tokens[2]
     
    439439                                size = tokens[6]
    440440                                compatible = tokens[7]
    441                                
     441
    442442                                try:
    443443                                        compatible_int = decode_value(compatible)
     
    445445                                except:
    446446                                        print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
    447                                
     447
    448448                                if (compatible_int == 1):
    449449                                        builtins[tag] = {
     
    454454                                                'size': size_int,
    455455                                        }
    456        
     456
    457457        for typedef in typesizes:
    458458                if not typedef['tag'] in builtins:
     
    461461                if 'sname' in typedef:
    462462                        builtins[typedef['tag']]['sname'] = typedef['sname']
    463        
     463
    464464        return builtins
    465465
     
    490490def detect_sizes(probe):
    491491        "Detect properties of builtin types"
    492        
     492
    493493        macros = {}
    494        
     494
    495495        for type in probe.values():
    496496                macros['__SIZEOF_%s__' % type['tag']] = type['size']
    497                
     497
    498498                if ('sname' in type):
    499499                        macros['__%s_TYPE__'  % type['sname']] = type['name']
     
    502502                        macros['__%s_C_SUFFIX__' % type['sname']] = get_suffix(type)
    503503                        macros['__%s_MAX__' % type['sname']] = "%d%s" % (get_max(type), get_suffix(type))
    504        
     504
    505505        if (probe['SIZE_T']['sign'] != 'unsigned'):
    506506                print_error(['The type size_t is not unsigned.', COMPILER_FAIL])
    507        
     507
    508508        return macros
    509509
    510510def create_makefile(mkname, common):
    511511        "Create makefile output"
    512        
     512
    513513        outmk = open(mkname, 'w')
    514        
     514
    515515        outmk.write('#########################################\n')
    516516        outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
    517517        outmk.write('## Generated by: tools/autotool.py     ##\n')
    518518        outmk.write('#########################################\n\n')
    519        
     519
    520520        for key, value in common.items():
    521521                if (type(value) is list):
     
    523523                else:
    524524                        outmk.write('%s = %s\n' % (key, value))
    525        
     525
    526526        outmk.close()
    527527
    528528def create_header(hdname, macros):
    529529        "Create header output"
    530        
     530
    531531        outhd = open(hdname, 'w')
    532        
     532
    533533        outhd.write('/***************************************\n')
    534534        outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
    535535        outhd.write(' * Generated by: tools/autotool.py     *\n')
    536536        outhd.write(' ***************************************/\n\n')
    537        
     537
    538538        outhd.write('#ifndef %s\n' % GUARD)
    539539        outhd.write('#define %s\n\n' % GUARD)
    540        
     540
    541541        for macro in sorted(macros):
    542542                outhd.write('#ifndef %s\n' % macro)
    543543                outhd.write('#define %s  %s\n' % (macro, macros[macro]))
    544544                outhd.write('#endif\n\n')
    545        
     545
    546546        outhd.write('\n#endif\n')
    547547        outhd.close()
     
    550550        config = {}
    551551        common = {}
    552        
     552
    553553        # Read and check configuration
    554554        if os.path.exists(CONFIG):
     
    558558                             "configuration phase of HelenOS build went OK. Try running",
    559559                             "\"make config\" again."])
    560        
     560
    561561        check_config(config, "PLATFORM")
    562562        check_config(config, "COMPILER")
    563563        check_config(config, "BARCH")
    564        
     564
    565565        # Cross-compiler prefix
    566566        if ('CROSS_PREFIX' in os.environ):
     
    568568        else:
    569569                cross_prefix = "/usr/local/cross"
    570        
     570
    571571        # HelenOS cross-compiler prefix
    572572        if ('CROSS_HELENOS_PREFIX' in os.environ):
     
    574574        else:
    575575                cross_helenos_prefix = "/usr/local/cross-helenos"
    576        
     576
    577577        # Prefix binutils tools on Solaris
    578578        if (os.uname()[0] == "SunOS"):
     
    580580        else:
    581581                binutils_prefix = ""
    582        
     582
    583583        owd = sandbox_enter()
    584        
     584
    585585        try:
    586586                # Common utilities
     
    593593                check_app(["make", "--version"], "Make utility", "preferably GNU Make")
    594594                check_app(["unzip"], "unzip utility", "usually part of zip/unzip utilities")
    595                
     595
    596596                platform, cc_args, target = get_target(config)
    597                
     597
    598598                if (platform is None) or (target is None):
    599599                        print_error(["Unsupported compiler target.",
    600600                                     "Please contact the developers of HelenOS."])
    601                
     601
    602602                path = "%s/%s/bin" % (cross_prefix, target)
    603                
     603
    604604                # Compatibility with earlier toolchain paths.
    605605                if not os.path.exists(path):
     
    614614                                        print_error(["Toolchain for target is not installed, or CROSS_PREFIX is not set correctly."])
    615615                                path = "%s/%s/bin" % (cross_prefix, platform)
    616                
     616
    617617                common['TARGET'] = target
    618618                prefix = "%s-" % target
    619                
     619
    620620                # Compiler
    621621                if (config['COMPILER'] == "gcc_cross" or config['COMPILER'] == "gcc_helenos"):
    622622                        check_gcc(path, prefix, common, PACKAGE_CROSS)
    623623                        check_binutils(path, prefix, common, PACKAGE_CROSS)
    624                        
     624
    625625                        check_common(common, "GCC")
    626626                        common['CC'] = " ".join([common['GCC']] + cc_args)
    627627                        common['CC_AUTOGEN'] = common['CC']
    628                
     628
    629629                if (config['COMPILER'] == "gcc_native"):
    630630                        check_gcc(None, "", common, PACKAGE_GCC)
    631631                        check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
    632                        
     632
    633633                        check_common(common, "GCC")
    634634                        common['CC'] = common['GCC']
    635635                        common['CC_AUTOGEN'] = common['CC']
    636                
     636
    637637                if (config['COMPILER'] == "clang"):
    638638                        check_binutils(path, prefix, common, PACKAGE_CROSS)
    639639                        check_clang(path, prefix, common, PACKAGE_CLANG)
    640                        
     640
    641641                        check_common(common, "CLANG")
    642642                        common['CC'] = " ".join([common['CLANG']] + cc_args)
    643643                        common['CC_AUTOGEN'] = common['CC'] + " -no-integrated-as"
    644                        
     644
    645645                        if (config['INTEGRATED_AS'] == "yes"):
    646646                                common['CC'] += " -integrated-as"
    647                        
     647
    648648                        if (config['INTEGRATED_AS'] == "no"):
    649649                                common['CC'] += " -no-integrated-as"
    650                
     650
    651651                check_python()
    652                
     652
    653653                # Platform-specific utilities
    654654                if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
     
    656656                        if common['GENISOIMAGE'] == 'xorriso':
    657657                                common['GENISOIMAGE'] += ' -as genisoimage'
    658                
     658
    659659                probe = probe_compiler(common,
    660660                        [
     
    675675                        ]
    676676                )
    677                
     677
    678678                macros = detect_sizes(probe)
    679                
     679
    680680        finally:
    681681                sandbox_leave(owd)
    682        
     682
    683683        common['AUTOGEN'] = "%s/autogen.py" % os.path.dirname(os.path.abspath(sys.argv[0]))
    684        
     684
    685685        create_makefile(MAKEFILE, common)
    686686        create_header(HEADER, macros)
    687        
     687
    688688        return 0
    689689
Note: See TracChangeset for help on using the changeset viewer.