Changeset 8565a42 in mainline for tools


Ignore:
Timestamp:
2018-03-02T20:34:50Z (8 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

Location:
tools
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • tools/autogen.py

    r3061bc1 r8565a42  
    8585                        code = code + ("\temit_constant(%s_%s_ITEM_SIZE, sizeof(%s));\n" %
    8686                            (struct['name'].upper(), member['name'].upper(), member['type']))
    87                        
     87
    8888        return code
    8989
     
    113113        """ % (generate_includes(struct), generate_struct(struct),
    114114            generate_probes(struct), name.upper(), typename)
    115        
     115
    116116        return code
    117117
     
    159159                pairs = pairs + [res.group(1, 3)]
    160160        return pairs
    161        
     161
    162162
    163163def run():
  • tools/autotool.py

    r3061bc1 r8565a42  
    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
  • tools/checkers/clang.py

    r3061bc1 r8565a42  
    4646def clang(root, job):
    4747        "Run Clang on a jobfile"
    48        
     48
    4949        inname = os.path.join(root, job)
    50        
     50
    5151        if (not os.path.isfile(inname)):
    5252                print("Unable to open %s" % inname)
    5353                print("Did you run \"make precheck\" on the source tree?")
    5454                return False
    55        
     55
    5656        inf = open(inname, "r")
    5757        records = inf.read().splitlines()
    5858        inf.close()
    59        
     59
    6060        for record in records:
    6161                arg = jobfile.parse_arg(record)
    6262                if (not arg):
    6363                        return False
    64                
     64
    6565                if (len(arg) < 6):
    6666                        print("Not enough jobfile record arguments")
    6767                        return False
    68                
     68
    6969                srcfname = arg[0]
    7070                tgtfname = arg[1]
     
    7373                base = arg[4]
    7474                options = arg[5].split()
    75                
     75
    7676                srcfqname = os.path.join(base, srcfname)
    7777                if (not os.path.isfile(srcfqname)):
    7878                        print("Source %s not found" % srcfqname)
    7979                        return False
    80                
     80
    8181                # Only C files are interesting for us
    8282                if (tool != "cc"):
    8383                        continue
    84                
     84
    8585                args = ['clang', '-Qunused-arguments', '--analyze',
    8686                        '-Xanalyzer', '-analyzer-opt-analyze-headers',
     
    8888                args.extend(options)
    8989                args.extend(['-o', tgtfname, srcfname])
    90                
     90
    9191                cwd = os.getcwd()
    9292                os.chdir(base)
    9393                retval = subprocess.Popen(args).wait()
    9494                os.chdir(cwd)
    95                
     95
    9696                if (retval != 0):
    9797                        return False
    98                
     98
    9999        return True
    100100
     
    103103                usage(sys.argv[0])
    104104                return
    105        
     105
    106106        rootdir = os.path.abspath(sys.argv[1])
    107107        config = os.path.join(rootdir, "HelenOS.config")
    108        
     108
    109109        if (not os.path.isfile(config)):
    110110                print("%s not found." % config)
    111111                print("Please specify the path to HelenOS build tree root as the first argument.")
    112112                return
    113        
     113
    114114        for job in jobs:
    115115                if (not clang(rootdir, job)):
     
    117117                        print("Failed job: %s" % job)
    118118                        return
    119        
     119
    120120        print
    121121        print("All jobs passed")
  • tools/checkers/jobfile.py

    r3061bc1 r8565a42  
    3232def parse_arg(record):
    3333        "Parse jobfile line arguments"
    34        
     34
    3535        arg = []
    3636        i = 0
     
    3838        nil = True
    3939        inside = False
    40        
     40
    4141        while (i < len(record)):
    4242                if (inside):
     
    5656                                print("Unexpected '%s'" % record[i])
    5757                                return False
    58                
     58
    5959                i += 1
    60        
     60
    6161        if (not nil):
    6262                arg.append(current)
    63        
     63
    6464        return arg
  • tools/checkers/stanse.py

    r3061bc1 r8565a42  
    4747def stanse(root, job):
    4848        "Run Stanse on a jobfile"
    49        
     49
    5050        # Convert generic jobfile to Stanse-specific jobfile format
    51        
     51
    5252        inname = os.path.join(root, job)
    5353        outname = os.path.join(root, "_%s" % os.path.basename(job))
    54        
     54
    5555        if (not os.path.isfile(inname)):
    5656                print("Unable to open %s" % inname)
    5757                print("Did you run \"make precheck\" on the source tree?")
    5858                return False
    59        
     59
    6060        inf = open(inname, "r")
    6161        records = inf.read().splitlines()
    6262        inf.close()
    63        
     63
    6464        output = []
    6565        for record in records:
     
    6767                if (not arg):
    6868                        return False
    69                
     69
    7070                if (len(arg) < 6):
    7171                        print("Not enough jobfile record arguments")
    7272                        return False
    73                
     73
    7474                srcfname = arg[0]
    7575                tgtfname = arg[1]
     
    7878                base = arg[4]
    7979                options = arg[5]
    80                
     80
    8181                srcfqname = os.path.join(base, srcfname)
    8282                if (not os.path.isfile(srcfqname)):
    8383                        print("Source %s not found" % srcfqname)
    8484                        return False
    85                
     85
    8686                # Only C files are interesting for us
    8787                if (tool != "cc"):
    8888                        continue
    89                
     89
    9090                output.append([srcfname, tgtfname, base, options])
    91        
     91
    9292        outf = open(outname, "w")
    9393        for record in output:
    9494                outf.write("{%s},{%s},{%s},{%s}\n" % (record[0], record[1], record[2], record[3]))
    9595        outf.close()
    96        
     96
    9797        # Run Stanse
    98        
     98
    9999        retval = subprocess.Popen(['stanse', '--checker', 'ReachabilityChecker', '--jobfile', outname]).wait()
    100        
     100
    101101        # Cleanup
    102        
     102
    103103        os.remove(outname)
    104104        for record in output:
     
    106106                if (os.path.isfile(tmpfile)):
    107107                        os.remove(tmpfile)
    108        
     108
    109109        if (retval == 0):
    110110                return True
    111        
     111
    112112        return False
    113113
     
    116116                usage(sys.argv[0])
    117117                return
    118        
     118
    119119        rootdir = os.path.abspath(sys.argv[1])
    120120        config = os.path.join(rootdir, "HelenOS.config")
    121        
     121
    122122        if (not os.path.isfile(config)):
    123123                print("%s not found." % config)
    124124                print("Please specify the path to HelenOS build tree root as the first argument.")
    125125                return
    126        
     126
    127127        for job in jobs:
    128128                if (not stanse(rootdir, job)):
     
    130130                        print("Failed job: %s" % job)
    131131                        return
    132        
     132
    133133        print
    134134        print("All jobs passed")
  • tools/checkers/vcc.py

    r3061bc1 r8565a42  
    5353def cygpath(upath):
    5454        "Convert Unix (Cygwin) path to Windows path"
    55        
     55
    5656        return subprocess.Popen(['cygpath', '--windows', '--absolute', upath], stdout = subprocess.PIPE).communicate()[0].strip()
    5757
    5858def preprocess(srcfname, tmpfname, base, options):
    5959        "Preprocess source using GCC preprocessor and compatibility tweaks"
    60        
     60
    6161        global specification
    62        
     62
    6363        args = ['gcc', '-E']
    6464        args.extend(options.split())
    6565        args.extend(['-DCONFIG_VERIFY_VCC=1', srcfname])
    66        
     66
    6767        # Change working directory
    68        
     68
    6969        cwd = os.getcwd()
    7070        os.chdir(base)
    71        
     71
    7272        preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
    73        
     73
    7474        tmpf = open(tmpfname, "w")
    7575        tmpf.write(specification)
    76        
     76
    7777        for line in preproc.splitlines():
    78                
     78
    7979                # Ignore preprocessor directives
    80                
     80
    8181                if (line.startswith('#')):
    8282                        continue
    83                
     83
    8484                # Remove __attribute__((.*)) GCC extension
    85                
     85
    8686                line = re.sub(re_attribute, "", line)
    87                
     87
    8888                # Ignore unsupported __builtin_va_list type
    8989                # (a better solution replacing __builrin_va_list with
    9090                # an emulated implementation is needed)
    91                
     91
    9292                line = re.sub(re_va_list, "void *", line)
    93                
     93
    9494                tmpf.write("%s\n" % line)
    95        
     95
    9696        tmpf.close()
    97        
     97
    9898        os.chdir(cwd)
    99        
     99
    100100        return True
    101101
    102102def vcc(vcc_path, root, job):
    103103        "Run Vcc on a jobfile"
    104        
     104
    105105        # Parse jobfile
    106        
     106
    107107        inname = os.path.join(root, job)
    108        
     108
    109109        if (not os.path.isfile(inname)):
    110110                print("Unable to open %s" % inname)
    111111                print("Did you run \"make precheck\" on the source tree?")
    112112                return False
    113        
     113
    114114        inf = open(inname, "r")
    115115        records = inf.read().splitlines()
    116116        inf.close()
    117        
     117
    118118        for record in records:
    119119                arg = jobfile.parse_arg(record)
    120120                if (not arg):
    121121                        return False
    122                
     122
    123123                if (len(arg) < 6):
    124124                        print("Not enough jobfile record arguments")
    125125                        return False
    126                
     126
    127127                srcfname = arg[0]
    128128                tgtfname = arg[1]
     
    131131                base = arg[4]
    132132                options = arg[5]
    133                
     133
    134134                srcfqname = os.path.join(base, srcfname)
    135135                if (not os.path.isfile(srcfqname)):
    136136                        print("Source %s not found" % srcfqname)
    137137                        return False
    138                
     138
    139139                tmpfname = "%s.preproc" % srcfname
    140140                tmpfqname = os.path.join(base, tmpfname)
    141                
     141
    142142                vccfname = "%s.i" % srcfname
    143143                vccfqname = os.path.join(base, vccfname);
    144                
     144
    145145                # Only C files are interesting for us
    146146                if (tool != "cc"):
    147147                        continue
    148                
     148
    149149                # Preprocess sources
    150                
     150
    151151                if (not preprocess(srcfname, tmpfname, base, options)):
    152152                        return False
    153                
     153
    154154                # Run Vcc
    155155                print(" -- %s --" % srcfname)
    156156                retval = subprocess.Popen([vcc_path, '/pointersize:32', '/newsyntax', cygpath(tmpfqname)]).wait()
    157                
     157
    158158                if (retval != 0):
    159159                        return False
    160                
     160
    161161                # Cleanup, but only if verification was successful
    162162                # (to be able to examine the preprocessed file)
    163                
     163
    164164                if (os.path.isfile(tmpfqname)):
    165165                        os.remove(tmpfqname)
    166166                        os.remove(vccfqname)
    167        
     167
    168168        return True
    169169
    170170def main():
    171171        global specification
    172        
     172
    173173        if (len(sys.argv) < 2):
    174174                usage(sys.argv[0])
    175175                return
    176        
     176
    177177        rootdir = os.path.abspath(sys.argv[1])
    178178        if (len(sys.argv) > 2):
     
    180180        else:
    181181                vcc_path = "/cygdrive/c/Program Files (x86)/Microsoft Research/Vcc/Binaries/vcc"
    182        
     182
    183183        if (not os.path.isfile(vcc_path)):
    184184                print("%s is not a binary." % vcc_path)
    185185                print("Please supply the full Cygwin path to Vcc as the second argument.")
    186186                return
    187        
     187
    188188        config = os.path.join(rootdir, "HelenOS.config")
    189        
     189
    190190        if (not os.path.isfile(config)):
    191191                print("%s not found." % config)
    192192                print("Please specify the path to HelenOS build tree root as the first argument.")
    193193                return
    194        
     194
    195195        specpath = os.path.join(rootdir, "tools/checkers/vcc.h")
    196196        if (not os.path.isfile(specpath)):
    197197                print("%s not found." % config)
    198198                return
    199        
     199
    200200        specfile = file(specpath, "r")
    201201        specification = specfile.read()
    202202        specfile.close()
    203        
     203
    204204        for job in jobs:
    205205                if (not vcc(vcc_path, rootdir, job)):
     
    207207                        print("Failed job: %s" % job)
    208208                        return
    209        
     209
    210210        print()
    211211        print("All jobs passed")
  • tools/config.py

    r3061bc1 r8565a42  
    4949def read_config(fname, config):
    5050        "Read saved values from last configuration run or a preset file"
    51        
     51
    5252        inf = open(fname, 'r')
    53        
     53
    5454        for line in inf:
    5555                res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
    5656                if res:
    5757                        config[res.group(1)] = res.group(2)
    58        
     58
    5959        inf.close()
    6060
    6161def check_condition(text, config, rules):
    6262        "Check that the condition specified on input line is True (only CNF and DNF is supported)"
    63        
     63
    6464        ctype = 'cnf'
    65        
     65
    6666        if (')|' in text) or ('|(' in text):
    6767                ctype = 'dnf'
    68        
     68
    6969        if ctype == 'cnf':
    7070                conds = text.split('&')
    7171        else:
    7272                conds = text.split('|')
    73        
     73
    7474        for cond in conds:
    7575                if cond.startswith('(') and cond.endswith(')'):
    7676                        cond = cond[1:-1]
    77                
     77
    7878                inside = check_inside(cond, config, ctype)
    79                
     79
    8080                if (ctype == 'cnf') and (not inside):
    8181                        return False
    82                
     82
    8383                if (ctype == 'dnf') and inside:
    8484                        return True
    85        
     85
    8686        if ctype == 'cnf':
    8787                return True
    88        
     88
    8989        return False
    9090
    9191def check_inside(text, config, ctype):
    9292        "Check for condition"
    93        
     93
    9494        if ctype == 'cnf':
    9595                conds = text.split('|')
    9696        else:
    9797                conds = text.split('&')
    98        
     98
    9999        for cond in conds:
    100100                res = re.match(r'^(.*?)(!?=)(.*)$', cond)
    101101                if not res:
    102102                        raise RuntimeError("Invalid condition: %s" % cond)
    103                
     103
    104104                condname = res.group(1)
    105105                oper = res.group(2)
    106106                condval = res.group(3)
    107                
     107
    108108                if not condname in config:
    109109                        varval = ''
     
    112112                        if (varval == '*'):
    113113                                varval = 'y'
    114                
     114
    115115                if ctype == 'cnf':
    116116                        if (oper == '=') and (condval == varval):
    117117                                return True
    118                
     118
    119119                        if (oper == '!=') and (condval != varval):
    120120                                return True
     
    122122                        if (oper == '=') and (condval != varval):
    123123                                return False
    124                        
     124
    125125                        if (oper == '!=') and (condval == varval):
    126126                                return False
    127        
     127
    128128        if ctype == 'cnf':
    129129                return False
    130        
     130
    131131        return True
    132132
    133133def parse_rules(fname, rules):
    134134        "Parse rules file"
    135        
     135
    136136        inf = open(fname, 'r')
    137        
     137
    138138        name = ''
    139139        choices = []
    140        
     140
    141141        for line in inf:
    142                
     142
    143143                if line.startswith('!'):
    144144                        # Ask a question
    145145                        res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line)
    146                        
     146
    147147                        if not res:
    148148                                raise RuntimeError("Weird line: %s" % line)
    149                        
     149
    150150                        cond = res.group(1)
    151151                        varname = res.group(2)
    152152                        vartype = res.group(3)
    153                        
     153
    154154                        rules.append((varname, vartype, name, choices, cond))
    155155                        name = ''
    156156                        choices = []
    157157                        continue
    158                
     158
    159159                if line.startswith('@'):
    160160                        # Add new line into the 'choices' array
    161161                        res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
    162                        
     162
    163163                        if not res:
    164164                                raise RuntimeError("Bad line: %s" % line)
    165                        
     165
    166166                        choices.append((res.group(2), res.group(3)))
    167167                        continue
    168                
     168
    169169                if line.startswith('%'):
    170170                        # Name of the option
    171171                        name = line[1:].strip()
    172172                        continue
    173                
     173
    174174                if line.startswith('#') or (line == '\n'):
    175175                        # Comment or empty line
    176176                        continue
    177                
    178                
     177
     178
    179179                raise RuntimeError("Unknown syntax: %s" % line)
    180        
     180
    181181        inf.close()
    182182
    183183def yes_no(default):
    184184        "Return '*' if yes, ' ' if no"
    185        
     185
    186186        if default == 'y':
    187187                return '*'
    188        
     188
    189189        return ' '
    190190
    191191def subchoice(screen, name, choices, default):
    192192        "Return choice of choices"
    193        
     193
    194194        maxkey = 0
    195195        for key, val in choices:
     
    197197                if (length > maxkey):
    198198                        maxkey = length
    199        
     199
    200200        options = []
    201201        position = None
     
    204204                if (default) and (key == default):
    205205                        position = cnt
    206                
     206
    207207                options.append(" %-*s  %s " % (maxkey, key, val))
    208208                cnt += 1
    209        
     209
    210210        (button, value) = xtui.choice_window(screen, name, 'Choose value', options, position)
    211        
     211
    212212        if button == 'cancel':
    213213                return None
    214        
     214
    215215        return choices[value][0]
    216216
     
    228228def infer_verify_choices(config, rules):
    229229        "Infer and verify configuration values."
    230        
     230
    231231        for rule in rules:
    232232                varname, vartype, name, choices, cond = rule
    233                
     233
    234234                if cond and (not check_condition(cond, config, rules)):
    235235                        continue
    236                
     236
    237237                if not varname in config:
    238238                        value = None
    239239                else:
    240240                        value = config[varname]
    241                
     241
    242242                if not validate_rule_value(rule, value):
    243243                        value = None
    244                
     244
    245245                default = get_default_rule(rule)
    246                
     246
    247247                #
    248248                # If we don't have a value but we do have
     
    252252                        value = default
    253253                        config[varname] = default
    254                
     254
    255255                if not varname in config:
    256256                        return False
    257        
     257
    258258        return True
    259259
     
    275275        if start_index >= len(rules):
    276276                return True
    277        
     277
    278278        varname, vartype, name, choices, cond = rules[start_index]
    279279
     
    282282                if not check_condition(cond, config, rules):
    283283                        return random_choices(config, rules, start_index + 1)
    284        
     284
    285285        # Remember previous choices for backtracking
    286286        yes_no = 0
    287287        choices_indexes = range(0, len(choices))
    288288        random.shuffle(choices_indexes)
    289        
     289
    290290        # Remember current configuration value
    291291        old_value = None
     
    294294        except KeyError:
    295295                old_value = None
    296        
     296
    297297        # For yes/no choices, we ran the loop at most 2 times, for select
    298298        # choices as many times as there are options.
     
    320320                else:
    321321                        raise RuntimeError("Unknown variable type: %s" % vartype)
    322        
     322
    323323                config[varname] = value
    324                
     324
    325325                ok = random_choices(config, rules, start_index + 1)
    326326                if ok:
    327327                        return True
    328                
     328
    329329                try_counter = try_counter + 1
    330        
     330
    331331        # Restore the old value and backtrack
    332332        # (need to delete to prevent "ghost" variables that do not exist under
     
    335335        if old_value is None:
    336336                del config[varname]
    337        
     337
    338338        return random_choices(config, rules, start_index + 1)
    339        
     339
    340340
    341341## Get default value from a rule.
    342342def get_default_rule(rule):
    343343        varname, vartype, name, choices, cond = rule
    344        
     344
    345345        default = None
    346        
     346
    347347        if vartype == 'choice':
    348348                # If there is just one option, use it
     
    359359        else:
    360360                raise RuntimeError("Unknown variable type: %s" % vartype)
    361        
     361
    362362        return default
    363363
     
    371371def get_rule_option(rule, value):
    372372        varname, vartype, name, choices, cond = rule
    373        
     373
    374374        option = None
    375        
     375
    376376        if vartype == 'choice':
    377377                # If there is just one option, don't ask
     
    391391        else:
    392392                raise RuntimeError("Unknown variable type: %s" % vartype)
    393        
     393
    394394        return option
    395395
     
    403403def validate_rule_value(rule, value):
    404404        varname, vartype, name, choices, cond = rule
    405        
     405
    406406        if value == None:
    407407                return True
    408        
     408
    409409        if vartype == 'choice':
    410410                if not value in [choice[0] for choice in choices]:
     
    424424        else:
    425425                raise RuntimeError("Unknown variable type: %s" % vartype)
    426        
     426
    427427        return True
    428428
    429429def preprocess_config(config, rules):
    430430        "Preprocess configuration"
    431        
     431
    432432        varname_mode = 'CONFIG_BFB_MODE'
    433433        varname_width = 'CONFIG_BFB_WIDTH'
    434434        varname_height = 'CONFIG_BFB_HEIGHT'
    435        
     435
    436436        if varname_mode in config:
    437437                mode = config[varname_mode].partition('x')
    438                
     438
    439439                config[varname_width] = mode[0]
    440440                rules.append((varname_width, 'choice', 'Default framebuffer width', None, None))
    441                
     441
    442442                config[varname_height] = mode[2]
    443443                rules.append((varname_height, 'choice', 'Default framebuffer height', None, None))
     
    445445def create_output(mkname, mcname, config, rules):
    446446        "Create output configuration"
    447        
     447
    448448        varname_strip = 'CONFIG_STRIP_REVISION_INFO'
    449449        strip_rev_info = (varname_strip in config) and (config[varname_strip] == 'y')
    450        
     450
    451451        if strip_rev_info:
    452452                timestamp_unix = int(0)
     
    454454                # TODO: Use commit timestamp instead of build time.
    455455                timestamp_unix = int(time.time())
    456        
     456
    457457        timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp_unix))
    458        
     458
    459459        sys.stderr.write("Fetching current revision identifier ... ")
    460        
     460
    461461        try:
    462462                version = subprocess.Popen(['git', 'log', '-1', '--pretty=%h'], stdout = subprocess.PIPE).communicate()[0].decode().strip()
     
    465465                version = None
    466466                sys.stderr.write("failed\n")
    467        
     467
    468468        if (not strip_rev_info) and (version is not None):
    469469                revision = version
    470470        else:
    471471                revision = None
    472        
     472
    473473        outmk = open(mkname, 'w')
    474474        outmc = open(mcname, 'w')
    475        
     475
    476476        outmk.write('#########################################\n')
    477477        outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
    478478        outmk.write('## Generated by: tools/config.py       ##\n')
    479479        outmk.write('#########################################\n\n')
    480        
     480
    481481        outmc.write('/***************************************\n')
    482482        outmc.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
    483483        outmc.write(' * Generated by: tools/config.py       *\n')
    484484        outmc.write(' ***************************************/\n\n')
    485        
     485
    486486        defs = 'CONFIG_DEFS ='
    487        
     487
    488488        for varname, vartype, name, choices, cond in rules:
    489489                if cond and (not check_condition(cond, config, rules)):
    490490                        continue
    491                
     491
    492492                if not varname in config:
    493493                        value = ''
     
    496496                        if (value == '*'):
    497497                                value = 'y'
    498                
     498
    499499                outmk.write('# %s\n%s = %s\n\n' % (name, varname, value))
    500                
     500
    501501                if vartype in ["y", "n", "y/n", "n/y"]:
    502502                        if value == "y":
     
    506506                        outmc.write('/* %s */\n#define %s %s\n#define %s_%s\n\n' % (name, varname, value, varname, value))
    507507                        defs += ' -D%s=%s -D%s_%s' % (varname, value, varname, value)
    508        
     508
    509509        if revision is not None:
    510510                outmk.write('REVISION = %s\n' % revision)
    511511                outmc.write('#define REVISION %s\n' % revision)
    512512                defs += ' "-DREVISION=%s"' % revision
    513        
     513
    514514        outmk.write('TIMESTAMP_UNIX = %d\n' % timestamp_unix)
    515515        outmc.write('#define TIMESTAMP_UNIX %d\n' % timestamp_unix)
    516516        defs += ' "-DTIMESTAMP_UNIX=%d"\n' % timestamp_unix
    517        
     517
    518518        outmk.write('TIMESTAMP = %s\n' % timestamp)
    519519        outmc.write('#define TIMESTAMP %s\n' % timestamp)
    520520        defs += ' "-DTIMESTAMP=%s"\n' % timestamp
    521        
     521
    522522        outmk.write(defs)
    523        
     523
    524524        outmk.close()
    525525        outmc.close()
     
    536536        opt2path = {}
    537537        cnt = 0
    538        
     538
    539539        # Look for profiles
    540540        for name in sorted_dir(root):
    541541                path = os.path.join(root, name)
    542542                canon = os.path.join(path, fname)
    543                
     543
    544544                if os.path.isdir(path) and os.path.exists(canon) and os.path.isfile(canon):
    545545                        subprofile = False
    546                        
     546
    547547                        # Look for subprofiles
    548548                        for subname in sorted_dir(path):
    549549                                subpath = os.path.join(path, subname)
    550550                                subcanon = os.path.join(subpath, fname)
    551                                
     551
    552552                                if os.path.isdir(subpath) and os.path.exists(subcanon) and os.path.isfile(subcanon):
    553553                                        subprofile = True
     
    555555                                        opt2path[cnt] = [name, subname]
    556556                                        cnt += 1
    557                        
     557
    558558                        if not subprofile:
    559559                                options.append(name)
    560560                                opt2path[cnt] = [name]
    561561                                cnt += 1
    562        
     562
    563563        (button, value) = xtui.choice_window(screen, 'Load preconfigured defaults', 'Choose configuration profile', options, None)
    564        
     564
    565565        if button == 'cancel':
    566566                return None
    567        
     567
    568568        return opt2path[value]
    569569
     
    576576        path = os.path.join(PRESETS_DIR, profile[0], MAKEFILE)
    577577        read_config(path, config)
    578        
     578
    579579        if len(profile) > 1:
    580580                path = os.path.join(PRESETS_DIR, profile[0], profile[1], MAKEFILE)
     
    588588def parse_profile_name(profile_name):
    589589        profile = []
    590        
     590
    591591        head, tail = os.path.split(profile_name)
    592592        if head != '':
    593593                profile.append(head)
    594        
     594
    595595        profile.append(tail)
    596596        return profile
     
    600600        config = {}
    601601        rules = []
    602        
     602
    603603        # Parse rules file
    604604        parse_rules(RULES_FILE, rules)
    605        
     605
    606606        # Input configuration file can be specified on command line
    607607        # otherwise configuration from previous run is used.
     
    611611        elif os.path.exists(MAKEFILE):
    612612                read_config(MAKEFILE, config)
    613        
     613
    614614        # Default mode: check values and regenerate configuration files
    615615        if (len(sys.argv) >= 3) and (sys.argv[2] == 'default'):
     
    618618                        create_output(MAKEFILE, MACROS, config, rules)
    619619                        return 0
    620        
     620
    621621        # Hands-off mode: check values and regenerate configuration files,
    622622        # but no interactive fallback
     
    627627                        sys.stderr.write("Configuration error: No presets specified\n")
    628628                        return 2
    629                
     629
    630630                if (infer_verify_choices(config, rules)):
    631631                        preprocess_config(config, rules)
    632632                        create_output(MAKEFILE, MACROS, config, rules)
    633633                        return 0
    634                
     634
    635635                sys.stderr.write("Configuration error: The presets are ambiguous\n")
    636636                return 1
    637        
     637
    638638        # Check mode: only check configuration
    639639        if (len(sys.argv) >= 3) and (sys.argv[2] == 'check'):
     
    641641                        return 0
    642642                return 1
    643        
     643
    644644        # Random mode
    645645        if (len(sys.argv) == 3) and (sys.argv[2] == 'random'):
     
    653653                preprocess_config(config, rules)
    654654                create_output(MAKEFILE, MACROS, config, rules)
    655                
     655
    656656                return 0
    657        
     657
    658658        screen = xtui.screen_init()
    659659        try:
     
    661661                position = None
    662662                while True:
    663                        
     663
    664664                        # Cancel out all values which have to be deduced
    665665                        for varname, vartype, name, choices, cond in rules:
    666666                                if (vartype == 'y') and (varname in config) and (config[varname] == '*'):
    667667                                        config[varname] = None
    668                        
     668
    669669                        options = []
    670670                        opt2row = {}
    671671                        cnt = 1
    672                        
     672
    673673                        options.append("  --- Load preconfigured defaults ... ")
    674                        
     674
    675675                        for rule in rules:
    676676                                varname, vartype, name, choices, cond = rule
    677                                
     677
    678678                                if cond and (not check_condition(cond, config, rules)):
    679679                                        continue
    680                                
     680
    681681                                if varname == selname:
    682682                                        position = cnt
    683                                
     683
    684684                                if not varname in config:
    685685                                        value = None
    686686                                else:
    687687                                        value = config[varname]
    688                                
     688
    689689                                if not validate_rule_value(rule, value):
    690690                                        value = None
    691                                
     691
    692692                                default = get_default_rule(rule)
    693                                
     693
    694694                                #
    695695                                # If we don't have a value but we do have
     
    699699                                        value = default
    700700                                        config[varname] = default
    701                                
     701
    702702                                option = get_rule_option(rule, value)
    703703                                if option != None:
     
    705705                                else:
    706706                                        continue
    707                                
     707
    708708                                opt2row[cnt] = (varname, vartype, name, choices)
    709                                
     709
    710710                                cnt += 1
    711                        
     711
    712712                        if (position != None) and (position >= len(options)):
    713713                                position = None
    714                        
     714
    715715                        (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position)
    716                        
     716
    717717                        if button == 'cancel':
    718718                                return 'Configuration canceled'
    719                        
     719
    720720                        if button == 'done':
    721721                                if (infer_verify_choices(config, rules)):
     
    724724                                        xtui.error_dialog(screen, 'Error', 'Some options have still undefined values. These options are marked with the "?" sign.')
    725725                                        continue
    726                        
     726
    727727                        if value == 0:
    728728                                profile = choose_profile(PRESETS_DIR, MAKEFILE, screen, config)
     
    731731                                position = 1
    732732                                continue
    733                        
     733
    734734                        position = None
    735735                        if not value in opt2row:
    736736                                raise RuntimeError("Error selecting value: %s" % value)
    737                        
     737
    738738                        (selname, seltype, name, choices) = opt2row[value]
    739                        
     739
    740740                        if not selname in config:
    741741                                value = None
    742742                        else:
    743743                                value = config[selname]
    744                        
     744
    745745                        if seltype == 'choice':
    746746                                config[selname] = subchoice(screen, name, choices, value)
     
    752752        finally:
    753753                xtui.screen_done(screen)
    754        
     754
    755755        preprocess_config(config, rules)
    756756        create_output(MAKEFILE, MACROS, config, rules)
  • tools/dest_build.py

    r3061bc1 r8565a42  
    4242def duplicate_tree(src_path, dest_path, current):
    4343        "Duplicate source directory tree in the destination path"
    44        
     44
    4545        for name in os.listdir(os.path.join(src_path, current)):
    4646                if name in exclude_names:
    4747                        next
    48                
     48
    4949                following = os.path.join(current, name)
    5050                src = os.path.join(src_path, following)
     
    5252                dest_parent = os.path.join(dest_path, current)
    5353                dest_stat = os.stat(src)
    54                
     54
    5555                # Create shadow directories
    5656                if stat.S_ISDIR(dest_stat.st_mode):
    5757                        if not os.path.exists(dest):
    5858                                os.mkdir(dest)
    59                        
     59
    6060                        if not os.path.isdir(dest):
    6161                                raise IOError(errno.ENOTDIR, "Destination path exists, but is not a directory", dest)
    62                        
     62
    6363                        duplicate_tree(src_path, dest_path, following)
    6464                else:
    6565                        # Compute the relative path from destination to source
    6666                        relative = os.path.relpath(src, dest_parent)
    67                        
     67
    6868                        # Create symlink
    6969                        if not os.path.exists(dest):
     
    7878                usage(sys.argv[0])
    7979                return 1
    80        
     80
    8181        # Source tree path
    8282        src_path = os.path.abspath(sys.argv[1])
     
    8484                print("<SRC_PATH> must be a directory")
    8585                return 2
    86        
     86
    8787        # Destination tree path
    8888        dest_path = os.path.abspath(sys.argv[2])
    8989        if not os.path.exists(dest_path):
    9090                os.mkdir(dest_path)
    91        
     91
    9292        if not os.path.isdir(dest_path):
    9393                print("<DEST_PATH> must be a directory")
    9494                return 3
    95        
     95
    9696        # Duplicate source directory tree
    9797        duplicate_tree(src_path, dest_path, "")
    98        
     98
    9999        # Run the build from the destination tree
    100100        os.chdir(dest_path)
    101101        args = ["make"]
    102102        args.extend(sys.argv[3:])
    103        
     103
    104104        return subprocess.Popen(args).wait()
    105105
  • tools/ew.py

    r3061bc1 r8565a42  
    7676def pc_options(guest_width):
    7777        opts = ''
    78        
     78
    7979        # Do not enable KVM if running 64 bits HelenOS
    8080        # on 32 bits host
     
    8282        if guest_width <= host_width and not is_override('nokvm'):
    8383                opts = opts + ' -enable-kvm'
    84        
     84
    8585        # Remove the leading space
    8686        return opts[1:]
     
    132132        if is_override('nohdd'):
    133133                return ''
    134        
     134
    135135        hdisk_mk()
    136        
     136
    137137        return ' -drive file=hdisk.img,index=0,media=disk,format=raw'
    138138
     
    208208        if (not 'audio' in cfg.keys()) or cfg['audio']:
    209209                cmdline += qemu_audio_options()
    210        
     210
    211211        if cfg['image'] == 'image.iso':
    212212                cmdline += ' -boot d -cdrom image.iso'
     
    328328def fail(platform, machine):
    329329        print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
    330        
     330
    331331
    332332def run():
  • tools/imgutil.py

    r3061bc1 r8565a42  
    4040def align_up(size, alignment):
    4141        "Return size aligned up to alignment"
    42        
     42
    4343        if (size % alignment == 0):
    4444                return size
    45        
     45
    4646        return ((size // alignment) + 1) * alignment
    4747
    4848def count_up(size, alignment):
    4949        "Return units necessary to fit the size"
    50        
     50
    5151        if (size % alignment == 0):
    5252                return (size // alignment)
    53        
     53
    5454        return ((size // alignment) + 1)
    5555
    5656def num_of_trailing_bin_zeros(num):
    5757        "Return number of trailing zeros in binary representation"
    58        
     58
    5959        i = 0
    6060        if (num == 0): raise ValueError()
     
    6666def get_bit(number, n):
    6767        "Return True if n-th least-significant bit is set in the given number"
    68        
     68
    6969        return bool((number >> n) & 1)
    7070
    7171def set_bit(number, n):
    7272        "Return the number with n-th least-significant bit set"
    73        
     73
    7474        return number | (1 << n)
    7575
    7676class ItemToPack:
    7777        "Stores information about one directory item to be added to the image"
    78        
     78
    7979        def __init__(self, parent, name):
    8080                self.parent = parent
     
    8888def listdir_items(path):
    8989        "Return a list of items to be packed inside a fs image"
    90        
     90
    9191        for name in os.listdir(path):
    9292                if name in exclude_names:
    9393                        continue
    94                
     94
    9595                item = ItemToPack(path, name)
    96                
     96
    9797                if not (item.is_dir or item.is_file):
    9898                        continue
    99                
     99
    100100                yield item
    101101
    102102def chunks(item, chunk_size):
    103103        "Iterate contents of a file in chunks of a given size"
    104        
     104
    105105        inf = open(item.path, 'rb')
    106106        rd = 0
    107        
     107
    108108        while (rd < item.size):
    109109                data = bytes(inf.read(chunk_size))
    110110                yield data
    111111                rd += len(data)
    112        
     112
    113113        inf.close()
  • tools/jobfile.py

    r3061bc1 r8565a42  
    4444                usage(sys.argv[0])
    4545                return
    46        
     46
    4747        jobfname = sys.argv[1]
    4848        ccname = sys.argv[2]
     
    5353        options = " ".join(sys.argv[6:])
    5454        cwd = os.getcwd()
    55        
     55
    5656        if srcfname.endswith(".c"):
    5757                toolname = "cc"
    5858                category = "core"
    59        
     59
    6060        if srcfname.endswith(".s"):
    6161                toolname = "as"
    6262                category = "asm"
    63        
     63
    6464        if srcfname.endswith(".S"):
    6565                toolname = "as"
    6666                category = "asm/preproc"
    67        
     67
    6868        jobfile = open(jobfname, "a")
    6969        fcntl.lockf(jobfile, fcntl.LOCK_EX)
     
    7171        fcntl.lockf(jobfile, fcntl.LOCK_UN)
    7272        jobfile.close()
    73        
     73
    7474        # Run the compiler proper.
    7575        os.execvp(ccname, sys.argv[2:])
  • tools/mkarray.py

    r3061bc1 r8565a42  
    5757def main():
    5858        arg_check()
    59        
     59
    6060        if sys.argv[1] == "--deflate":
    6161                sys.argv.pop(1)
     
    6464        else:
    6565                compress = False
    66        
     66
    6767        dest = sys.argv[1]
    6868        label = sys.argv[2]
    6969        as_prolog = sys.argv[3]
    7070        section = sys.argv[4]
    71        
     71
    7272        timestamp = (1980, 1, 1, 0, 0, 0)
    73        
     73
    7474        header_ctx = []
    7575        desc_ctx = []
    7676        size_ctx = []
    7777        data_ctx = []
    78        
     78
    7979        src_cnt = 0
    80        
     80
    8181        archive = zipfile.ZipFile("%s.zip" % dest, "w", zipfile.ZIP_STORED)
    82        
     82
    8383        for src in sys.argv[5:]:
    8484                basename = os.path.basename(src)
    8585                plainname = os.path.splitext(basename)[0]
    8686                symbol = basename.replace(".", "_")
    87                
     87
    8888                print("%s -> %s" % (src, symbol))
    89                
     89
    9090                src_in = open(src, "rb")
    9191                src_data = src_in.read()
    9292                src_in.close()
    93                
     93
    9494                length = len(src_data)
    95                
     95
    9696                if compress:
    9797                        src_data = deflate(src_data)
     
    101101                else:
    102102                        src_fname = src
    103                
     103
    104104                if sys.version_info < (3,):
    105105                        src_data = bytearray(src_data)
    106                
     106
    107107                length_out = len(src_data)
    108                
     108
    109109                header_ctx.append("extern uint8_t %s[];" % symbol)
    110110                header_ctx.append("extern size_t %s_size;" % symbol)
    111                
     111
    112112                data_ctx.append(".globl %s" % symbol)
    113113                data_ctx.append(".balign 8")
     
    115115                data_ctx.append("%s:" % symbol)
    116116                data_ctx.append("\t.incbin \"%s\"\n" % src_fname)
    117                
     117
    118118                desc_field = []
    119119                desc_field.append("\t{")
     
    122122                desc_field.append("\t\t.size = %u," % length_out)
    123123                desc_field.append("\t\t.inflated = %u," % length)
    124                
     124
    125125                if compress:
    126126                        desc_field.append("\t\t.compressed = true")
    127127                else:
    128128                        desc_field.append("\t\t.compressed = false")
    129                
     129
    130130                desc_field.append("\t}")
    131                
     131
    132132                desc_ctx.append("\n".join(desc_field))
    133                
     133
    134134                size_ctx.append("size_t %s_size = %u;" % (symbol, length_out))
    135                
     135
    136136                src_cnt += 1
    137        
     137
    138138        data = ''
    139139        data += '/***************************************\n'
     
    160160        zipinfo = zipfile.ZipInfo("%s.h" % dest, timestamp)
    161161        archive.writestr(zipinfo, data)
    162        
     162
    163163        data = ''
    164164        data += '/***************************************\n'
     
    172172        zipinfo = zipfile.ZipInfo("%s.s" % dest, timestamp)
    173173        archive.writestr(zipinfo, data)
    174        
     174
    175175        data = ''
    176176        data += '/***************************************\n'
     
    187187        zipinfo = zipfile.ZipInfo("%s_desc.c" % dest, timestamp)
    188188        archive.writestr(zipinfo, data)
    189        
     189
    190190        archive.close()
    191191
  • tools/mkext2.py

    r3061bc1 r8565a42  
    7777        uint32_t rev_major            /* Major revision level */
    7878        padding[4] /* default reserved uid and gid */
    79        
     79
    8080        /* Following is for ext2 revision 1 only */
    8181        uint32_t first_inode
     
    130130        def __init__(self, filename, block_groups, blocks_per_group, inodes_per_group, block_size, inode_size, reserved_inode_count):
    131131                "Initialize the filesystem writer"
    132                
     132
    133133                outf = open(filename, "w+b")
    134134                # Set the correct size of the image, so that we can read arbitrary position
     
    172172                lpf_dir.add(self.root_inode.as_dirent('..'))
    173173                lpf_dir.finish()
    174        
     174
    175175        def init_gdt(self):
    176176                "Initialize block group descriptor table"
    177                
     177
    178178                self.superblock_positions = []
    179179                self.gdt = []
     
    202202                        gde.directory_inode_count = 0
    203203                        self.gdt.append(gde)
    204        
     204
    205205        def mark_block_cb(self, block):
    206206                "Called after a block has been allocated"
    207                
     207
    208208                self.gdt[block // self.blocks_per_group].free_block_count -= 1
    209        
     209
    210210        def mark_inode_cb(self, index, directory=False):
    211211                "Called after an inode has been allocated"
    212                
     212
    213213                index -= 1
    214214                gde = self.gdt[index // self.inodes_per_group]
     
    216216                if directory:
    217217                        gde.directory_inode_count += 1
    218        
     218
    219219        def seek_to_block(self, block, offset=0):
    220220                "Seek to offset bytes after the start of the given block"
    221                
     221
    222222                if offset < 0 or offset > self.block_size:
    223223                        raise Exception("Invalid in-block offset")
    224224                self.outf.seek(block * self.block_size + offset)
    225        
     225
    226226        def seek_to_inode(self, index):
    227227                "Seek to the start of the inode structure for the inode number index"
    228                
     228
    229229                index -= 1
    230230                if index < 0:
     
    235235                block = base_block + (offset // self.block_size)
    236236                self.seek_to_block(block, offset % self.block_size)
    237        
     237
    238238        def subtree_add(self, inode, parent_inode, dirpath, is_root=False):
    239239                "Recursively add files to the filesystem"
    240                
     240
    241241                dir_writer = DirWriter(inode)
    242242                dir_writer.add(inode.as_dirent('.'))
    243243                dir_writer.add(parent_inode.as_dirent('..'))
    244                
     244
    245245                if is_root:
    246246                        dir_writer.add(self.lost_plus_found.as_dirent('lost+found'))
     
    255255                                child_inode = Inode(self, newidx, Inode.TYPE_DIR)
    256256                                self.subtree_add(child_inode, inode, item.path)
    257                
     257
    258258                        dir_writer.add(child_inode.as_dirent(item.name))
    259259                        self.write_inode(child_inode)
    260260
    261261                dir_writer.finish()
    262        
     262
    263263        def write_inode(self, inode):
    264264                "Write inode information into the inode table"
    265                
     265
    266266                self.seek_to_inode(inode.index)
    267267                self.outf.write(inode.pack())
     
    269269        def write_gdt(self):
    270270                "Write group descriptor table at the current file position"
    271                
     271
    272272                for gde in self.gdt:
    273273                        data = bytes(gde.pack())
    274274                        self.outf.write(data)
    275275                        self.outf.seek(GDE_SIZE-len(data), os.SEEK_CUR)
    276        
     276
    277277        def write_superblock(self, block_group):
    278278                "Write superblock at the current position"
    279                
     279
    280280                sb = xstruct.create(STRUCT_SUPERBLOCK)
    281281                sb.total_inode_count = self.total_inode_count
     
    312312                sb.volume_name = 'HelenOS rdimage\0'
    313313                self.outf.write(bytes(sb.pack()))
    314        
     314
    315315        def write_all_metadata(self):
    316316                "Write superblocks, block group tables, block and inode bitmaps"
    317                
     317
    318318                bbpg = self.blocks_per_group // 8
    319319                bipg = self.inodes_per_group // 8
    320320                def window(arr, index, size):
    321321                        return arr[index * size:(index + 1) * size]
    322                
     322
    323323                for bg_index in xrange(len(self.gdt)):
    324324                        sbpos = self.superblock_positions[bg_index]
    325325                        sbblock = (sbpos + 1023) // self.block_size
    326326                        gde = self.gdt[bg_index]
    327                        
     327
    328328                        self.outf.seek(sbpos)
    329329                        self.write_superblock(bg_index)
    330                        
     330
    331331                        self.seek_to_block(sbblock+1)
    332332                        self.write_gdt()
    333                        
     333
    334334                        self.seek_to_block(gde.block_bitmap_block)
    335335                        self.outf.write(window(self.block_allocator.bitmap, bg_index, bbpg))
    336                        
     336
    337337                        self.seek_to_block(gde.inode_bitmap_block)
    338338                        self.outf.write(window(self.inode_allocator.bitmap, bg_index, bipg))
    339        
     339
    340340        def close(self):
    341341                "Write all remaining data to the filesystem and close the file"
    342                
     342
    343343                self.write_inode(self.root_inode)
    344344                self.write_inode(self.lost_plus_found)
     
    354354                self.bitmap = array.array('B', [0] * (count // 8))
    355355                self.mark_cb = None
    356        
     356
    357357        def __contains__(self, item):
    358358                "Check if the item is already used"
    359                
     359
    360360                bitidx = item - self.base
    361361                return get_bit(self.bitmap[bitidx // 8], bitidx % 8)
    362        
     362
    363363        def alloc(self, **options):
    364364                "Allocate a new item"
    365                
     365
    366366                while self.nextidx < self.count and (self.base + self.nextidx) in self:
    367367                        self.nextidx += 1
     
    372372                self.mark_used(item, **options)
    373373                return item
    374        
     374
    375375        def mark_used(self, item, **options):
    376376                "Mark the specified item as used"
    377                
     377
    378378                bitidx = item - self.base
    379379                if item in self:
     
    384384                if self.mark_cb:
    385385                        self.mark_cb(item, **options)
    386        
     386
    387387        def mark_used_all(self, items, **options):
    388388                "Mark all specified items as used"
    389                
     389
    390390                for item in items:
    391391                        self.mark_used(item, **options)
     
    395395        TYPE_DIR = 2
    396396        TYPE2MODE = {TYPE_FILE: 8, TYPE_DIR: 4}
    397        
     397
    398398        def __init__(self, fs, index, typ):
    399399                self.fs = fs
     
    406406                self.type = typ
    407407                self.refcount = 0
    408        
     408
    409409        def as_dirent(self, name):
    410410                "Return a DirEntry corresponding to this inode"
    411411                self.refcount += 1
    412412                return DirEntry(name, self.index, self.type)
    413        
     413
    414414        def new_block(self, data=True):
    415415                "Get a new block index from allocator and count it here as belonging to the file"
    416                
     416
    417417                block = self.fs.block_allocator.alloc()
    418418                self.blocks += 1
    419419                return block
    420        
     420
    421421        def get_or_add_block(self, block):
    422422                "Get or add a real block to the file"
    423                
     423
    424424                if block < 12:
    425425                        return self.get_or_add_block_direct(block)
    426426                return self.get_or_add_block_indirect(block)
    427        
     427
    428428        def get_or_add_block_direct(self, block):
    429429                "Get or add a real block to the file (direct blocks)"
    430                
     430
    431431                if self.direct[block] == None:
    432432                        self.direct[block] = self.new_block()
    433433                return self.direct[block]
    434        
     434
    435435        def get_or_add_block_indirect(self, block):
    436436                "Get or add a real block to the file (indirect blocks)"
    437                
     437
    438438                # Determine the indirection level for the desired block
    439439                level = None
     
    444444
    445445                assert level != None
    446        
     446
    447447                # Compute offsets for the topmost level
    448448                block_offset_in_level = block - self.fs.indirect_limits[level-1];
     
    452452                current_block.block_id = self.indirect[level-1]
    453453                offset_in_block = block_offset_in_level // self.fs.indirect_blocks_per_level[level-1]
    454        
     454
    455455                # Navigate through other levels
    456456                while level > 0:
    457457                        assert offset_in_block < self.fs.block_ids_per_block
    458                        
     458
    459459                        level -= 1
    460                        
     460
    461461                        self.fs.seek_to_block(current_block.block_id, offset_in_block*4)
    462462                        current_block.unpack(self.fs.outf.read(4))
    463                        
     463
    464464                        if current_block.block_id == 0:
    465465                                # The block does not exist, so alloc one and write it there
     
    467467                                current_block.block_id = self.new_block(data=(level==0))
    468468                                self.fs.outf.write(current_block.pack())
    469                
     469
    470470                        # If we are on the last level, break here as
    471471                        # there is no next level to visit
    472472                        if level == 0:
    473473                                break
    474                
     474
    475475                        # Visit the next level
    476476                        block_offset_in_level %= self.fs.indirect_blocks_per_level[level];
     
    478478
    479479                return current_block.block_id
    480        
     480
    481481        def do_seek(self):
    482482                "Perform a seek to the position indicated by self.pos"
    483                
     483
    484484                block = self.pos // self.fs.block_size
    485485                real_block = self.get_or_add_block(block)
    486486                offset = self.pos % self.fs.block_size
    487487                self.fs.seek_to_block(real_block, offset)
    488                
     488
    489489        def write(self, data):
    490490                "Write a piece of data (arbitrarily long) as the contents of the inode"
    491                
     491
    492492                data_pos = 0
    493493                while data_pos < len(data):
     
    499499                        data_pos += bytes_to_write
    500500                        self.size = max(self.pos, self.size)
    501        
     501
    502502        def align_size_to_block(self):
    503503                "Align the size of the inode up to block size"
    504                
     504
    505505                self.size = align_up(self.size, self.fs.block_size)
    506        
     506
    507507        def align_pos(self, bytes):
    508508                "Align the current position up to bytes boundary"
    509                
     509
    510510                self.pos = align_up(self.pos, bytes)
    511        
     511
    512512        def set_pos(self, pos):
    513513                "Set the current position"
    514                
     514
    515515                self.pos = pos
    516        
     516
    517517        def pack(self):
    518518                "Pack the inode structure and return the result"
    519                
     519
    520520                data = xstruct.create(STRUCT_INODE)
    521521                data.mode = (Inode.TYPE2MODE[self.type] << 12)
     
    546546                data.group_id_high = 0
    547547                return data.pack()
    548                
     548
    549549class DirEntry:
    550550        "Represents a linked list directory entry"
    551        
     551
    552552        def __init__(self, name, inode, typ):
    553553                self.name = name.encode('UTF-8')
     
    555555                self.skip = None
    556556                self.type = typ
    557        
     557
    558558        def size(self):
    559559                "Return size of the entry in bytes"
    560                
     560
    561561                return align_up(8 + len(self.name)+1, 4)
    562        
     562
    563563        def write(self, inode):
    564564                "Write the directory entry into the inode"
    565                
     565
    566566                head = xstruct.create(STRUCT_DIR_ENTRY_HEAD)
    567567                head.inode = self.inode
     
    575575class DirWriter:
    576576        "Manages writing directory entries into an inode (alignment, etc.)"
    577        
     577
    578578        def __init__(self, inode):
    579579                self.pos = 0
     
    581581                self.prev_entry = None
    582582                self.prev_pos = None
    583        
     583
    584584        def prev_write(self):
    585585                "Write a previously remembered entry"
    586                
     586
    587587                if self.prev_entry:
    588588                        self.prev_entry.skip = self.pos - self.prev_pos
     
    590590                                self.prev_entry.write(self.inode)
    591591                                self.inode.set_pos(self.pos)
    592        
     592
    593593        def add(self, entry):
    594594                "Add a directory entry to the directory"
    595                
     595
    596596                size = entry.size()
    597597                block_size = self.inode.fs.block_size
     
    602602                self.prev_pos = self.pos
    603603                self.pos += size
    604        
     604
    605605        def finish(self):
    606606                "Write the last entry and finish writing the directory contents"
    607                
     607
    608608                if not self.inode:
    609609                        return
     
    614614def subtree_stats(root, block_size):
    615615        "Recursively calculate statistics"
    616        
     616
    617617        blocks = 0
    618618        inodes = 1
    619619        dir_writer = DirWriter(None)
    620        
     620
    621621        for item in listdir_items(root):
    622622                inodes += 1
     
    627627                        blocks += subtree_blocks
    628628                        inodes += subtree_inodes
    629        
     629
    630630        dir_writer.finish()
    631631        blocks += count_up(dir_writer.pos, block_size)
     
    640640                usage(sys.argv[0])
    641641                return
    642        
     642
    643643        if (not sys.argv[1].isdigit()):
    644644                print("<EXTRA_BYTES> must be a number")
    645645                return
    646        
     646
    647647        extra_bytes = int(sys.argv[1])
    648        
     648
    649649        path = os.path.abspath(sys.argv[2])
    650650        if (not os.path.isdir(path)):
    651651                print("<PATH> must be a directory")
    652652                return
    653        
     653
    654654        block_size = 4096
    655655        inode_size = 128
     
    657657        blocks_per_group = 1024
    658658        inodes_per_group = 512
    659        
     659
    660660        blocks, inodes = subtree_stats(path, block_size)
    661661        blocks += count_up(extra_bytes, block_size)
    662662        inodes += reserved_inode_count
    663        
     663
    664664        inodes_per_group = align_up(inodes_per_group, 8)
    665665        blocks_per_group = align_up(blocks_per_group, 8)
    666        
     666
    667667        inode_table_blocks_per_group = (inodes_per_group * inode_size) // block_size
    668668        inode_bitmap_blocks_per_group = count_up(inodes_per_group // 8, block_size)
     
    673673        free_blocks_per_group -= block_bitmap_blocks_per_group
    674674        free_blocks_per_group -= 10 # one for SB and some reserve for GDT
    675        
     675
    676676        block_groups = max(count_up(inodes, inodes_per_group), count_up(blocks, free_blocks_per_group))
    677        
     677
    678678        fs = Filesystem(sys.argv[3], block_groups, blocks_per_group, inodes_per_group,
    679679                                block_size, inode_size, reserved_inode_count)
    680        
     680
    681681        fs.subtree_add(fs.root_inode, fs.root_inode, path, is_root=True)
    682682        fs.close()
    683        
     683
    684684if __name__ == '__main__':
    685685        main()
  • tools/mkfat.py

    r3061bc1 r8565a42  
    4141def subtree_size(root, cluster_size, dirent_size):
    4242        "Recursive directory walk and calculate size"
    43        
     43
    4444        size = 0
    4545        files = 2
    46        
     46
    4747        for item in listdir_items(root):
    4848                if item.is_file:
     
    5252                        size += subtree_size(item.path, cluster_size, dirent_size)
    5353                        files += 1
    54        
     54
    5555        return size + align_up(files * dirent_size, cluster_size)
    5656
    5757def root_entries(root):
    5858        "Return number of root directory entries"
    59        
     59
    6060        return len(os.listdir(root))
    6161
    6262def write_file(item, outf, cluster_size, data_start, fat, reserved_clusters):
    6363        "Store the contents of a file"
    64        
     64
    6565        prev = -1
    6666        first = 0
    67        
     67
    6868        for data in chunks(item, cluster_size):
    6969                empty_cluster = fat.index(0)
    7070                fat[empty_cluster] = 0xffff
    71                
     71
    7272                if (prev != -1):
    7373                        fat[prev] = empty_cluster
    7474                else:
    7575                        first = empty_cluster
    76                
     76
    7777                prev = empty_cluster
    78                
     78
    7979                outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size)
    8080                outf.write(data)
    81        
     81
    8282        return first, item.size
    8383
    8484def write_directory(directory, outf, cluster_size, data_start, fat, reserved_clusters, dirent_size, empty_cluster):
    8585        "Store the contents of a directory"
    86        
     86
    8787        length = len(directory)
    8888        size = length * dirent_size
    8989        prev = -1
    9090        first = 0
    91        
     91
    9292        i = 0
    9393        rd = 0;
     
    9999                else:
    100100                        first = empty_cluster
    101                
     101
    102102                prev = empty_cluster
    103                
     103
    104104                data = bytes()
    105105                data_len = 0
     
    107107                        if (i == 0):
    108108                                directory[i].cluster = empty_cluster
    109                        
     109
    110110                        data += directory[i].pack()
    111111                        data_len += dirent_size
    112112                        i += 1
    113                
     113
    114114                outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size)
    115115                outf.write(data)
    116116                rd += len(data)
    117        
     117
    118118        return first, size
    119119
     
    188188def fat_lchars(name):
    189189        "Filter FAT legal characters"
    190        
     190
    191191        filtered_name = b''
    192192        filtered = False
    193        
     193
    194194        for char in name.encode('ascii', 'replace').upper():
    195195                if char in lchars:
     
    198198                        filtered_name += b'_'
    199199                        filtered = True
    200        
     200
    201201        return (filtered_name, filtered)
    202202
    203203def fat_name83(name, name83_list):
    204204        "Create a 8.3 name for the given name"
    205        
     205
    206206        ascii_name, lfn = fat_lchars(name)
    207207        # Splitting works only on strings, not on bytes
    208208        ascii_parts = ascii_name.decode('utf8').split('.')
    209        
     209
    210210        short_name = ''
    211211        short_ext = ''
    212        
     212
    213213        if len(ascii_name) > 11:
    214214                lfn = True
    215        
     215
    216216        if len(ascii_parts) > 0:
    217217                short_name = ascii_parts[0]
    218218                if len(short_name) > 8:
    219219                        lfn = True
    220        
     220
    221221        if len(ascii_parts) > 1:
    222222                short_ext = ascii_parts[-1]
    223223                if len(short_ext) > 3:
    224224                        lfn = True
    225        
     225
    226226        if len(ascii_parts) > 2:
    227227                lfn = True
    228        
     228
    229229        if lfn == False:
    230230                name83_list.append(short_name + '.' + short_ext)
    231231                return (short_name.ljust(8)[0:8], short_ext.ljust(3)[0:3], False)
    232        
     232
    233233        # For filenames with multiple extensions, we treat the last one
    234234        # as the actual extension. The rest of the filename is stripped
     
    236236        for part in ascii_parts[1:-1]:
    237237                short_name += part
    238        
     238
    239239        for number in range(1, 999999):
    240240                number_str = ('~' + str(number)).upper()
    241                
     241
    242242                if len(short_name) + len(number_str) > 8:
    243243                        short_name = short_name[0:8 - len(number_str)]
    244                
     244
    245245                short_name += number_str;
    246                
     246
    247247                if not (short_name + '.' + short_ext) in name83_list:
    248248                        break
    249        
     249
    250250        name83_list.append(short_name + '.' + short_ext)
    251251        return (short_name.ljust(8)[0:8], short_ext.ljust(3)[0:3], True)
     
    253253def create_lfn_dirent(name, seq, checksum):
    254254        "Create LFN directory entry"
    255        
     255
    256256        entry = xstruct.create(LFN_DIR_ENTRY)
    257257        name_rest = name[26:]
    258        
     258
    259259        if len(name_rest) > 0:
    260260                entry.seq = seq
    261261        else:
    262262                entry.seq = seq | 0x40
    263        
     263
    264264        entry.name1 = name[0:10]
    265265        entry.name2 = name[10:22]
    266266        entry.name3 = name[22:26]
    267        
     267
    268268        entry.attr = 0x0F
    269269        entry.rec_type = 0
    270270        entry.checksum = checksum
    271271        entry.cluster = 0
    272        
     272
    273273        return (entry, name_rest)
    274274
    275275def lfn_checksum(name):
    276276        "Calculate LFN checksum"
    277        
     277
    278278        checksum = 0
    279279        for i in range(0, 11):
    280280                checksum = (((checksum & 1) << 7) + (checksum >> 1) + ord(name[i])) & 0xFF
    281        
     281
    282282        return checksum
    283283
    284284def create_dirent(name, name83_list, directory, cluster, size):
    285285        short_name, short_ext, lfn = fat_name83(name, name83_list)
    286        
     286
    287287        dir_entry = xstruct.create(DIR_ENTRY)
    288        
     288
    289289        dir_entry.name = short_name
    290290        dir_entry.ext = short_ext
    291        
     291
    292292        if (directory):
    293293                dir_entry.attr = 0x30
    294294        else:
    295295                dir_entry.attr = 0x20
    296        
     296
    297297        dir_entry.lcase = 0x18
    298298        dir_entry.ctime_fine = 0 # FIXME
     
    303303        dir_entry.mdate = 0 # FIXME
    304304        dir_entry.cluster = cluster
    305        
     305
    306306        if (directory):
    307307                dir_entry.size = 0
    308308        else:
    309309                dir_entry.size = size
    310        
     310
    311311        if not lfn:
    312312                return [dir_entry]
    313        
     313
    314314        long_name = name.encode('utf_16_le')
    315315        entries = [dir_entry]
    316        
     316
    317317        seq = 1
    318318        checksum = lfn_checksum(dir_entry.name + dir_entry.ext)
    319        
     319
    320320        while len(long_name) > 0:
    321321                long_entry, long_name = create_lfn_dirent(long_name, seq, checksum)
    322322                entries.append(long_entry)
    323323                seq += 1
    324        
     324
    325325        entries.reverse()
    326326        return entries
     
    328328def create_dot_dirent(empty_cluster):
    329329        dir_entry = xstruct.create(DOT_DIR_ENTRY)
    330        
     330
    331331        dir_entry.signature = 0x2e
    332332        dir_entry.name = b'       '
    333333        dir_entry.ext = b'   '
    334334        dir_entry.attr = 0x10
    335        
     335
    336336        dir_entry.ctime_fine = 0 # FIXME
    337337        dir_entry.ctime = 0 # FIXME
     
    342342        dir_entry.cluster = empty_cluster
    343343        dir_entry.size = 0
    344        
     344
    345345        return dir_entry
    346346
    347347def create_dotdot_dirent(parent_cluster):
    348348        dir_entry = xstruct.create(DOTDOT_DIR_ENTRY)
    349        
     349
    350350        dir_entry.signature = [0x2e, 0x2e]
    351351        dir_entry.name = b'      '
    352352        dir_entry.ext = b'   '
    353353        dir_entry.attr = 0x10
    354        
     354
    355355        dir_entry.ctime_fine = 0 # FIXME
    356356        dir_entry.ctime = 0 # FIXME
     
    361361        dir_entry.cluster = parent_cluster
    362362        dir_entry.size = 0
    363        
     363
    364364        return dir_entry
    365365
    366366def recursion(head, root, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, parent_cluster):
    367367        "Recursive directory walk"
    368        
     368
    369369        directory = []
    370370        name83_list = []
    371        
     371
    372372        if not head:
    373373                # Directory cluster preallocation
    374374                empty_cluster = fat.index(0)
    375375                fat[empty_cluster] = 0xFFFF
    376                
     376
    377377                directory.append(create_dot_dirent(empty_cluster))
    378378                directory.append(create_dotdot_dirent(parent_cluster))
    379379        else:
    380380                empty_cluster = 0
    381        
     381
    382382        for item in listdir_items(root):
    383383                if item.is_file:
     
    387387                        rv = recursion(False, item.path, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, empty_cluster)
    388388                        directory.extend(create_dirent(item.name, name83_list, True, rv[0], rv[1]))
    389        
     389
    390390        if head:
    391391                outf.seek(root_start)
     
    410410        uint32_t hidden            /* hidden sectors */
    411411        uint32_t sectors_big       /* total number of sectors (if sectors == 0) */
    412        
     412
    413413        /* Extended BIOS Parameter Block */
    414414        uint8_t drive              /* physical drive number */
     
    438438                usage(sys.argv[0])
    439439                return
    440        
     440
    441441        if (not sys.argv[1].isdigit()):
    442442                print("<EXTRA_BYTES> must be a number")
    443443                return
    444        
     444
    445445        extra_bytes = int(sys.argv[1])
    446        
     446
    447447        path = os.path.abspath(sys.argv[2])
    448448        if (not os.path.isdir(path)):
    449449                print("<PATH> must be a directory")
    450450                return
    451        
     451
    452452        fat16_clusters = 4096
    453        
     453
    454454        sector_size = 512
    455455        cluster_size = 4096
     
    458458        fat_count = 2
    459459        reserved_clusters = 2
    460        
     460
    461461        # Make sure the filesystem is large enough for FAT16
    462462        size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes
     
    467467                else:
    468468                        size = fat16_clusters * cluster_size + reserved_clusters * cluster_size
    469        
     469
    470470        root_size = align_up(root_entries(path) * dirent_size, cluster_size)
    471        
     471
    472472        fat_size = align_up(align_up(size, cluster_size) // cluster_size * fatent_size, sector_size)
    473        
     473
    474474        sectors = (cluster_size + fat_count * fat_size + root_size + size) // sector_size
    475475        root_start = cluster_size + fat_count * fat_size
    476476        data_start = root_start + root_size
    477        
     477
    478478        outf = open(sys.argv[3], "wb")
    479        
     479
    480480        boot_sector = xstruct.create(BOOT_SECTOR)
    481481        boot_sector.jmp = [0xEB, 0x3C, 0x90]
     
    499499        else:
    500500                boot_sector.sectors_big = 0
    501        
     501
    502502        boot_sector.drive = 0x80
    503503        boot_sector.extboot_signature = 0x29
     
    506506        boot_sector.fstype = b'FAT16   '
    507507        boot_sector.boot_signature = [0x55, 0xAA]
    508        
     508
    509509        outf.write(boot_sector.pack())
    510        
     510
    511511        empty_sector = xstruct.create(EMPTY_SECTOR)
    512        
     512
    513513        # Reserved sectors
    514514        for i in range(1, cluster_size // sector_size):
    515515                outf.write(empty_sector.pack())
    516        
     516
    517517        # FAT tables
    518518        for i in range(0, fat_count):
    519519                for j in range(0, fat_size // sector_size):
    520520                        outf.write(empty_sector.pack())
    521        
     521
    522522        # Root directory
    523523        for i in range(0, root_size // sector_size):
    524524                outf.write(empty_sector.pack())
    525        
     525
    526526        # Data
    527527        for i in range(0, size // sector_size):
    528528                outf.write(empty_sector.pack())
    529        
     529
    530530        fat = array.array('L', [0] * (fat_size // fatent_size))
    531531        fat[0] = 0xfff8
    532532        fat[1] = 0xffff
    533        
     533
    534534        recursion(True, path, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, 0)
    535        
     535
    536536        # Store FAT
    537537        fat_entry = xstruct.create(FAT_ENTRY)
     
    541541                        fat_entry.next = fat[j]
    542542                        outf.write(fat_entry.pack())
    543        
     543
    544544        outf.close()
    545545
  • tools/mktmpfs.py

    r3061bc1 r8565a42  
    6969def recursion(root, outf):
    7070        "Recursive directory walk"
    71        
     71
    7272        for item in listdir_items(root):
    7373                if item.is_file:
     
    7777                        dentry.fname = item.name.encode('ascii')
    7878                        dentry.flen = item.size
    79                        
     79
    8080                        outf.write(dentry.pack())
    81                        
     81
    8282                        for data in chunks(item, 4096):
    8383                                outf.write(data)
    84                
     84
    8585                elif item.is_dir:
    8686                        dentry = xstruct.create(DENTRY_DIRECTORY % len(item.name))
     
    8888                        dentry.fname_len = len(item.name)
    8989                        dentry.fname = item.name.encode('ascii')
    90                        
     90
    9191                        outf.write(dentry.pack())
    92                        
     92
    9393                        recursion(item.path, outf)
    94                        
     94
    9595                        dentry = xstruct.create(DENTRY_NONE)
    9696                        dentry.kind = TMPFS_NONE
    9797                        dentry.fname_len = 0
    98                        
     98
    9999                        outf.write(dentry.pack())
    100100
     
    103103                usage(sys.argv[0])
    104104                return
    105        
     105
    106106        path = os.path.abspath(sys.argv[1])
    107107        if (not os.path.isdir(path)):
    108108                print("<PATH> must be a directory")
    109109                return
    110        
     110
    111111        outf = open(sys.argv[2], "wb")
    112        
     112
    113113        header = xstruct.create(HEADER)
    114114        header.tag = b"TMPFS"
    115        
     115
    116116        outf.write(header.pack())
    117        
     117
    118118        recursion(path, outf)
    119        
     119
    120120        dentry = xstruct.create(DENTRY_NONE)
    121121        dentry.kind = TMPFS_NONE
    122122        dentry.fname_len = 0
    123        
     123
    124124        outf.write(dentry.pack())
    125        
     125
    126126        outf.close()
    127        
     127
    128128if __name__ == '__main__':
    129129        main()
  • tools/toolchain-binutils-2.23.1.patch

    r3061bc1 r8565a42  
    127127   ia64-*-hpux*)                                fmt=elf em=hpux ;;
    128128   ia64-*-netbsd*)                      fmt=elf em=nbsd ;;
    129  
     129
    130130@@ -304,7 +305,7 @@
    131131   mips-*-irix*)                                fmt=ecoff em=irix ;;
  • tools/toolchain.sh

    r3061bc1 r8565a42  
    8585        HEADER="$2"
    8686        BODY="$3"
    87        
     87
    8888        FNAME="/tmp/conftest-$$"
    89        
     89
    9090        echo "#include ${HEADER}" > "${FNAME}.c"
    9191        echo >> "${FNAME}.c"
     
    9595        echo "  return 0;" >> "${FNAME}.c"
    9696        echo "}" >> "${FNAME}.c"
    97        
     97
    9898        cc $CFLAGS -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
    9999        RC="$?"
    100        
     100
    101101        if [ "$RC" -ne "0" ] ; then
    102102                if [ "${DEPENDENCY}" == "isl" ]; then
    103103                        BUILD_ISL=true
    104                        
     104
    105105                        echo " isl not found. Will be downloaded and built with GCC."
    106106                else
     
    134134                echo
    135135                echo "Script failed: $2"
    136                
     136
    137137                exit 1
    138138        fi
     
    142142        FILE="$1"
    143143        SUM="$2"
    144        
     144
    145145        COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
    146146        if [ "${SUM}" != "${COMPUTED}" ] ; then
    147147                echo
    148148                echo "Checksum of ${FILE} does not match."
    149                
     149
    150150                exit 2
    151151        fi
     
    193193        echo "feature that is not fully supported."
    194194        echo
    195        
     195
    196196        exit 3
    197197}
     
    203203show_countdown() {
    204204        TM="$1"
    205        
     205
    206206        if [ "${TM}" -eq 0 ] ; then
    207207                echo
    208208                return 0
    209209        fi
    210        
     210
    211211        echo -n "${TM} "
    212212        change_title "${TM}"
    213213        sleep 1
    214        
     214
    215215        TM="`expr "${TM}" - 1`"
    216216        show_countdown "${TM}"
     
    243243        FILE="$2"
    244244        CHECKSUM="$3"
    245        
     245
    246246        if [ ! -f "${FILE}" ] ; then
    247247                change_title "Downloading ${FILE}"
    248248                wget -c "${SOURCE}${FILE}" -O "${FILE}".part
    249249                check_error $? "Error downloading ${FILE}."
    250                
     250
    251251                mv "${FILE}".part "${FILE}"
    252252        fi
    253        
     253
    254254        check_md5 "${FILE}" "${CHECKSUM}"
    255255}
     
    257257source_check() {
    258258        FILE="$1"
    259        
     259
    260260        if [ ! -f "${FILE}" ] ; then
    261261                echo
    262262                echo "File ${FILE} not found."
    263                
     263
    264264                exit 4
    265265        fi
     
    268268cleanup_dir() {
    269269        DIR="$1"
    270        
     270
    271271        if [ -d "${DIR}" ] ; then
    272272                change_title "Removing ${DIR}"
     
    279279        DIR="$1"
    280280        DESC="$2"
    281        
     281
    282282        change_title "Creating ${DESC}"
    283283        echo ">>> Creating ${DESC}"
    284        
     284
    285285        mkdir -p "${DIR}"
    286286        test -d "${DIR}"
     
    292292        BASE="$2"
    293293        ORIGINAL="`pwd`"
    294        
     294
    295295        mkdir -p "${OUTSIDE}"
    296        
     296
    297297        cd "${OUTSIDE}"
    298298        check_error $? "Unable to change directory to ${OUTSIDE}."
    299299        ABS_OUTSIDE="`pwd`"
    300        
     300
    301301        cd "${BASE}"
    302302        check_error $? "Unable to change directory to ${BASE}."
    303303        ABS_BASE="`pwd`"
    304        
     304
    305305        cd "${ORIGINAL}"
    306306        check_error $? "Unable to change directory to ${ORIGINAL}."
    307        
     307
    308308        BASE_LEN="${#ABS_BASE}"
    309309        OUTSIDE_TRIM="${ABS_OUTSIDE:0:${BASE_LEN}}"
    310        
     310
    311311        if [ "${OUTSIDE_TRIM}" == "${ABS_BASE}" ] ; then
    312312                echo
    313313                echo "CROSS_PREFIX cannot reside within the working directory."
    314                
     314
    315315                exit 5
    316316        fi
     
    320320        FILE="$1"
    321321        DESC="$2"
    322        
     322
    323323        change_title "Unpacking ${DESC}"
    324324        echo " >>> Unpacking ${DESC}"
    325        
     325
    326326        case "${FILE}" in
    327327                *.gz)
     
    345345        PATCH_STRIP="$2"
    346346        DESC="$3"
    347        
     347
    348348        change_title "Patching ${DESC}"
    349349        echo " >>> Patching ${DESC} with ${PATCH_FILE}"
    350        
     350
    351351        patch -t "-p${PATCH_STRIP}" <"$PATCH_FILE"
    352352        check_error $? "Error patching ${DESC}."
     
    357357        check_dependecies
    358358        show_countdown 10
    359        
     359
    360360        BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
    361361        GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
    362362        GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
    363363        ISL_SOURCE="http://isl.gforge.inria.fr/"
    364        
     364
    365365        download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "9e8340c96626b469a603c15c9d843727"
    366366        download_fetch "${GCC_SOURCE}" "${GCC}" "6bf56a2bca9dac9dbbf8e8d1036964a8"
    367367        download_fetch "${GDB_SOURCE}" "${GDB}" "06c8f40521ed65fe36ebc2be29b56942"
    368        
     368
    369369        if $BUILD_ISL ; then
    370370                download_fetch "${ISL_SOURCE}" "${ISL}" "11436d6b205e516635b666090b94ab32"
     
    426426build_target() {
    427427        PLATFORM="$1"
    428        
     428
    429429        # This sets the *_TARGET variables
    430430        set_target_from_platform "$PLATFORM"
     
    434434                TARGET="$LINUX_TARGET"
    435435        fi
    436        
     436
    437437        WORKDIR="${BASEDIR}/${TARGET}"
    438438        INSTALL_DIR="${WORKDIR}/PKG"
     
    442442        OBJDIR="${WORKDIR}/gcc-obj"
    443443        GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
    444        
     444
    445445        if [ -z "${CROSS_PREFIX}" ] ; then
    446446                CROSS_PREFIX="/usr/local/cross"
    447447        fi
    448        
     448
    449449        PREFIX="${CROSS_PREFIX}/${TARGET}"
    450        
     450
    451451        echo ">>> Downloading tarballs"
    452452        source_check "${BASEDIR}/${BINUTILS}"
     
    456456                source_check "${BASEDIR}/${ISL}"
    457457        fi
    458        
     458
    459459        echo ">>> Removing previous content"
    460460        cleanup_dir "${WORKDIR}"
    461        
     461
    462462        create_dir "${OBJDIR}" "GCC object directory"
    463        
     463
    464464        check_dirs "${PREFIX}" "${WORKDIR}"
    465        
     465
    466466        echo ">>> Unpacking tarballs"
    467467        cd "${WORKDIR}"
    468468        check_error $? "Change directory failed."
    469        
     469
    470470        unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
    471471        unpack_tarball "${BASEDIR}/${GCC}" "GCC"
     
    475475                mv "${ISLDIR}" "${GCCDIR}"/isl
    476476        fi
    477        
     477
    478478        echo ">>> Applying patches"
    479479        for p in $BINUTILS_PATCHES ; do
     
    486486                patch_sources "${SRCDIR}/${p}" 0 "GDB"
    487487        done
    488        
     488
    489489        echo ">>> Processing binutils (${PLATFORM})"
    490490        cd "${BINUTILSDIR}"
    491491        check_error $? "Change directory failed."
    492        
     492
    493493        change_title "binutils: configure (${PLATFORM})"
    494494        CFLAGS=-Wno-error ./configure \
     
    498498                --enable-deterministic-archives
    499499        check_error $? "Error configuring binutils."
    500        
     500
    501501        change_title "binutils: make (${PLATFORM})"
    502502        make all
    503503        check_error $? "Error compiling binutils."
    504        
     504
    505505        change_title "binutils: install (${PLATFORM})"
    506506        make install "DESTDIR=${INSTALL_DIR}"
    507507        check_error $? "Error installing binutils."
    508        
    509        
     508
     509
    510510        echo ">>> Processing GCC (${PLATFORM})"
    511511        cd "${OBJDIR}"
    512512        check_error $? "Change directory failed."
    513        
     513
    514514        change_title "GCC: configure (${PLATFORM})"
    515515        PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${GCCDIR}/configure" \
     
    521521                --disable-shared --enable-lto --disable-werror
    522522        check_error $? "Error configuring GCC."
    523        
     523
    524524        change_title "GCC: make (${PLATFORM})"
    525525        PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc
    526526        check_error $? "Error compiling GCC."
    527        
     527
    528528        change_title "GCC: install (${PLATFORM})"
    529529        PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
    530530        check_error $? "Error installing GCC."
    531        
    532        
     531
     532
    533533        # No GDB support for RISC-V so far
    534534        if [ "$PLATFORM" != "riscv64" ] ; then
     
    536536                cd "${GDBDIR}"
    537537                check_error $? "Change directory failed."
    538                
     538
    539539                change_title "GDB: configure (${PLATFORM})"
    540540                PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" ./configure \
     
    543543                        --enable-werror=no --without-guile
    544544                check_error $? "Error configuring GDB."
    545                
     545
    546546                change_title "GDB: make (${PLATFORM})"
    547547                PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all
    548548                check_error $? "Error compiling GDB."
    549                
     549
    550550                change_title "GDB: make (${PLATFORM})"
    551551                PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install "DESTDIR=${INSTALL_DIR}"
    552552                check_error $? "Error installing GDB."
    553553        fi
    554        
     554
    555555        # Symlink clang and lld to the install path.
    556556        CLANG="`which clang 2> /dev/null || echo "/usr/bin/clang"`"
    557557        LLD="`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`"
    558        
     558
    559559        ln -s $CLANG "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-clang"
    560560        ln -s $LLD "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-ld.lld"
    561        
     561
    562562        if $REAL_INSTALL ; then
    563563                echo ">>> Moving to the destination directory."
     
    566566                mv "${INSTALL_DIR}/${PREFIX}" "${PREFIX}"
    567567        fi
    568        
     568
    569569        cd "${BASEDIR}"
    570570        check_error $? "Change directory failed."
    571        
     571
    572572        echo ">>> Cleaning up"
    573573        cleanup_dir "${WORKDIR}"
    574        
     574
    575575        echo
    576576        echo ">>> Cross-compiler for ${TARGET} installed."
     
    647647                build_target "arm32" &
    648648                wait
    649                
     649
    650650                build_target "ia32" &
    651651                build_target "ia64" &
    652652                wait
    653                
     653
    654654                build_target "mips32" &
    655655                build_target "mips32eb" &
    656656                wait
    657                
     657
    658658                build_target "mips64" &
    659659                build_target "ppc32" &
    660660                wait
    661                
     661
    662662                build_target "riscv64" &
    663663                build_target "ppc64" &
    664664                wait
    665                
     665
    666666                build_target "sparc64" &
    667667                wait
  • tools/travis.sh

    r3061bc1 r8565a42  
    119119elif [ "$1" = "install" ]; then
    120120    set -x
    121    
     121
    122122    # Install dependencies
    123123    sudo apt-get -qq update || exit 1
     
    133133elif [ "$1" = "run" ]; then
    134134    set -x
    135    
     135
    136136    # Expected output filename (bootable image)
    137137    H_OUTPUT_FILENAME=`h_get_arch_config $H_ARCH_CONFIG_OUTPUT_FILENAME`
     
    150150    fi
    151151
    152        
     152
    153153    # Build it
    154154    make "PROFILE=$H_ARCH" HANDS_OFF=y || exit 1
    155155    test -s "$H_OUTPUT_FILENAME" || exit 1
    156    
     156
    157157    echo
    158158    echo "HelenOS for $H_ARCH built okay."
     
    165165        echo "Repository used is $H_HARBOURS_REPOSITORY."
    166166        echo
    167        
     167
    168168        H_HELENOS_HOME=`pwd`
    169169        cd "$HOME" || exit 1
     
    181181                echo "machine =" `echo "$H_ARCH" | cut -d/ -f 2`
    182182            ) >hsct.conf || exit 1
    183            
     183
    184184            # "$HOME/helenos-harbours/hsct.sh" init "$H_HELENOS_HOME" "$H_ARCH" build >/dev/null 2>/dev/null || exit 1
    185            
     185
    186186            "$HOME/helenos-harbours/hsct.sh" update || exit 1
    187187
     
    196196                    tail -n 100 "run-$HARBOUR.log"
    197197                fi
    198                
     198
    199199            done
    200            
     200
    201201            if [ -n "$FAILED_HARBOURS" ]; then
    202202                echo
  • tools/xstruct.py

    r3061bc1 r8565a42  
    7272        def size(self):
    7373                return struct.calcsize(self._format_)
    74        
     74
    7575        def pack(self):
    7676                args = []
     
    9090                                args.append(value)
    9191                return struct.pack(self._format_, *args)
    92        
     92
    9393        def unpack(self, data):
    9494                values = struct.unpack(self._format_, data)
     
    100100def create(definition):
    101101        "Create structure object"
    102        
     102
    103103        tokens = definition.split(None)
    104        
     104
    105105        # Initial byte order tag
    106106        format = {
     
    111111        inst = Struct()
    112112        args = []
    113        
     113
    114114        # Member tags
    115115        comment = False
     
    120120                                comment = False
    121121                        continue
    122                
     122
    123123                if (token == "/*"):
    124124                        comment = True
    125125                        continue
    126                
     126
    127127                if (variable != None):
    128128                        subtokens = token.split("[")
    129                        
     129
    130130                        length = None
    131131                        if (len(subtokens) > 1):
    132132                                length = int(subtokens[1].split("]")[0])
    133133                                format += "%d" % length
    134                        
     134
    135135                        format += variable
    136                        
     136
    137137                        inst.__dict__[subtokens[0]] = None
    138138                        args.append((subtokens[0], variable, length))
    139                        
     139
    140140                        variable = None
    141141                        continue
    142                
     142
    143143                if (token[0:8] == "padding["):
    144144                        size = token[8:].split("]")[0]
    145145                        format += "%dx" % int(size)
    146146                        continue
    147                
     147
    148148                variable = {
    149149                        "char":     lambda: "s",
     
    152152                        "uint32_t": lambda: "L",
    153153                        "uint64_t": lambda: "Q",
    154                        
     154
    155155                        "int8_t":   lambda: "b",
    156156                        "int16_t":  lambda: "h",
     
    158158                        "int64_t":  lambda: "q"
    159159                }[token]()
    160        
     160
    161161        inst.__dict__['_format_'] = format
    162162        inst.__dict__['_args_'] = args
  • tools/xtui.py

    r3061bc1 r8565a42  
    3535def call_dlg(dlgcmd, *args, **kw):
    3636        "Wrapper for calling 'dialog' program"
    37        
     37
    3838        indesc, outdesc = os.pipe()
    3939        pid = os.fork()
     
    4141                os.dup2(outdesc, 2)
    4242                os.close(indesc)
    43                
     43
    4444                dlgargs = [dlgcmd]
    4545                for key, val in kw.items():
    4646                        dlgargs.append('--' + key)
    4747                        dlgargs.append(val)
    48                
     48
    4949                dlgargs += args
    5050                os.execlp(dlgcmd, *dlgargs)
    51        
     51
    5252        os.close(outdesc)
    53        
     53
    5454        try:
    5555                errout = os.fdopen(indesc, 'r')
     
    6161                os.system('reset')
    6262                raise
    63        
     63
    6464        if (not os.WIFEXITED(status)):
    6565                # Reset terminal
    6666                os.system('reset')
    6767                raise EOFError
    68        
     68
    6969        status = os.WEXITSTATUS(status)
    7070        if (status == 255):
    7171                raise EOFError
    72        
     72
    7373        return (status, data)
    7474
     
    7979except ImportError:
    8080        newt = False
    81        
     81
    8282        dlgcmd = os.environ.get('DIALOG', 'dialog')
    8383        if (call_dlg(dlgcmd, '--print-maxsize')[0] != 0):
     
    9191def width_fix(screen, width):
    9292        "Correct width to screen size"
    93        
     93
    9494        if (width + width_extra > screen.width):
    9595                width = screen.width - width_extra
    96        
     96
    9797        if (width <= 0):
    9898                width = screen.width
    99        
     99
    100100        return width
    101101
    102102def height_fix(screen, height):
    103103        "Correct height to screen size"
    104        
     104
    105105        if (height + height_extra > screen.height):
    106106                height = screen.height - height_extra
    107        
     107
    108108        if (height <= 0):
    109109                height = screen.height
    110        
     110
    111111        return height
    112112
    113113def screen_init():
    114114        "Initialize the screen"
    115        
     115
    116116        if (newt):
    117117                return snack.SnackScreen()
    118        
     118
    119119        return None
    120120
    121121def screen_done(screen):
    122122        "Cleanup the screen"
    123        
     123
    124124        if (newt):
    125125                screen.finish()
     
    127127def choice_window(screen, title, text, options, position):
    128128        "Create options menu"
    129        
     129
    130130        maxopt = 0
    131131        for option in options:
     
    133133                if (length > maxopt):
    134134                        maxopt = length
    135        
     135
    136136        width = maxopt
    137137        height = len(options)
    138        
     138
    139139        if (newt):
    140140                width = width_fix(screen, width + width_extra)
    141141                height = height_fix(screen, height)
    142                
     142
    143143                if (height > 3):
    144144                        large = True
    145145                else:
    146146                        large = False
    147                
     147
    148148                buttonbar = snack.ButtonBar(screen, ('Done', 'Cancel'))
    149149                textbox = snack.TextboxReflowed(width, text)
    150150                listbox = snack.Listbox(height, scroll = large, returnExit = 1)
    151                
     151
    152152                cnt = 0
    153153                for option in options:
    154154                        listbox.append(option, cnt)
    155155                        cnt += 1
    156                
     156
    157157                if (position != None):
    158158                        listbox.setCurrent(position)
    159                
     159
    160160                grid = snack.GridForm(screen, title, 1, 3)
    161161                grid.add(textbox, 0, 0)
    162162                grid.add(listbox, 0, 1, padding = (0, 1, 0, 1))
    163163                grid.add(buttonbar, 0, 2, growx = 1)
    164                
     164
    165165                retval = grid.runOnce()
    166                
     166
    167167                return (buttonbar.buttonPressed(retval), listbox.current())
    168168        elif (dialog):
    169169                if (width < 35):
    170170                        width = 35
    171                
     171
    172172                args = []
    173173                cnt = 0
     
    175175                        args.append(str(cnt + 1))
    176176                        args.append(option)
    177                        
     177
    178178                        cnt += 1
    179                
     179
    180180                kw = {}
    181181                if (position != None):
    182182                        kw['default-item'] = str(position + 1)
    183                
     183
    184184                status, data = call_dlg(dlgcmd, '--title', title, '--extra-button', '--extra-label', 'Done', '--menu', text, str(height + height_extra), str(width + width_extra), str(cnt), *args, **kw)
    185                
     185
    186186                if (status == 1):
    187187                        return ('cancel', None)
    188                
     188
    189189                try:
    190190                        choice = int(data) - 1
    191191                except ValueError:
    192192                        return ('cancel', None)
    193                
     193
    194194                if (status == 0):
    195195                        return (None, choice)
    196                
     196
    197197                return ('done', choice)
    198        
     198
    199199        sys.stdout.write("\n *** %s *** \n%s\n\n" % (title, text))
    200        
     200
    201201        maxcnt = len(str(len(options)))
    202202        cnt = 0
     
    204204                sys.stdout.write("%*s. %s\n" % (maxcnt, cnt + 1, option))
    205205                cnt += 1
    206        
     206
    207207        sys.stdout.write("\n%*s. Done\n" % (maxcnt, '0'))
    208208        sys.stdout.write("%*s. Quit\n\n" % (maxcnt, 'q'))
    209        
     209
    210210        while True:
    211211                if (position != None):
     
    217217                                sys.stdout.write("Selection[0]: ")
    218218                inp = sys.stdin.readline()
    219                
     219
    220220                if (not inp):
    221221                        raise EOFError
    222                
     222
    223223                if (not inp.strip()):
    224224                        if (position != None):
     
    229229                                else:
    230230                                        inp = '0'
    231                
     231
    232232                if (inp.strip() == 'q'):
    233233                        return ('cancel', None)
    234                
     234
    235235                try:
    236236                        choice = int(inp.strip())
    237237                except ValueError:
    238238                        continue
    239                
     239
    240240                if (choice == 0):
    241241                        return ('done', 0)
    242                
     242
    243243                if (choice < 1) or (choice > len(options)):
    244244                        continue
    245                
     245
    246246                return (None, choice - 1)
    247247
    248248def error_dialog(screen, title, msg):
    249249        "Print error dialog"
    250        
     250
    251251        width = len(msg)
    252        
     252
    253253        if (newt):
    254254                width = width_fix(screen, width)
    255                
     255
    256256                buttonbar = snack.ButtonBar(screen, ['Ok'])
    257257                textbox = snack.TextboxReflowed(width, msg)
    258                
     258
    259259                grid = snack.GridForm(screen, title, 1, 2)
    260260                grid.add(textbox, 0, 0, padding = (0, 0, 0, 1))
Note: See TracChangeset for help on using the changeset viewer.