mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-06-28 05:07:55 +08:00
freebsd-to-rtems.py Enhancements
+ dry-run mode + early-exit mode + more verbose output + usage message improved + FreeBSD and RTEMS Directory error checking
This commit is contained in:
parent
b9c291c147
commit
a803d120b6
@ -37,21 +37,32 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
|
|
||||||
RTEMS_DIR = sys.argv[1]
|
RTEMS_DIR = "not_set"
|
||||||
FreeBSD_DIR = '.'
|
FreeBSD_DIR = "not_set"
|
||||||
verbose = False
|
isVerbose = False
|
||||||
isForward = True
|
isForward = True
|
||||||
|
isDryRun = True
|
||||||
|
isEarlyExit = False
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print "Usage help here"
|
print "freebsd-to-rtems.py [args]"
|
||||||
|
print " -?|-h|--help print this and exit"
|
||||||
|
print " -d|--dry-run run program but no modifications"
|
||||||
|
print " -e|--early-exit evaluate arguments, print results, and exit"
|
||||||
|
print " -R|--reverse default FreeBSD -> RTEMS, reverse that"
|
||||||
|
print " -r|--rtems RTEMS directory"
|
||||||
|
print " -f|--freebsd FreeBSD directory"
|
||||||
|
print " -v|--verbose enable verbose output mode"
|
||||||
|
|
||||||
# Parse the arguments
|
# Parse the arguments
|
||||||
def parseArguments():
|
def parseArguments():
|
||||||
global RTEMS_DIR, FreeBSD_DIR, verbose, isForward
|
global RTEMS_DIR, FreeBSD_DIR, isVerbose, isForward, isEarlyExit
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "?hRr:f:v",
|
opts, args = getopt.getopt(sys.argv[1:], "?hdeRr:f:v",
|
||||||
["help",
|
["help",
|
||||||
"help",
|
"help",
|
||||||
|
"dry-run"
|
||||||
|
"early-exit"
|
||||||
"reverse"
|
"reverse"
|
||||||
"rtems="
|
"rtems="
|
||||||
"freebsd="
|
"freebsd="
|
||||||
@ -65,10 +76,14 @@ def parseArguments():
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == "-v":
|
if o == "-v":
|
||||||
verbose = True
|
isVerbose = True
|
||||||
elif o in ("-h", "--help", "-?"):
|
elif o in ("-h", "--help", "-?"):
|
||||||
usage()
|
usage()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
elif o in ("-d", "--dry-run"):
|
||||||
|
isForward = False
|
||||||
|
elif o in ("-e", "--early-exit"):
|
||||||
|
isEarlyExit = True
|
||||||
elif o in ("-R", "--reverse"):
|
elif o in ("-R", "--reverse"):
|
||||||
isForward = False
|
isForward = False
|
||||||
elif o in ("-r", "--rtems"):
|
elif o in ("-r", "--rtems"):
|
||||||
@ -81,20 +96,38 @@ def parseArguments():
|
|||||||
assert False, "unhandled option"
|
assert False, "unhandled option"
|
||||||
|
|
||||||
parseArguments()
|
parseArguments()
|
||||||
print "Verbose: " + ("no", "yes")[verbose]
|
print "Verbose: " + ("no", "yes")[isVerbose]
|
||||||
|
print "Dry Run: " + ("no", "yes")[isDryRun]
|
||||||
print "RTEMS Directory: " + RTEMS_DIR
|
print "RTEMS Directory: " + RTEMS_DIR
|
||||||
print "FreeBSD Directory: " + FreeBSD_DIR
|
print "FreeBSD Directory: " + FreeBSD_DIR
|
||||||
print "Direction: " + ("reverse", "forward")[isForward]
|
print "Direction: " + ("reverse", "forward")[isForward]
|
||||||
|
|
||||||
# test for existence of RTEMS and FreeBSD directories
|
# Check directory argument was set and exist
|
||||||
if os.path.isdir( RTEMS_DIR ) != True:
|
def wasDirectorySet(desc, path):
|
||||||
print "RTEMS Directory (" + RTEMS_DIR + ") does not exist"
|
if path == "not_set":
|
||||||
sys.exit(2)
|
print desc + " Directory was not specified on command line"
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
if os.path.isdir( path ) != True:
|
||||||
|
print desc + " Directory (" + path + ") does not exist"
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
# Were RTEMS and FreeBSD directories specified
|
||||||
|
wasDirectorySet( "RTEMS", RTEMS_DIR )
|
||||||
|
wasDirectorySet( "FreeBSD", FreeBSD_DIR )
|
||||||
|
|
||||||
if os.path.isdir( FreeBSD_DIR ) != True:
|
if os.path.isdir( FreeBSD_DIR ) != True:
|
||||||
print "FreeBSD Directory (" + FreeBSD_DIR + ") does not exist"
|
print "FreeBSD Directory (" + FreeBSD_DIR + ") does not exist"
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
if FreeBSD_DIR == RTEMS_DIR:
|
||||||
|
print "FreeBSD and RTEMS Directories are the same"
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
if isEarlyExit == True:
|
||||||
|
print "Early exit at user request"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# Prefix added to FreeBSD files as they are copied into the RTEMS
|
# Prefix added to FreeBSD files as they are copied into the RTEMS
|
||||||
# build tree.
|
# build tree.
|
||||||
PREFIX = 'freebsd'
|
PREFIX = 'freebsd'
|
||||||
@ -109,6 +142,10 @@ def mapContribPath(path):
|
|||||||
|
|
||||||
def installEmptyFile(src):
|
def installEmptyFile(src):
|
||||||
dst = RTEMS_DIR + '/' + PREFIX + '/' + src.replace('rtems/', '')
|
dst = RTEMS_DIR + '/' + PREFIX + '/' + src.replace('rtems/', '')
|
||||||
|
if isVerbose == True:
|
||||||
|
print "Install empty - " + dst
|
||||||
|
if isDryRun == True:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(dst))
|
os.makedirs(os.path.dirname(dst))
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -135,6 +172,10 @@ def installHeaderFile(org):
|
|||||||
src = FreeBSD_DIR + '/' + org
|
src = FreeBSD_DIR + '/' + org
|
||||||
dst = RTEMS_DIR + '/' + PREFIX + '/' + org # + org.replace('rtems/', '')
|
dst = RTEMS_DIR + '/' + PREFIX + '/' + org # + org.replace('rtems/', '')
|
||||||
dst = mapContribPath(dst)
|
dst = mapContribPath(dst)
|
||||||
|
if isVerbose == True:
|
||||||
|
print "Install Header - " + src + " => " + dst
|
||||||
|
if isDryRun == True:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(dst))
|
os.makedirs(os.path.dirname(dst))
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -150,6 +191,10 @@ def installSourceFile(org):
|
|||||||
src = FreeBSD_DIR + '/' + org
|
src = FreeBSD_DIR + '/' + org
|
||||||
dst = RTEMS_DIR + '/' + PREFIX + '/' + org
|
dst = RTEMS_DIR + '/' + PREFIX + '/' + org
|
||||||
dst = mapContribPath(dst)
|
dst = mapContribPath(dst)
|
||||||
|
if isVerbose == True:
|
||||||
|
print "Install Source - " + src + " => " + dst
|
||||||
|
if isDryRun == True:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(dst))
|
os.makedirs(os.path.dirname(dst))
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -166,6 +211,10 @@ def revertHeaderFile(org):
|
|||||||
src = RTEMS_DIR + '/' + PREFIX + '/' + org.replace('rtems/', '')
|
src = RTEMS_DIR + '/' + PREFIX + '/' + org.replace('rtems/', '')
|
||||||
src = mapContribPath(src)
|
src = mapContribPath(src)
|
||||||
dst = FreeBSD_DIR + '/' + org
|
dst = FreeBSD_DIR + '/' + org
|
||||||
|
if isVerbose == True:
|
||||||
|
print "Revert Header - " + src + " => " + dst
|
||||||
|
if isDryRun == True:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(dst))
|
os.makedirs(os.path.dirname(dst))
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -181,6 +230,10 @@ def revertSourceFile(org):
|
|||||||
src = RTEMS_DIR + '/' + PREFIX + '/' + org
|
src = RTEMS_DIR + '/' + PREFIX + '/' + org
|
||||||
src = mapContribPath(src)
|
src = mapContribPath(src)
|
||||||
dst = FreeBSD_DIR + '/' + org
|
dst = FreeBSD_DIR + '/' + org
|
||||||
|
if isVerbose == True:
|
||||||
|
print "Revert Source - " + src + " => " + dst
|
||||||
|
if isDryRun == True:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(dst))
|
os.makedirs(os.path.dirname(dst))
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -194,6 +247,10 @@ def revertSourceFile(org):
|
|||||||
out.close()
|
out.close()
|
||||||
|
|
||||||
def deleteOutputDirectory():
|
def deleteOutputDirectory():
|
||||||
|
if isVerbose == True:
|
||||||
|
print "Delete Directory - " + RTEMS_DIR
|
||||||
|
if isDryRun == True:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(RTEMS_DIR)
|
shutil.rmtree(RTEMS_DIR)
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -227,6 +284,10 @@ class ModuleManager:
|
|||||||
revertSourceFile(f)
|
revertSourceFile(f)
|
||||||
|
|
||||||
def createMakefile(self):
|
def createMakefile(self):
|
||||||
|
if isVerbose == True:
|
||||||
|
print "Create Makefile"
|
||||||
|
if isDryRun == True:
|
||||||
|
return
|
||||||
data = 'include config.inc\n' \
|
data = 'include config.inc\n' \
|
||||||
'\n' \
|
'\n' \
|
||||||
'include $(RTEMS_MAKEFILE_PATH)/Makefile.inc\n' \
|
'include $(RTEMS_MAKEFILE_PATH)/Makefile.inc\n' \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user