2009-03-04 04:28:35 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2014-07-10 00:33:25 +02:00
|
|
|
import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
|
2009-03-04 04:28:35 +01:00
|
|
|
from defaults import *
|
|
|
|
from utils import *
|
|
|
|
|
|
|
|
def usage():
|
|
|
|
print """\
|
2010-10-11 22:11:06 +02:00
|
|
|
usage: %(progname)s [kernel-original-path]
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
this program is used to update all the auto-generated clean headers
|
|
|
|
used by the Bionic C library. it assumes the following:
|
|
|
|
|
|
|
|
- a set of source kernel headers is located in '../original',
|
|
|
|
relative to the program's directory
|
|
|
|
|
|
|
|
- the clean headers will be placed in '../arch-<arch>/asm',
|
|
|
|
'../common/linux', '../common/asm-generic', etc..
|
|
|
|
""" % { "progname" : os.path.basename(sys.argv[0]) }
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
try:
|
|
|
|
optlist, args = getopt.getopt( sys.argv[1:], '' )
|
|
|
|
except:
|
|
|
|
# unrecognized option
|
|
|
|
sys.stderr.write( "error: unrecognized option\n" )
|
|
|
|
usage()
|
|
|
|
|
2010-10-11 22:11:06 +02:00
|
|
|
if len(optlist) > 0 or len(args) > 1:
|
2009-03-04 04:28:35 +01:00
|
|
|
usage()
|
|
|
|
|
|
|
|
progdir = find_program_dir()
|
2010-10-11 22:11:06 +02:00
|
|
|
|
|
|
|
if len(args) == 1:
|
2011-12-19 20:27:50 +01:00
|
|
|
original_dir = args[0]
|
2010-10-11 22:11:06 +02:00
|
|
|
if not os.path.isdir(original_dir):
|
2011-12-19 20:27:50 +01:00
|
|
|
panic( "Not a directory: %s\n" % original_dir )
|
2010-10-11 22:11:06 +02:00
|
|
|
else:
|
|
|
|
original_dir = kernel_original_path
|
|
|
|
if not os.path.isdir(original_dir):
|
2011-12-19 20:27:50 +01:00
|
|
|
panic( "Missing directory, please specify one through command-line: %s\n" % original_dir )
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-07-10 00:33:25 +02:00
|
|
|
# Fixme: This should be removed after next release.
|
|
|
|
# Do not update ion.h ion_test.h until after next release in aosp.
|
|
|
|
source = subprocess.check_output('git remote show', shell=True).strip()
|
|
|
|
skip_ion = False
|
|
|
|
if source == "aosp":
|
|
|
|
skip_ion = True
|
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
# find all source files in 'original'
|
|
|
|
#
|
|
|
|
sources = []
|
2014-07-10 00:33:25 +02:00
|
|
|
warning_ion = []
|
2009-03-04 04:28:35 +01:00
|
|
|
for root, dirs, files in os.walk( original_dir ):
|
|
|
|
for file in files:
|
2014-07-10 00:33:25 +02:00
|
|
|
if skip_ion and (file == "ion.h" or file == "ion_test.h"):
|
|
|
|
warning_ion.append(" Skipped file %s/%s" % (root, file))
|
|
|
|
continue
|
2009-03-04 04:28:35 +01:00
|
|
|
base, ext = os.path.splitext(file)
|
|
|
|
if ext == ".h":
|
|
|
|
sources.append( "%s/%s" % (root,file) )
|
|
|
|
|
|
|
|
b = BatchFileUpdater()
|
|
|
|
|
|
|
|
for arch in kernel_archs:
|
|
|
|
b.readDir( os.path.normpath( progdir + "/../arch-%s" % arch ) )
|
|
|
|
|
|
|
|
b.readDir( os.path.normpath( progdir + "/../common" ) )
|
|
|
|
|
|
|
|
#print "OLD " + repr(b.old_files)
|
|
|
|
|
2010-10-11 22:11:06 +02:00
|
|
|
oldlen = 120
|
2009-03-04 04:28:35 +01:00
|
|
|
for path in sources:
|
2010-10-11 22:11:06 +02:00
|
|
|
dst_path, newdata = clean_header.cleanupFile(path, original_dir)
|
2009-03-04 04:28:35 +01:00
|
|
|
if not dst_path:
|
|
|
|
continue
|
|
|
|
|
|
|
|
b.readFile( dst_path )
|
|
|
|
r = b.editFile( dst_path, newdata )
|
|
|
|
if r == 0:
|
2010-10-11 22:11:06 +02:00
|
|
|
state = "unchanged"
|
2009-03-04 04:28:35 +01:00
|
|
|
elif r == 1:
|
2010-10-11 22:11:06 +02:00
|
|
|
state = "edited"
|
2009-03-04 04:28:35 +01:00
|
|
|
else:
|
2010-10-11 22:11:06 +02:00
|
|
|
state = "added"
|
|
|
|
|
|
|
|
str = "cleaning: %-*s -> %-*s (%s)" % ( 35, "<original>" + path[len(original_dir):], 35, dst_path, state )
|
|
|
|
if sys.stdout.isatty():
|
|
|
|
print "%-*s" % (oldlen,str),
|
|
|
|
if (r == 0):
|
|
|
|
print "\r",
|
|
|
|
else:
|
|
|
|
print "\n",
|
|
|
|
oldlen = 0
|
|
|
|
else:
|
|
|
|
print str
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2010-10-11 22:11:06 +02:00
|
|
|
oldlen = len(str)
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2010-10-11 22:11:06 +02:00
|
|
|
print "%-*s" % (oldlen,"Done!")
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2010-10-11 22:11:06 +02:00
|
|
|
b.updateGitFiles()
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-07-10 00:33:25 +02:00
|
|
|
if warning_ion:
|
|
|
|
print "NOTE: Due to import into aosp, some files were not processed."
|
|
|
|
print "\n".join(warning_ion)
|
2009-03-04 04:28:35 +01:00
|
|
|
sys.exit(0)
|