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