summaryrefslogtreecommitdiffstats
path: root/libc/kernel/tools/update_all.py
blob: 73862da17d4b7badf64df68fc3984b246d23065a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
#
import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
from defaults import *
from utils import *

def usage():
    print """\
  usage: %(progname)s [kernel-original-path]

    this program is used to update all the auto-generated clean headers
    used by the Bionic C library. it assumes the following:

      - a set of source kernel headers is located in '../original',
        relative to the program's directory

      - the clean headers will be placed in '../arch-<arch>/asm',
        '../common/linux', '../common/asm-generic', etc..
""" % { "progname" : os.path.basename(sys.argv[0]) }
    sys.exit(0)

try:
    optlist, args = getopt.getopt( sys.argv[1:], '' )
except:
    # unrecognized option
    sys.stderr.write( "error: unrecognized option\n" )
    usage()

if len(optlist) > 0 or len(args) > 1:
    usage()

progdir = find_program_dir()

if len(args) == 1:
    original_dir = args[0]
    if not os.path.isdir(original_dir):
        panic( "Not a directory: %s\n" % original_dir )
else:
    original_dir = kernel_original_path
    if not os.path.isdir(original_dir):
        panic( "Missing directory, please specify one through command-line: %s\n" % original_dir )

# Fixme: This should be removed after next release.
# Do not update ion.h ion_test.h until after next release in aosp.
source = subprocess.check_output('git remote show', shell=True).strip()
skip_ion = False
if source == "aosp":
    skip_ion = True

# find all source files in 'original'
#
sources = []
warning_ion = []
for root, dirs, files in os.walk( original_dir ):
    for file in files:
        if skip_ion and (file == "ion.h" or file == "ion_test.h"):
            warning_ion.append("  Skipped file %s/%s" % (root, file))
            continue
        base, ext = os.path.splitext(file)
        if ext == ".h":
            sources.append( "%s/%s" % (root,file) )

b = BatchFileUpdater()

for arch in kernel_archs:
    b.readDir( os.path.normpath( progdir + "/../arch-%s" % arch ) )

b.readDir( os.path.normpath( progdir + "/../common" ) )

#print "OLD " + repr(b.old_files)

oldlen = 120
for path in sources:
    dst_path, newdata = clean_header.cleanupFile(path, original_dir)
    if not dst_path:
        continue

    b.readFile( dst_path )
    r = b.editFile( dst_path, newdata )
    if r == 0:
        state = "unchanged"
    elif r == 1:
        state = "edited"
    else:
        state = "added"

    str = "cleaning: %-*s -> %-*s (%s)" % ( 35, "<original>" + path[len(original_dir):], 35, dst_path, state )
    if sys.stdout.isatty():
        print "%-*s" % (oldlen,str),
        if (r == 0):
            print "\r",
        else:
            print "\n",
            oldlen = 0
    else:
        print str

    oldlen = len(str)

print "%-*s" % (oldlen,"Done!")

b.updateGitFiles()

if warning_ion:
    print "NOTE: Due to import into aosp, some files were not processed."
    print "\n".join(warning_ion)
sys.exit(0)