• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
4from defaults import *
5from utils import *
6
7def 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
22try:
23    optlist, args = getopt.getopt( sys.argv[1:], '' )
24except:
25    # unrecognized option
26    sys.stderr.write( "error: unrecognized option\n" )
27    usage()
28
29if len(optlist) > 0 or len(args) > 1:
30    usage()
31
32progdir = find_program_dir()
33
34if 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 )
38else:
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
43skip_ion = False
44
45# find all source files in 'original'
46#
47sources = []
48warning_ion = []
49for root, dirs, files in os.walk( original_dir ):
50    for file in files:
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
54        base, ext = os.path.splitext(file)
55        if ext == ".h":
56            sources.append( "%s/%s" % (root,file) )
57
58b = BatchFileUpdater()
59
60for arch in kernel_archs:
61    b.readDir( os.path.normpath( progdir + "/../arch-%s" % arch ) )
62
63b.readDir( os.path.normpath( progdir + "/../common" ) )
64
65#print "OLD " + repr(b.old_files)
66
67oldlen = 120
68for path in sources:
69    dst_path, newdata = clean_header.cleanupFile(path, original_dir)
70    if not dst_path:
71        continue
72
73    b.readFile( dst_path )
74    r = b.editFile( dst_path, newdata )
75    if r == 0:
76        state = "unchanged"
77    elif r == 1:
78        state = "edited"
79    else:
80        state = "added"
81
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
92
93    oldlen = len(str)
94
95print "%-*s" % (oldlen,"Done!")
96
97b.updateGitFiles()
98
99if warning_ion:
100    print "NOTE: Due to import into aosp, some files were not processed."
101    print "\n".join(warning_ion)
102sys.exit(0)
103