blob: 73862da17d4b7badf64df68fc3984b246d23065a [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001#!/usr/bin/env python
2#
Christopher Ferris38062f92014-07-09 15:33:25 -07003import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08004from defaults import *
5from utils import *
6
7def usage():
8 print """\
David 'Digit' Turnerfc269312010-10-11 22:11:06 +02009 usage: %(progname)s [kernel-original-path]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080010
11 this program is used to update all the auto-generated clean headers
12 used by the Bionic C library. it assumes the following:
13
14 - a set of source kernel headers is located in '../original',
15 relative to the program's directory
16
17 - the clean headers will be placed in '../arch-<arch>/asm',
18 '../common/linux', '../common/asm-generic', etc..
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080019""" % { "progname" : os.path.basename(sys.argv[0]) }
20 sys.exit(0)
21
22try:
23 optlist, args = getopt.getopt( sys.argv[1:], '' )
24except:
25 # unrecognized option
26 sys.stderr.write( "error: unrecognized option\n" )
27 usage()
28
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020029if len(optlist) > 0 or len(args) > 1:
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080030 usage()
31
32progdir = find_program_dir()
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020033
34if len(args) == 1:
Glenn Kastenc61f9902011-12-19 11:27:50 -080035 original_dir = args[0]
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020036 if not os.path.isdir(original_dir):
Glenn Kastenc61f9902011-12-19 11:27:50 -080037 panic( "Not a directory: %s\n" % original_dir )
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020038else:
39 original_dir = kernel_original_path
40 if not os.path.isdir(original_dir):
Glenn Kastenc61f9902011-12-19 11:27:50 -080041 panic( "Missing directory, please specify one through command-line: %s\n" % original_dir )
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042
Christopher Ferris38062f92014-07-09 15:33:25 -070043# Fixme: This should be removed after next release.
44# Do not update ion.h ion_test.h until after next release in aosp.
45source = subprocess.check_output('git remote show', shell=True).strip()
46skip_ion = False
47if source == "aosp":
48 skip_ion = True
49
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080050# find all source files in 'original'
51#
52sources = []
Christopher Ferris38062f92014-07-09 15:33:25 -070053warning_ion = []
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080054for root, dirs, files in os.walk( original_dir ):
55 for file in files:
Christopher Ferris38062f92014-07-09 15:33:25 -070056 if skip_ion and (file == "ion.h" or file == "ion_test.h"):
57 warning_ion.append(" Skipped file %s/%s" % (root, file))
58 continue
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080059 base, ext = os.path.splitext(file)
60 if ext == ".h":
61 sources.append( "%s/%s" % (root,file) )
62
63b = BatchFileUpdater()
64
65for arch in kernel_archs:
66 b.readDir( os.path.normpath( progdir + "/../arch-%s" % arch ) )
67
68b.readDir( os.path.normpath( progdir + "/../common" ) )
69
70#print "OLD " + repr(b.old_files)
71
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020072oldlen = 120
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080073for path in sources:
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020074 dst_path, newdata = clean_header.cleanupFile(path, original_dir)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080075 if not dst_path:
76 continue
77
78 b.readFile( dst_path )
79 r = b.editFile( dst_path, newdata )
80 if r == 0:
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020081 state = "unchanged"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080082 elif r == 1:
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020083 state = "edited"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080084 else:
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020085 state = "added"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080086
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020087 str = "cleaning: %-*s -> %-*s (%s)" % ( 35, "<original>" + path[len(original_dir):], 35, dst_path, state )
88 if sys.stdout.isatty():
89 print "%-*s" % (oldlen,str),
90 if (r == 0):
91 print "\r",
92 else:
93 print "\n",
94 oldlen = 0
95 else:
96 print str
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080097
David 'Digit' Turnerfc269312010-10-11 22:11:06 +020098 oldlen = len(str)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080099
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200100print "%-*s" % (oldlen,"Done!")
101
102b.updateGitFiles()
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800103
Christopher Ferris38062f92014-07-09 15:33:25 -0700104if warning_ion:
105 print "NOTE: Due to import into aosp, some files were not processed."
106 print "\n".join(warning_ion)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800107sys.exit(0)