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 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 return os.sep.join(script_components[base_index:]) | 1341 return os.sep.join(script_components[base_index:]) |
1333 | 1342 |
1334 | 1343 |
1335 def main(argv): | 1344 def main(argv): |
1336 usage = """usage: %prog [OPTIONS] | 1345 usage = """usage: %prog [OPTIONS] |
1337 This script will parse the given java source code extracting the native | 1346 This script will parse the given java source code extracting the native |
1338 declarations and print the header file to stdout (or a file). | 1347 declarations and print the header file to stdout (or a file). |
1339 See SampleForTests.java for more details. | 1348 See SampleForTests.java for more details. |
1340 """ | 1349 """ |
1341 option_parser = optparse.OptionParser(usage=usage) | 1350 option_parser = optparse.OptionParser(usage=usage) |
| 1351 build_utils.AddDepfileOption(option_parser) |
| 1352 |
1342 option_parser.add_option('-j', '--jar_file', dest='jar_file', | 1353 option_parser.add_option('-j', '--jar_file', dest='jar_file', |
1343 help='Extract the list of input files from' | 1354 help='Extract the list of input files from' |
1344 ' a specified jar file.' | 1355 ' a specified jar file.' |
1345 ' Uses javap to extract the methods from a' | 1356 ' Uses javap to extract the methods from a' |
1346 ' pre-compiled class. --input should point' | 1357 ' pre-compiled class. --input should point' |
1347 ' to pre-compiled Java .class files.') | 1358 ' to pre-compiled Java .class files.') |
1348 option_parser.add_option('-n', dest='namespace', | 1359 option_parser.add_option('-n', dest='namespace', |
1349 help='Uses as a namespace in the generated header ' | 1360 help='Uses as a namespace in the generated header ' |
1350 'instead of the javap class name, or when there is ' | 1361 'instead of the javap class name, or when there is ' |
1351 'no JNINamespace annotation in the java source.') | 1362 'no JNINamespace annotation in the java source.') |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 return 1 | 1417 return 1 |
1407 output_file = None | 1418 output_file = None |
1408 if options.output_dir: | 1419 if options.output_dir: |
1409 root_name = os.path.splitext(os.path.basename(input_file))[0] | 1420 root_name = os.path.splitext(os.path.basename(input_file))[0] |
1410 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1421 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
1411 if options.jarjar: | 1422 if options.jarjar: |
1412 with open(options.jarjar) as f: | 1423 with open(options.jarjar) as f: |
1413 JniParams.SetJarJarMappings(f.read()) | 1424 JniParams.SetJarJarMappings(f.read()) |
1414 GenerateJNIHeader(input_file, output_file, options) | 1425 GenerateJNIHeader(input_file, output_file, options) |
1415 | 1426 |
| 1427 if options.depfile: |
| 1428 build_utils.WriteDepfile( |
| 1429 options.depfile, |
| 1430 build_utils.GetPythonDependencies()) |
| 1431 |
1416 | 1432 |
1417 if __name__ == '__main__': | 1433 if __name__ == '__main__': |
1418 sys.exit(main(sys.argv)) | 1434 sys.exit(main(sys.argv)) |
OLD | NEW |