The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | import sys, cpp, kernel, glob, os, re, getopt, clean_header |
| 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.. |
| 19 | |
| 20 | - if ANDROID_PRODUCT_OUT is defined in your environment, you're |
| 21 | using the Android build system, and the program will issue |
| 22 | p4 add / edit / delete commands to update the depot for you. |
| 23 | (you'll need to p4 submit manually though) |
| 24 | """ % { "progname" : os.path.basename(sys.argv[0]) } |
| 25 | sys.exit(0) |
| 26 | |
| 27 | try: |
| 28 | optlist, args = getopt.getopt( sys.argv[1:], '' ) |
| 29 | except: |
| 30 | # unrecognized option |
| 31 | sys.stderr.write( "error: unrecognized option\n" ) |
| 32 | usage() |
| 33 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 34 | if len(optlist) > 0 or len(args) > 1: |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | usage() |
| 36 | |
| 37 | progdir = find_program_dir() |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 38 | |
| 39 | if len(args) == 1: |
Glenn Kasten | c61f990 | 2011-12-19 11:27:50 -0800 | [diff] [blame^] | 40 | original_dir = args[0] |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 41 | if not os.path.isdir(original_dir): |
Glenn Kasten | c61f990 | 2011-12-19 11:27:50 -0800 | [diff] [blame^] | 42 | panic( "Not a directory: %s\n" % original_dir ) |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 43 | else: |
| 44 | original_dir = kernel_original_path |
| 45 | if not os.path.isdir(original_dir): |
Glenn Kasten | c61f990 | 2011-12-19 11:27:50 -0800 | [diff] [blame^] | 46 | 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] | 47 | |
| 48 | # find all source files in 'original' |
| 49 | # |
| 50 | sources = [] |
| 51 | for root, dirs, files in os.walk( original_dir ): |
| 52 | for file in files: |
| 53 | base, ext = os.path.splitext(file) |
| 54 | if ext == ".h": |
| 55 | sources.append( "%s/%s" % (root,file) ) |
| 56 | |
| 57 | b = BatchFileUpdater() |
| 58 | |
| 59 | for arch in kernel_archs: |
| 60 | b.readDir( os.path.normpath( progdir + "/../arch-%s" % arch ) ) |
| 61 | |
| 62 | b.readDir( os.path.normpath( progdir + "/../common" ) ) |
| 63 | |
| 64 | #print "OLD " + repr(b.old_files) |
| 65 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 66 | oldlen = 120 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 67 | for path in sources: |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 68 | dst_path, newdata = clean_header.cleanupFile(path, original_dir) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 69 | if not dst_path: |
| 70 | continue |
| 71 | |
| 72 | b.readFile( dst_path ) |
| 73 | r = b.editFile( dst_path, newdata ) |
| 74 | if r == 0: |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 75 | state = "unchanged" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 76 | elif r == 1: |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 77 | state = "edited" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 78 | else: |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 79 | state = "added" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 80 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 81 | str = "cleaning: %-*s -> %-*s (%s)" % ( 35, "<original>" + path[len(original_dir):], 35, dst_path, state ) |
| 82 | if sys.stdout.isatty(): |
| 83 | print "%-*s" % (oldlen,str), |
| 84 | if (r == 0): |
| 85 | print "\r", |
| 86 | else: |
| 87 | print "\n", |
| 88 | oldlen = 0 |
| 89 | else: |
| 90 | print str |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 91 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 92 | oldlen = len(str) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 93 | |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 94 | print "%-*s" % (oldlen,"Done!") |
| 95 | |
| 96 | b.updateGitFiles() |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 97 | |
| 98 | sys.exit(0) |