Chromium Code Reviews| Index: build/android/gyp/jar_toc.py |
| diff --git a/build/android/gyp/jar_toc.py b/build/android/gyp/jar_toc.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..1df44d687f0838b57bbd195c1e14718c829b6be5 |
| --- /dev/null |
| +++ b/build/android/gyp/jar_toc.py |
| @@ -0,0 +1,97 @@ |
| +#!/usr/bin/env python |
| +# |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +""" Creates a TOC file from a Java jar. |
|
nilesh
2013/04/12 01:09:52
New line after copyright.
cjhopman
2013/04/12 23:09:48
Done.
|
| + |
| +The TOC file contains the non-package API of the jar. This includes all |
| +public/protected classes/functions/members and the values of static final |
| +variables. Some other information (major/minor javac version) is also included. |
| + |
| +This TOC file then can be used to determine if a dependent library should be |
| +rebuilt when this jar changes. I.e. any change to the jar that would require a |
| +rebuild, will have a corresponding change in the TOC file. |
| +""" |
| + |
| +import optparse |
| +import os |
| +import re |
| +import sys |
| +import zipfile |
| + |
| +from util import build_utils |
| +from util import md5_check |
| + |
| +def CreateToc(jar_path, toc_path): |
| + jar = zipfile.ZipFile(jar_path) |
| + classes = [] |
| + files = jar.namelist() |
| + for f in files: |
| + if f.endswith('.class'): |
| + # f is of the form org/chromium/base/Class$Inner.class |
| + classes.append(f.replace('/', '.')[:-6]) |
| + |
| + javap_cmd = [ |
| + 'javap', |
| + '-public', |
| + '-protected', |
| + # -verbose is required to get constant values (which can be inlined in |
| + # dependents). |
| + '-verbose', |
| + '-classpath', jar_path |
| + ] + classes |
| + output = build_utils.CheckCallDie(javap_cmd, suppress_output=True) |
| + |
| + # javap output is structured by indent (2-space) levels. |
| + good_patterns = [ |
| + '^[^ ]', # This includes all class/function/member signatures. |
| + '^ SourceFile:', |
| + '^ minor version:', |
| + '^ major version:', |
| + '^ Constant value:', |
| + ] |
| + bad_patterns = [ |
| + '^const #', # Matches the constant pool (i.e. literals used in the class). |
| + ] |
| + def JavapFilter(line): |
|
nilesh
2013/04/12 01:09:52
newline before def
cjhopman
2013/04/12 23:09:48
Done.
|
| + return (re.match('|'.join(good_patterns), line) and |
| + not re.match('|'.join(bad_patterns), line)) |
| + filtered_output = filter(JavapFilter, output.split('\n')) |
| + |
| + with open(toc_path, 'w') as tocfile: |
| + tocfile.write('\n'.join(filtered_output)) |
| + |
| + |
| +def DoJarToc(options): |
| + jar_path = options.jar_path |
| + toc_path = jar_path + '.TOC' |
| + md5_stamp = '%s.md5' % toc_path |
|
nilesh
2013/04/12 01:09:52
md5_stamp_path
cjhopman
2013/04/12 23:09:48
Done.
|
| + md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=[jar_path]) |
| + if md5_checker.IsStale(): |
|
nilesh
2013/04/12 01:09:52
Add comment:
# Update the toc file and timestamp.
cjhopman
2013/04/12 23:09:48
Done... kind of. Renamed function to UpdateToc(...
|
| + CreateToc(jar_path, toc_path) |
| + else: |
| + build_utils.Touch(toc_path) |
| + md5_checker.Write() |
|
nilesh
2013/04/12 01:09:52
Do this only if isstale
cjhopman
2013/04/12 23:09:48
Done.
|
| + |
| + |
| +def main(argv): |
| + parser = optparse.OptionParser() |
| + parser.add_option('--jar-path', help='Input .jar path.') |
| + parser.add_option('--toc-path', help='Output .jar.TOC path.') |
|
nilesh
2013/04/12 01:09:52
where is options.toc_path used? I see that you com
cjhopman
2013/04/12 23:09:48
It's now used, it should not have been computed fr
|
| + parser.add_option('--stamp', help='Path to touch on success.') |
| + |
| + # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. |
| + parser.add_option('--ignore', help='Ignored.') |
| + |
| + options, _ = parser.parse_args() |
| + |
| + DoJarToc(options) |
| + |
| + if options.stamp: |
| + build_utils.Touch(options.stamp) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv)) |
| + |