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