source: rtems-libbsd/freebsd-to-rtems.py @ 38c1a41

55-freebsd-126-freebsd-12
Last change on this file since 38c1a41 was fedd993, checked in by Christian Mauderer <christian.mauderer@…>, on 04/06/18 at 07:37:35

freebsd-to-rtems.py: Use all modules.

Update #3351

  • Property mode set to 100755
File size: 5.8 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 libbsd
46
47isForward = True
48isEarlyExit = False
49statsReport = False
50
51def usage():
52    print("freebsd-to-rtems.py [args]")
53    print("  -?|-h|--help      print this and exit")
54    print("  -d|--dry-run      run program but no modifications")
55    print("  -D|--diff         provide diff of files between trees")
56    print("  -e|--early-exit   evaluate arguments, print results, and exit")
57    print("  -m|--makefile     Warning: depreciated and will be removed ")
58    print("  -S|--stats        Print a statistics report")
59    print("  -R|--reverse      default origin -> LibBSD, reverse that")
60    print("  -r|--rtems        LibBSD directory (default: '.')")
61    print("  -f|--freebsd      FreeBSD origin directory (default: 'freebsd-org')")
62    print("  -v|--verbose      enable verbose output mode")
63
64# Parse the arguments
65def parseArguments():
66    global isForward, isEarlyExit, statsReport
67    try:
68        opts, args = getopt.getopt(sys.argv[1:],
69                                   "?hdDembSRr:f:v",
70                                   [ "help",
71                                     "help",
72                                     "dry-run"
73                                     "diff"
74                                     "early-exit"
75                                     "makefile"
76                                     "buildscripts"
77                                     "reverse"
78                                     "stats"
79                                     "rtems="
80                                     "freebsd="
81                                     "verbose" ])
82    except getopt.GetoptError as err:
83        # print help information and exit:
84        print(str(err)) # will print something like "option -a not recognized"
85        usage()
86        sys.exit(2)
87    for o, a in opts:
88        if o in ("-v", "--verbose"):
89            builder.verboseLevel += 1
90        elif o in ("-h", "--help", "-?"):
91            usage()
92            sys.exit()
93        elif o in ("-d", "--dry-run"):
94            builder.isDryRun = True
95        elif o in ("-D", "--diff"):
96            builder.isDiffMode = True
97        elif o in ("-e", "--early-exit"):
98            isEarlyExit = True
99        elif o in ("-S", "--stats"):
100            statsReport = True
101        elif o in ("-R", "--reverse"):
102            isForward = False
103        elif o in ("-r", "--rtems"):
104            builder.LIBBSD_DIR = a
105        elif o in ("-f", "--freebsd"):
106            builder.FreeBSD_DIR = a
107        else:
108            assert False, "unhandled option"
109
110parseArguments()
111
112print("Verbose:                     %s (%d)" % (("no", "yes")[builder.verbose()],
113                                                builder.verboseLevel))
114print("Dry Run:                     %s" % (("no", "yes")[builder.isDryRun]))
115print("Diff Mode Enabled:           %s" % (("no", "yes")[builder.isDiffMode]))
116print("LibBSD Directory:            %s" % (builder.LIBBSD_DIR))
117print("FreeBSD Directory:           %s" % (builder.FreeBSD_DIR))
118print("Direction:                   %s" % (("reverse", "forward")[isForward]))
119
120# Check directory argument was set and exist
121def wasDirectorySet(desc, path):
122    if path == "not_set":
123        print("error:" + desc + " Directory was not specified on command line")
124        sys.exit(2)
125
126    if os.path.isdir( path ) != True:
127        print("error:" + desc + " Directory (" + path + ") does not exist")
128        sys.exit(2)
129
130# Were directories specified?
131wasDirectorySet( "LibBSD", builder.LIBBSD_DIR )
132wasDirectorySet( "FreeBSD", builder.FreeBSD_DIR )
133
134# Are we generating or reverting?
135if isForward == True:
136    print("Forward from", builder.FreeBSD_DIR, "into", builder.LIBBSD_DIR)
137else:
138    print("Reverting from", builder.LIBBSD_DIR)
139
140if isEarlyExit == True:
141    print("Early exit at user request")
142    sys.exit(0)
143
144try:
145    build = builder.ModuleManager()
146    libbsd.load(build)
147    build.generateBuild(only_enabled=False)
148    build.processSource(isForward)
149    builder.changedFileSummary(statsReport)
150except IOError as ioe:
151    print('error: %s' % (str(ioe)))
152except builder.error as be:
153    print('error: %s' % (be))
154except KeyboardInterrupt:
155    print('user abort')
Note: See TracBrowser for help on using the repository browser.