1#!/usr/bin/env python 2# 3import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess, shutil 4from defaults import * 5from utils import * 6 7def usage(): 8 print """\ 9 usage: %(progname)s [kernel-original-path] [kernel-modified-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 15 'external/kernel-headers/original', relative to the current 16 android tree 17 18 - a set of manually modified kernel header files located in 19 'external/kernel-headers/modified', relative to the current 20 android tree 21 22 - the clean headers will be placed in 'bionic/libc/kernel/arch-<arch>/asm', 23 'bionic/libc/kernel/android', etc.. 24""" % { "progname" : os.path.basename(sys.argv[0]) } 25 sys.exit(0) 26 27def processFiles(updater, original_dir, modified_dir, src_rel_dir, update_rel_dir): 28 # Delete the old headers before updating to the new headers. 29 update_dir = os.path.join(get_kernel_dir(), update_rel_dir) 30 shutil.rmtree(update_dir) 31 os.mkdir(update_dir, 0755) 32 33 src_dir = os.path.normpath(os.path.join(original_dir, src_rel_dir)) 34 src_dir_len = len(src_dir) + 1 35 mod_src_dir = os.path.join(modified_dir, src_rel_dir) 36 update_dir = os.path.join(get_kernel_dir(), update_rel_dir) 37 38 kernel_dir = get_kernel_dir() 39 for root, _, files in os.walk(src_dir): 40 for file in sorted(files): 41 _, ext = os.path.splitext(file) 42 if ext != ".h": 43 continue 44 src_file = os.path.normpath(os.path.join(root, file)) 45 rel_path = src_file[src_dir_len:] 46 # Check to see if there is a modified header to use instead. 47 if os.path.exists(os.path.join(mod_src_dir, rel_path)): 48 src_file = os.path.join(mod_src_dir, rel_path) 49 src_str = os.path.join("<modified>", src_rel_dir, rel_path) 50 else: 51 src_str = os.path.join("<original>", src_rel_dir, rel_path) 52 dst_file = os.path.join(update_dir, rel_path) 53 new_data = clean_header.cleanupFile(dst_file, src_file, rel_path) 54 if not new_data: 55 continue 56 updater.readFile(dst_file) 57 ret_val = updater.editFile(dst_file, new_data) 58 if ret_val == 0: 59 state = "unchanged" 60 elif ret_val == 1: 61 state = "edited" 62 else: 63 state = "added" 64 update_path = os.path.join(update_rel_dir, rel_path) 65 print "cleaning %s -> %s (%s)" % (src_str, update_path, state) 66 67try: 68 optlist, args = getopt.getopt(sys.argv[1:], '') 69except: 70 # Unrecognized option 71 sys.stderr.write("error: unrecognized option\n") 72 usage() 73 74if len(optlist) > 0 or len(args) > 2: 75 usage() 76 77if len(args) > 0: 78 original_dir = args[0] 79else: 80 original_dir = get_kernel_headers_original_dir() 81 82if len(args) > 1: 83 modified_dir = args[1] 84else: 85 modified_dir = get_kernel_headers_modified_dir() 86 87if not os.path.isdir(original_dir): 88 panic("The kernel directory %s is not a directory\n" % original_dir) 89 90if not os.path.isdir(modified_dir): 91 panic("The kernel modified directory %s is not a directory\n" % modified_dir) 92 93updater = BatchFileUpdater() 94# Process the original uapi headers first. 95processFiles(updater, original_dir, modified_dir, "uapi", "uapi"), 96 97# Now process the special files. 98processFiles(updater, original_dir, modified_dir, "scsi", os.path.join("android", "scsi", "scsi")) 99 100updater.updateGitFiles() 101