Changeset f9798ad in rtems-libbsd


Ignore:
Timestamp:
05/30/16 23:49:31 (8 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
5, 5-freebsd-12, 6-freebsd-12, freebsd-9.3, master
Children:
ab5cd63
Parents:
70d52b8
Message:

Add a stats report command.

The report shows the level of changes we have made to the FreeBSD code.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • builder.py

    r70d52b8 rf9798ad  
    5656filesProcessedCount = 0
    5757filesProcessed = []
     58filesTotal = 0
     59filesTotalLines = 0
     60filesTotalInserts = 0
     61filesTotalDeletes = 0
     62diffDetails = { }
    5863
    5964verboseInfo = 1
     
    6570    return verboseLevel >= level
    6671
    67 def changedFileSummary():
     72def changedFileSummary(statsReport = False):
     73
     74    global filesTotal, filesTotalLines, filesTotalInserts, filesTotalDeletes
     75
    6876    if isDiffMode == False:
    69         print('%d file(s) were changed:' % (filesProcessedCount))
    7077        if verbose():
     78            print('%d file(s) were changed:' % (filesProcessedCount))
    7179            for f in sorted(filesProcessed):
    7280                print(' %s' % (f))
     81        else:
     82            print('%d file(s) were changed.' % (filesProcessedCount))
     83    if statsReport:
     84        print('Stats Report:')
     85        transparent = filesTotal - len(diffDetails)
     86        changes = filesTotalInserts + filesTotalDeletes
     87        opacity = (float(changes) / (filesTotalLines + changes)) * 100.0
     88        print(' Total File(s):%d  Unchanged:%d (%.1f%%)  Changed:%d' \
     89              '   Opacity:%5.1f%% Lines:%d Edits:%d (+):%d (-):%d'  % \
     90              (filesTotal, transparent, (float(transparent) / filesTotal) * 100.0, len(diffDetails), \
     91               opacity, filesTotalLines, changes, filesTotalInserts, filesTotalDeletes))
     92        #
     93        # Sort by opacity.
     94        #
     95        ordered_diffs = sorted(diffDetails.items(), key = lambda diff: diff[1].opacity, reverse = True)
     96        for f in ordered_diffs:
     97            print('  %s' % (diffDetails[f[0]].status()))
    7398
    7499def readFile(name):
     
    105130    def __str__(self):
    106131        return self.msg
     132
     133#
     134# Diff Record
     135#
     136class diffRecord:
     137    def __init__(self, src, dst, orig, diff, inserts, deletes):
     138        self.src = src
     139        self.dst = dst
     140        self.orig = orig
     141        self.diff = diff
     142        self.lines = len(orig)
     143        self.inserts = inserts
     144        self.deletes = deletes
     145        self.changes = inserts + deletes
     146        self.opacity = (float(self.changes) / (self.lines + self.changes)) * 100.0
     147
     148    def __repr__(self):
     149        return self.src
     150
     151    def status(self):
     152        return 'opacity:%5.1f%% edits:%4d (+):%-4d (-):%-4d %s' % \
     153            (self.opacity, self.changes, self.inserts, self.deletes, self.src)
    107154
    108155#
     
    222269        sys.exit(2)
    223270
     271def diffSource(dstLines, srcLines, src, dst):
     272    global filesTotal, filesTotalLines, filesTotalInserts, filesTotalDeletes
     273    #
     274    # Diff, note there is no line termination on each string.  Expand the
     275    # generator to list because the generator is not reusable.
     276    #
     277    diff = list(difflib.unified_diff(dstLines,
     278                                     srcLines,
     279                                     fromfile = src,
     280                                     tofile = dst,
     281                                     n = 5,
     282                                     lineterm = ''))
     283    inserts = 0
     284    deletes = 0
     285    if len(diff) > 0:
     286        if src in diffDetails and \
     287           diffDetails[src].dst != dst and diffDetails[src].diff != diff:
     288            raise error('repeated diff of file different: src:%s dst:%s' % (src, dst))
     289        for l in diff:
     290            if l[0] == '-':
     291                deletes += 1
     292            elif l[0] == '+':
     293                inserts += 1
     294        diffDetails[src] = diffRecord(src, dst, srcLines, diff, inserts, deletes)
     295
     296    #
     297    # Count the total files, lines and the level of changes.
     298    #
     299    filesTotal += 1
     300    filesTotalLines += len(srcLines)
     301    filesTotalInserts += inserts
     302    filesTotalDeletes += deletes
     303
     304    return diff
     305
    224306#
    225307# Converters provide a way to alter the various types of code. The conversion
     
    277359
    278360        #
    279         # Diff, note there is no line termination on each string.  Expand the
    280         # generator to list because the generator is not reusable.
    281         #
    282         diff = list(difflib.unified_diff(dstLines,
    283                                          srcLines,
    284                                          fromfile = src,
    285                                          tofile = dst,
    286                                          n = 5,
    287                                          lineterm = ''))
     361        # Diff, note there is no line termination on each string.
     362        #
     363        diff = diffSource(dstLines, srcLines, src, dst)
    288364
    289365        #
  • freebsd-to-rtems.py

    r70d52b8 rf9798ad  
    4949isEarlyExit = False
    5050isOnlyBuildScripts = False
     51statsReport = False
    5152
    5253def usage():
     
    5859    print("  -m|--makefile     Warning: depreciated and will be removed ")
    5960    print("  -b|--buildscripts just generate the build scripts")
     61    print("  -S|--stats        Print a statistics report")
    6062    print("  -R|--reverse      default FreeBSD -> RTEMS, reverse that")
    6163    print("  -r|--rtems        RTEMS Libbsd directory (default: '.')")
     
    6567# Parse the arguments
    6668def parseArguments():
    67     global isForward, isEarlyExit
     69    global isForward, isEarlyExit, statsReport
    6870    global isOnlyBuildScripts
    6971    try:
    7072        opts, args = getopt.getopt(sys.argv[1:],
    71                                    "?hdDembRr:f:v",
     73                                   "?hdDembSRr:f:v",
    7274                                   [ "help",
    7375                                     "help",
     
    7880                                     "buildscripts"
    7981                                     "reverse"
     82                                     "stats"
    8083                                     "rtems="
    8184                                     "freebsd="
     
    100103        elif o in ("-b", "--buildscripts") or o in ("-m", "--makefile"):
    101104            isOnlyBuildScripts = True
     105        elif o in ("-S", "--stats"):
     106            statsReport = True
    102107        elif o in ("-R", "--reverse"):
    103108            isForward = False
     
    153158        wafGen.processSource(isForward)
    154159    wafGen.generate(libbsd.rtems_version())
    155     builder.changedFileSummary()
     160    builder.changedFileSummary(statsReport)
    156161except IOError as ioe:
    157162    print('error: %s' % (str(ioe)))
  • libbsd.txt

    r70d52b8 rf9798ad  
    615615  -m|--makefile     Warning: depreciated and will be removed
    616616  -b|--buildscripts just generate the build scripts
     617  -S|--stats        Print a statistics report
    617618  -R|--reverse      default FreeBSD -> RTEMS, reverse that
    618   -r|--rtems        RTEMS directory
    619   -f|--freebsd      FreeBSD directory
     619  -r|--rtems        RTEMS Libbsd directory (default: '.')
     620  -f|--freebsd      FreeBSD SVN directory (default: 'freebsd-org')
    620621  -v|--verbose      enable verbose output mode
    621622----
     
    682683. Run `./create-kernel-namespace.sh` if you imported kernel space headers.  Add only your new defines via `git add -p rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h`.
    683684. Create one commit from this.
     685
     686The -S or --stats option generates reports the changes we have made to
     687FreeBSD. If the code has been reserved into the original FreeBSD tree it will
     688show nothing has changed. To see what we have change:
     689
     690 $ cd freebsd-org
     691 $ git checkout -- .
     692 $ cd ..
     693 $ ./freebsd-to-rtems.py -R -S -d
     694
     695The report lists the files change based on the opacity level. The opacity is a
     696measure on how much of a file differs from the original FreeBSD source. The
     697lower the value the more transparent the source file it.
    684698
    685699== Initialization of the BSD Library
Note: See TracChangeset for help on using the changeset viewer.