2009-03-03 19:28:35 -08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2014-07-09 15:33:25 -07:00
|
|
|
import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
|
2009-03-03 19:28:35 -08:00
|
|
|
from defaults import *
|
|
|
|
from utils import *
|
|
|
|
|
|
|
|
def usage():
|
|
|
|
print """\
|
2015-09-15 14:13:17 -07:00
|
|
|
usage: %(progname)s [kernel-original-path] [kernel-modified-path]
|
2009-03-03 19:28:35 -08:00
|
|
|
|
|
|
|
this program is used to update all the auto-generated clean headers
|
|
|
|
used by the Bionic C library. it assumes the following:
|
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
- a set of source kernel headers is located in
|
|
|
|
'external/kernel-headers/original', relative to the current
|
|
|
|
android tree
|
2009-03-03 19:28:35 -08:00
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
- a set of manually modified kernel header files located in
|
|
|
|
'external/kernel-headers/modified', relative to the current
|
|
|
|
android tree
|
|
|
|
|
|
|
|
- the clean headers will be placed in 'bionic/libc/kernel/arch-<arch>/asm',
|
|
|
|
'bionic/libc/kernel/common', etc..
|
2009-03-03 19:28:35 -08:00
|
|
|
""" % { "progname" : os.path.basename(sys.argv[0]) }
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
try:
|
2015-09-15 14:13:17 -07:00
|
|
|
optlist, args = getopt.getopt(sys.argv[1:], '')
|
2009-03-03 19:28:35 -08:00
|
|
|
except:
|
|
|
|
# unrecognized option
|
2015-09-15 14:13:17 -07:00
|
|
|
sys.stderr.write("error: unrecognized option\n")
|
2009-03-03 19:28:35 -08:00
|
|
|
usage()
|
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
if len(optlist) > 0 or len(args) > 2:
|
2009-03-03 19:28:35 -08:00
|
|
|
usage()
|
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
modified_dir = get_kernel_headers_modified_dir()
|
|
|
|
if len(args) == 1 or len(args) == 2:
|
2011-12-19 11:27:50 -08:00
|
|
|
original_dir = args[0]
|
2010-10-11 22:11:06 +02:00
|
|
|
if not os.path.isdir(original_dir):
|
2015-09-15 14:13:17 -07:00
|
|
|
panic("Not a directory: %s\n" % original_dir)
|
|
|
|
|
|
|
|
if len(args) == 2:
|
|
|
|
modified_dir = args[1]
|
|
|
|
if not os.path.isdir(modified_dir):
|
|
|
|
panic("Not a directory: %s\n" % modified_dir)
|
2010-10-11 22:11:06 +02:00
|
|
|
else:
|
2015-09-15 14:13:17 -07:00
|
|
|
original_dir = get_kernel_headers_original_dir()
|
2010-10-11 22:11:06 +02:00
|
|
|
if not os.path.isdir(original_dir):
|
2015-09-15 14:13:17 -07:00
|
|
|
panic("Missing directory, please specify one through command-line: %s\n" % original_dir)
|
2009-03-03 19:28:35 -08:00
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
if not os.path.isdir(modified_dir):
|
|
|
|
modified_dir = None
|
2014-07-09 15:33:25 -07:00
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
# Find all source files in 'original'.
|
|
|
|
sources = dict()
|
|
|
|
original_dir = os.path.normpath(original_dir)
|
|
|
|
original_dir_len = len(original_dir) + 1
|
|
|
|
for root, _, files in os.walk(original_dir):
|
2009-03-03 19:28:35 -08:00
|
|
|
for file in files:
|
2015-09-15 14:13:17 -07:00
|
|
|
_, ext = os.path.splitext(file)
|
2009-03-03 19:28:35 -08:00
|
|
|
if ext == ".h":
|
2015-09-15 14:13:17 -07:00
|
|
|
rel_path = os.path.normpath(os.path.join(root, file))
|
|
|
|
rel_path = rel_path[original_dir_len:]
|
|
|
|
# Check to see if there is a modified header to use instead.
|
|
|
|
if modified_dir and os.path.exists(os.path.join(modified_dir, rel_path)):
|
|
|
|
sources[rel_path] = False
|
|
|
|
else:
|
|
|
|
sources[rel_path] = True
|
|
|
|
|
2009-03-03 19:28:35 -08:00
|
|
|
|
|
|
|
b = BatchFileUpdater()
|
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
kernel_dir = get_kernel_dir()
|
2009-03-03 19:28:35 -08:00
|
|
|
for arch in kernel_archs:
|
2015-09-15 14:13:17 -07:00
|
|
|
b.readDir(os.path.join(kernel_dir, "arch-%s" % arch))
|
2009-03-03 19:28:35 -08:00
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
b.readDir(os.path.join(kernel_dir, "common"))
|
2009-03-03 19:28:35 -08:00
|
|
|
|
2010-10-11 22:11:06 +02:00
|
|
|
oldlen = 120
|
2015-09-15 14:13:17 -07:00
|
|
|
android_root_len = len(get_android_root()) + 1
|
|
|
|
for rel_path in sorted(sources):
|
|
|
|
if sources[rel_path]:
|
|
|
|
src_dir = original_dir
|
|
|
|
src_str = "<original>/"
|
|
|
|
else:
|
|
|
|
src_dir = modified_dir
|
|
|
|
src_str = "<modified>/"
|
|
|
|
dst_path, newdata = clean_header.cleanupFile(kernel_dir, src_dir, rel_path)
|
2009-03-03 19:28:35 -08:00
|
|
|
if not dst_path:
|
|
|
|
continue
|
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
dst_path = os.path.join(kernel_dir, dst_path)
|
|
|
|
b.readFile(dst_path)
|
|
|
|
r = b.editFile(dst_path, newdata)
|
2009-03-03 19:28:35 -08:00
|
|
|
if r == 0:
|
2010-10-11 22:11:06 +02:00
|
|
|
state = "unchanged"
|
2009-03-03 19:28:35 -08:00
|
|
|
elif r == 1:
|
2010-10-11 22:11:06 +02:00
|
|
|
state = "edited"
|
2009-03-03 19:28:35 -08:00
|
|
|
else:
|
2010-10-11 22:11:06 +02:00
|
|
|
state = "added"
|
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
# dst_path is guaranteed to include android root.
|
|
|
|
rel_dst_path = dst_path[android_root_len:]
|
|
|
|
str = "cleaning: %-*s -> %-*s (%s)" % (35, src_str + rel_path, 35, rel_dst_path, state)
|
2010-10-11 22:11:06 +02:00
|
|
|
if sys.stdout.isatty():
|
2015-09-15 14:13:17 -07:00
|
|
|
print "%-*s" % (oldlen, str),
|
2010-10-11 22:11:06 +02:00
|
|
|
if (r == 0):
|
|
|
|
print "\r",
|
|
|
|
else:
|
|
|
|
print "\n",
|
|
|
|
oldlen = 0
|
|
|
|
else:
|
|
|
|
print str
|
2009-03-03 19:28:35 -08:00
|
|
|
|
2010-10-11 22:11:06 +02:00
|
|
|
oldlen = len(str)
|
2009-03-03 19:28:35 -08:00
|
|
|
|
2015-09-15 14:13:17 -07:00
|
|
|
print "%-*s" % (oldlen, "Done!")
|
2009-03-03 19:28:35 -08:00
|
|
|
|
2010-10-11 22:11:06 +02:00
|
|
|
b.updateGitFiles()
|
2009-03-03 19:28:35 -08:00
|
|
|
|
|
|
|
sys.exit(0)
|