source: rtems-libbsd/freebsd-to-rtems.py @ 97c5024a

5-freebsd-12freebsd-9.3
Last change on this file since 97c5024a was 97c5024a, checked in by Chris Johns <chrisj@…>, on Apr 18, 2016 at 12:53:20 AM

Add RTEMS version support, update all python to 2 and 3.

Add support to force the RTEMS version. This remove the need for using
the --rtems-version command line option if the automatic detection fails.

Update all python code to support python 2 and 3.

Update rtems_waf to the latest version to support the RTEMS version,
check environment variables and to display the CC version.

Sort all tests. I think the unsorted list is dependent on the version
of python and so would result in repo noise as if it regenerted.

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