source: rtems-libbsd/freebsd-to-rtems.py @ b151e8a

55-freebsd-126-freebsd-12
Last change on this file since b151e8a 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
RevLine 
[314be23]1#! /usr/bin/env python
2#
[97c5024a]3#  Copyright (c) 2015-2016 Chris Johns <chrisj@rtems.org>. All rights reserved.
[63e8969]4#
[012c263]5#  Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
[294ae20]6#
7#   embedded brains GmbH
[e599318]8#   Dornierstr. 4
[294ae20]9#   82178 Puchheim
10#   Germany
11#   <info@embedded-brains.de>
12#
[287453d]13#  Copyright (c) 2012 OAR Corporation. All rights reserved.
14#
[294ae20]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
[97c5024a]38from __future__ import print_function
39
[294ae20]40import os
[63e8969]41import sys
[b9c291c]42import getopt
43
[314be23]44import builder
45import libbsd
46
[b9c291c]47isForward = True
[a803d120]48isEarlyExit = False
[f9798ad]49statsReport = False
[b9c291c]50
51def usage():
[97c5024a]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 ")
[f9798ad]58    print("  -S|--stats        Print a statistics report")
[fa4ec51]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')")
[97c5024a]62    print("  -v|--verbose      enable verbose output mode")
[b9c291c]63
64# Parse the arguments
65def parseArguments():
[f9798ad]66    global isForward, isEarlyExit, statsReport
[314be23]67    try:
68        opts, args = getopt.getopt(sys.argv[1:],
[f9798ad]69                                   "?hdDembSRr:f:v",
[314be23]70                                   [ "help",
71                                     "help",
72                                     "dry-run"
73                                     "diff"
74                                     "early-exit"
75                                     "makefile"
[97c5024a]76                                     "buildscripts"
[314be23]77                                     "reverse"
[f9798ad]78                                     "stats"
[314be23]79                                     "rtems="
80                                     "freebsd="
81                                     "verbose" ])
[97c5024a]82    except getopt.GetoptError as err:
[314be23]83        # print help information and exit:
[97c5024a]84        print(str(err)) # will print something like "option -a not recognized"
[314be23]85        usage()
86        sys.exit(2)
87    for o, a in opts:
88        if o in ("-v", "--verbose"):
[f1fcdba]89            builder.verboseLevel += 1
[314be23]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
[f9798ad]99        elif o in ("-S", "--stats"):
100            statsReport = True
[314be23]101        elif o in ("-R", "--reverse"):
102            isForward = False
103        elif o in ("-r", "--rtems"):
[fa4ec51]104            builder.LIBBSD_DIR = a
[314be23]105        elif o in ("-f", "--freebsd"):
106            builder.FreeBSD_DIR = a
107        else:
108            assert False, "unhandled option"
[b9c291c]109
110parseArguments()
[314be23]111
[f1fcdba]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]))
[fa4ec51]116print("LibBSD Directory:            %s" % (builder.LIBBSD_DIR))
117print("FreeBSD Directory:           %s" % (builder.FreeBSD_DIR))
[f1fcdba]118print("Direction:                   %s" % (("reverse", "forward")[isForward]))
[b9c291c]119
[a803d120]120# Check directory argument was set and exist
121def wasDirectorySet(desc, path):
122    if path == "not_set":
[97c5024a]123        print("error:" + desc + " Directory was not specified on command line")
[a803d120]124        sys.exit(2)
125
126    if os.path.isdir( path ) != True:
[97c5024a]127        print("error:" + desc + " Directory (" + path + ") does not exist")
[a803d120]128        sys.exit(2)
129
[fa4ec51]130# Were directories specified?
131wasDirectorySet( "LibBSD", builder.LIBBSD_DIR )
[314be23]132wasDirectorySet( "FreeBSD", builder.FreeBSD_DIR )
133
[1e8830f0]134# Are we generating or reverting?
135if isForward == True:
[445d59e]136    print("Forward from", builder.FreeBSD_DIR, "into", builder.LIBBSD_DIR)
[1e8830f0]137else:
[fa4ec51]138    print("Reverting from", builder.LIBBSD_DIR)
[1e8830f0]139
[a803d120]140if isEarlyExit == True:
[97c5024a]141    print("Early exit at user request")
[a803d120]142    sys.exit(0)
[294ae20]143
[8440506]144try:
[f7a09b5]145    build = builder.ModuleManager()
[d797c5d]146    libbsd.load(build)
[fedd993]147    build.generateBuild(only_enabled=False)
[f7a09b5]148    build.processSource(isForward)
[f9798ad]149    builder.changedFileSummary(statsReport)
[97c5024a]150except IOError as ioe:
[f1fcdba]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.