Changeset a35b458 in mainline for tools/checkers/vcc.py


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

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

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

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/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.