Changeset a35b458 in mainline for tools/checkers


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

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

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

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

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

Location:
tools/checkers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tools/checkers/clang.py

    r3061bc1 ra35b458  
    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 ra35b458  
    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 ra35b458  
    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 ra35b458  
    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")
Note: See TracChangeset for help on using the changeset viewer.