source: rtems-libbsd/freebsd-to-rtems.py @ 301ee6e

55-freebsd-126-freebsd-12
Last change on this file since 301ee6e was f9798ad, checked in by Chris Johns <chrisj@…>, on 05/30/16 at 23:49:31

Add a stats report command.

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

  • Property mode set to 100755
File size: 6.3 KB
Line 
1#! /usr/bin/env python
2#
3#  Copyright (c) 2015-2016 Chris Johns <chrisj@rtems.org>. All rights reserved.
4#
5#  Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
6#
7#   embedded brains GmbH
8#   Dornierstr. 4
9#   82178 Puchheim
10#   Germany
11#   <info@embedded-brains.de>
12#
13#  Copyright (c) 2012 OAR Corporation. All rights reserved.
14#
15#  Redistribution and use in source and binary forms, with or without
16#  modification, are permitted provided that the following conditions
17#  are met:
18#  1. Redistributions of source code must retain the above copyright
19#     notice, this list of conditions and the following disclaimer.
20#  2. Redistributions in binary form must reproduce the above copyright
21#     notice, this list of conditions and the following disclaimer in the
22#     documentation and/or other materials provided with the distribution.
23#
24#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28#  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36# FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys (revision 222485)
37
38from __future__ import print_function
39
40import os
41import sys
42import getopt
43
44import builder
45import waf_generator
46import libbsd
47
48isForward = True
49isEarlyExit = False
50isOnlyBuildScripts = False
51statsReport = False
52
53def usage():
54    print("freebsd-to-rtems.py [args]")
55    print("  -?|-h|--help      print this and exit")
56    print("  -d|--dry-run      run program but no modifications")
57    print("  -D|--diff         provide diff of files between trees")
58    print("  -e|--early-exit   evaluate arguments, print results, and exit")
59    print("  -m|--makefile     Warning: depreciated and will be removed ")
60    print("  -b|--buildscripts just generate the build scripts")
61    print("  -S|--stats        Print a statistics report")
62    print("  -R|--reverse      default FreeBSD -> RTEMS, reverse that")
63    print("  -r|--rtems        RTEMS Libbsd directory (default: '.')")
64    print("  -f|--freebsd      FreeBSD SVN directory (default: 'freebsd-org')")
65    print("  -v|--verbose      enable verbose output mode")
66
67# Parse the arguments
68def parseArguments():
69    global isForward, isEarlyExit, statsReport
70    global isOnlyBuildScripts
71    try:
72        opts, args = getopt.getopt(sys.argv[1:],
73                                   "?hdDembSRr:f:v",
74                                   [ "help",
75                                     "help",
76                                     "dry-run"
77                                     "diff"
78                                     "early-exit"
79                                     "makefile"
80                                     "buildscripts"
81                                     "reverse"
82                                     "stats"
83                                     "rtems="
84                                     "freebsd="
85                                     "verbose" ])
86    except getopt.GetoptError as err:
87        # print help information and exit:
88        print(str(err)) # will print something like "option -a not recognized"
89        usage()
90        sys.exit(2)
91    for o, a in opts:
92        if o in ("-v", "--verbose"):
93            builder.verboseLevel += 1
94        elif o in ("-h", "--help", "-?"):
95            usage()
96            sys.exit()
97        elif o in ("-d", "--dry-run"):
98            builder.isDryRun = True
99        elif o in ("-D", "--diff"):
100            builder.isDiffMode = True
101        elif o in ("-e", "--early-exit"):
102            isEarlyExit = True
103        elif o in ("-b", "--buildscripts") or o in ("-m", "--makefile"):
104            isOnlyBuildScripts = True
105        elif o in ("-S", "--stats"):
106            statsReport = True
107        elif o in ("-R", "--reverse"):
108            isForward = False
109        elif o in ("-r", "--rtems"):
110            builder.RTEMS_DIR = a
111        elif o in ("-f", "--freebsd"):
112            builder.FreeBSD_DIR = a
113        else:
114            assert False, "unhandled option"
115
116parseArguments()
117
118print("Verbose:                     %s (%d)" % (("no", "yes")[builder.verbose()],
119                                                builder.verboseLevel))
120print("Dry Run:                     %s" % (("no", "yes")[builder.isDryRun]))
121print("Diff Mode Enabled:           %s" % (("no", "yes")[builder.isDiffMode]))
122print("Only Generate Build Scripts: %s" % (("no", "yes")[isOnlyBuildScripts]))
123print("RTEMS Libbsd Directory:      %s" % (builder.RTEMS_DIR))
124print("FreeBSD SVN Directory:       %s" % (builder.FreeBSD_DIR))
125print("Direction:                   %s" % (("reverse", "forward")[isForward]))
126
127# Check directory argument was set and exist
128def wasDirectorySet(desc, path):
129    if path == "not_set":
130        print("error:" + desc + " Directory was not specified on command line")
131        sys.exit(2)
132
133    if os.path.isdir( path ) != True:
134        print("error:" + desc + " Directory (" + path + ") does not exist")
135        sys.exit(2)
136
137# Were RTEMS and FreeBSD directories specified
138wasDirectorySet( "RTEMS", builder.RTEMS_DIR )
139wasDirectorySet( "FreeBSD", builder.FreeBSD_DIR )
140
141# Are we generating or reverting?
142if isForward == True:
143    print("Forward from FreeBSD GIT into ", builder.RTEMS_DIR)
144else:
145    print("Reverting from ", builder.RTEMS_DIR)
146    if isOnlyBuildScripts == True:
147        print("error: Build Script generation and Reverse are contradictory")
148        sys.exit(2)
149
150if isEarlyExit == True:
151    print("Early exit at user request")
152    sys.exit(0)
153
154try:
155    wafGen = waf_generator.ModuleManager()
156    libbsd.sources(wafGen)
157    if not isOnlyBuildScripts:
158        wafGen.processSource(isForward)
159    wafGen.generate(libbsd.rtems_version())
160    builder.changedFileSummary(statsReport)
161except IOError as ioe:
162    print('error: %s' % (str(ioe)))
163except builder.error as be:
164    print('error: %s' % (be))
165except KeyboardInterrupt:
166    print('user abort')
Note: See TracBrowser for help on using the repository browser.