1 #!/usr/bin/env python 2 # 3 import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess 4 from defaults import * 5 from utils import * 6 7 def usage(): 8 print """\ 9 usage: %(progname)s [kernel-original-path] 10 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.. 19 """ % { "progname" : os.path.basename(sys.argv[0]) } 20 sys.exit(0) 21 22 try: 23 optlist, args = getopt.getopt( sys.argv[1:], '' ) 24 except: 25 # unrecognized option 26 sys.stderr.write( "error: unrecognized option\n" ) 27 usage() 28 29 if len(optlist) > 0 or len(args) > 1: 30 usage() 31 32 progdir = find_program_dir() 33 34 if len(args) == 1: 35 original_dir = args[0] 36 if not os.path.isdir(original_dir): 37 panic( "Not a directory: %s\n" % original_dir ) 38 else: 39 original_dir = kernel_original_path 40 if not os.path.isdir(original_dir): 41 panic( "Missing directory, please specify one through command-line: %s\n" % original_dir ) 42 43 # Fixme: This should be removed after next release. 44 # Do not update ion.h ion_test.h until after next release in aosp. 45 source = subprocess.check_output('git remote show', shell=True).strip() 46 skip_ion = False 47 if source == "aosp": 48 skip_ion = True 49 50 # find all source files in 'original' 51 # 52 sources = [] 53 warning_ion = [] 54 for root, dirs, files in os.walk( original_dir ): 55 for file in files: 56 if skip_ion and (file == "ion.h" or file == "ion_test.h"): 57 warning_ion.append(" Skipped file %s/%s" % (root, file)) 58 continue 59 base, ext = os.path.splitext(file) 60 if ext == ".h": 61 sources.append( "%s/%s" % (root,file) ) 62 63 b = BatchFileUpdater() 64 65 for arch in kernel_archs: 66 b.readDir( os.path.normpath( progdir + "/../arch-%s" % arch ) ) 67 68 b.readDir( os.path.normpath( progdir + "/../common" ) ) 69 70 #print "OLD " + repr(b.old_files) 71 72 oldlen = 120 73 for path in sources: 74 dst_path, newdata = clean_header.cleanupFile(path, original_dir) 75 if not dst_path: 76 continue 77 78 b.readFile( dst_path ) 79 r = b.editFile( dst_path, newdata ) 80 if r == 0: 81 state = "unchanged" 82 elif r == 1: 83 state = "edited" 84 else: 85 state = "added" 86 87 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 97 98 oldlen = len(str) 99 100 print "%-*s" % (oldlen,"Done!") 101 102 b.updateGitFiles() 103 104 if warning_ion: 105 print "NOTE: Due to import into aosp, some files were not processed." 106 print "\n".join(warning_ion) 107 sys.exit(0) 108