The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
Christopher Ferris | 38062f9 | 2014-07-09 15:33:25 -0700 | [diff] [blame] | 3 | import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 4 | from defaults import * |
| 5 | from utils import * |
| 6 | |
| 7 | def usage(): |
| 8 | print """\ |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 9 | usage: %(progname)s [kernel-original-path] |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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.. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 29 | if len(optlist) > 0 or len(args) > 1: |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 30 | usage() |
| 31 | |
| 32 | progdir = find_program_dir() |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 33 | |
| 34 | if len(args) == 1: |
Glenn Kasten | c61f990 | 2011-12-19 11:27:50 -0800 | [diff] [blame] | 35 | original_dir = args[0] |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 36 | if not os.path.isdir(original_dir): |
Glenn Kasten | c61f990 | 2011-12-19 11:27:50 -0800 | [diff] [blame] | 37 | panic( "Not a directory: %s\n" % original_dir ) |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 38 | else: |
| 39 | original_dir = kernel_original_path |
| 40 | if not os.path.isdir(original_dir): |
Glenn Kasten | c61f990 | 2011-12-19 11:27:50 -0800 | [diff] [blame] | 41 | panic( "Missing directory, please specify one through command-line: %s\n" % original_dir ) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | |
Christopher Ferris | 38062f9 | 2014-07-09 15:33:25 -0700 | [diff] [blame] | 43 | skip_ion = False |
Christopher Ferris | 38062f9 | 2014-07-09 15:33:25 -0700 | [diff] [blame] | 44 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | # find all source files in 'original' |
| 46 | # |
| 47 | sources = [] |
Christopher Ferris | 38062f9 | 2014-07-09 15:33:25 -0700 | [diff] [blame] | 48 | warning_ion = [] |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 49 | for root, dirs, files in os.walk( original_dir ): |
| 50 | for file in files: |
Christopher Ferris | 38062f9 | 2014-07-09 15:33:25 -0700 | [diff] [blame] | 51 | if skip_ion and (file == "ion.h" or file == "ion_test.h"): |
| 52 | warning_ion.append(" Skipped file %s/%s" % (root, file)) |
| 53 | continue |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 54 | base, ext = os.path.splitext(file) |
| 55 | if ext == ".h": |
| 56 | sources.append( "%s/%s" % (root,file) ) |
| 57 | |
| 58 | b = BatchFileUpdater() |
| 59 | |
| 60 | for arch in kernel_archs: |
| 61 | b.readDir( os.path.normpath( progdir + "/../arch-%s" % arch ) ) |
| 62 | |
| 63 | b.readDir( os.path.normpath( progdir + "/../common" ) ) |
| 64 | |
| 65 | #print "OLD " + repr(b.old_files) |
| 66 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 67 | oldlen = 120 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 68 | for path in sources: |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 69 | dst_path, newdata = clean_header.cleanupFile(path, original_dir) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 70 | if not dst_path: |
| 71 | continue |
| 72 | |
| 73 | b.readFile( dst_path ) |
| 74 | r = b.editFile( dst_path, newdata ) |
| 75 | if r == 0: |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 76 | state = "unchanged" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 77 | elif r == 1: |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 78 | state = "edited" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 79 | else: |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 80 | state = "added" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 82 | str = "cleaning: %-*s -> %-*s (%s)" % ( 35, "<original>" + path[len(original_dir):], 35, dst_path, state ) |
| 83 | if sys.stdout.isatty(): |
| 84 | print "%-*s" % (oldlen,str), |
| 85 | if (r == 0): |
| 86 | print "\r", |
| 87 | else: |
| 88 | print "\n", |
| 89 | oldlen = 0 |
| 90 | else: |
| 91 | print str |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 93 | oldlen = len(str) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 94 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 95 | print "%-*s" % (oldlen,"Done!") |
| 96 | |
| 97 | b.updateGitFiles() |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 98 | |
Christopher Ferris | 38062f9 | 2014-07-09 15:33:25 -0700 | [diff] [blame] | 99 | if warning_ion: |
| 100 | print "NOTE: Due to import into aosp, some files were not processed." |
| 101 | print "\n".join(warning_ion) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 102 | sys.exit(0) |