OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Extracts native methods from a Java file and generates the JNI bindings. | 6 """Extracts native methods from a Java file and generates the JNI bindings. |
7 If you change this, please run and update the tests.""" | 7 If you change this, please run and update the tests.""" |
8 | 8 |
9 import collections | 9 import collections |
10 import errno | 10 import errno |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import re | 13 import re |
14 import string | 14 import string |
15 from string import Template | 15 from string import Template |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 import textwrap | 18 import textwrap |
19 import zipfile | 19 import zipfile |
20 | 20 |
| 21 CHROMIUM_SRC = os.path.join( |
| 22 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir) |
| 23 BUILD_ANDROID_GYP = os.path.join( |
| 24 CHROMIUM_SRC, 'build', 'android', 'gyp') |
| 25 |
| 26 sys.path.append(BUILD_ANDROID_GYP) |
| 27 |
| 28 from util import build_utils |
| 29 |
21 | 30 |
22 class ParseError(Exception): | 31 class ParseError(Exception): |
23 """Exception thrown when we can't parse the input file.""" | 32 """Exception thrown when we can't parse the input file.""" |
24 | 33 |
25 def __init__(self, description, *context_lines): | 34 def __init__(self, description, *context_lines): |
26 Exception.__init__(self) | 35 Exception.__init__(self) |
27 self.description = description | 36 self.description = description |
28 self.context_lines = context_lines | 37 self.context_lines = context_lines |
29 | 38 |
30 def __str__(self): | 39 def __str__(self): |
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 return os.sep.join(script_components[base_index:]) | 1353 return os.sep.join(script_components[base_index:]) |
1345 | 1354 |
1346 | 1355 |
1347 def main(argv): | 1356 def main(argv): |
1348 usage = """usage: %prog [OPTIONS] | 1357 usage = """usage: %prog [OPTIONS] |
1349 This script will parse the given java source code extracting the native | 1358 This script will parse the given java source code extracting the native |
1350 declarations and print the header file to stdout (or a file). | 1359 declarations and print the header file to stdout (or a file). |
1351 See SampleForTests.java for more details. | 1360 See SampleForTests.java for more details. |
1352 """ | 1361 """ |
1353 option_parser = optparse.OptionParser(usage=usage) | 1362 option_parser = optparse.OptionParser(usage=usage) |
| 1363 build_utils.AddDepfileOption(option_parser) |
| 1364 |
1354 option_parser.add_option('-j', '--jar_file', dest='jar_file', | 1365 option_parser.add_option('-j', '--jar_file', dest='jar_file', |
1355 help='Extract the list of input files from' | 1366 help='Extract the list of input files from' |
1356 ' a specified jar file.' | 1367 ' a specified jar file.' |
1357 ' Uses javap to extract the methods from a' | 1368 ' Uses javap to extract the methods from a' |
1358 ' pre-compiled class. --input should point' | 1369 ' pre-compiled class. --input should point' |
1359 ' to pre-compiled Java .class files.') | 1370 ' to pre-compiled Java .class files.') |
1360 option_parser.add_option('-n', dest='namespace', | 1371 option_parser.add_option('-n', dest='namespace', |
1361 help='Uses as a namespace in the generated header ' | 1372 help='Uses as a namespace in the generated header ' |
1362 'instead of the javap class name, or when there is ' | 1373 'instead of the javap class name, or when there is ' |
1363 'no JNINamespace annotation in the java source.') | 1374 'no JNINamespace annotation in the java source.') |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 return 1 | 1429 return 1 |
1419 output_file = None | 1430 output_file = None |
1420 if options.output_dir: | 1431 if options.output_dir: |
1421 root_name = os.path.splitext(os.path.basename(input_file))[0] | 1432 root_name = os.path.splitext(os.path.basename(input_file))[0] |
1422 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1433 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
1423 if options.jarjar: | 1434 if options.jarjar: |
1424 with open(options.jarjar) as f: | 1435 with open(options.jarjar) as f: |
1425 JniParams.SetJarJarMappings(f.read()) | 1436 JniParams.SetJarJarMappings(f.read()) |
1426 GenerateJNIHeader(input_file, output_file, options) | 1437 GenerateJNIHeader(input_file, output_file, options) |
1427 | 1438 |
| 1439 if options.depfile: |
| 1440 build_utils.WriteDepfile( |
| 1441 options.depfile, |
| 1442 build_utils.GetPythonDependencies()) |
| 1443 |
1428 | 1444 |
1429 if __name__ == '__main__': | 1445 if __name__ == '__main__': |
1430 sys.exit(main(sys.argv)) | 1446 sys.exit(main(sys.argv)) |
OLD | NEW |