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 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 for old, new in JniParams._remappings: | 317 for old, new in JniParams._remappings: |
318 if old in class_name: | 318 if old in class_name: |
319 return class_name.replace(old, new, 1) | 319 return class_name.replace(old, new, 1) |
320 return class_name | 320 return class_name |
321 | 321 |
322 @staticmethod | 322 @staticmethod |
323 def SetJarJarMappings(mappings): | 323 def SetJarJarMappings(mappings): |
324 """Parse jarjar mappings from a string.""" | 324 """Parse jarjar mappings from a string.""" |
325 JniParams._remappings = [] | 325 JniParams._remappings = [] |
326 for line in mappings.splitlines(): | 326 for line in mappings.splitlines(): |
327 keyword, src, dest = line.split() | 327 rule = line.split() |
328 if keyword != 'rule': | 328 if rule[0] != 'rule': |
329 continue | 329 continue |
330 assert src.endswith('.**') | 330 _, src, dest = rule |
| 331 assert src.endswith('**') |
331 src = src[:-2].replace('.', '/') | 332 src = src[:-2].replace('.', '/') |
332 dest = dest.replace('.', '/') | 333 dest = dest.replace('.', '/') |
| 334 |
333 if dest.endswith('@0'): | 335 if dest.endswith('@0'): |
334 JniParams._remappings.append((src, dest[:-2] + src)) | 336 JniParams._remappings.append((src, dest[:-2] + src)) |
335 else: | 337 else: |
336 assert dest.endswith('@1') | 338 assert dest.endswith('@1') |
337 JniParams._remappings.append((src, dest[:-2])) | 339 JniParams._remappings.append((src, dest[:-2])) |
338 | 340 |
339 | 341 |
340 def ExtractJNINamespace(contents): | 342 def ExtractJNINamespace(contents): |
341 re_jni_namespace = re.compile('.*?@JNINamespace\("(.*?)"\)') | 343 re_jni_namespace = re.compile('.*?@JNINamespace\("(.*?)"\)') |
342 m = re.findall(re_jni_namespace, contents) | 344 m = re.findall(re_jni_namespace, contents) |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 root_name = os.path.splitext(os.path.basename(input_file))[0] | 1388 root_name = os.path.splitext(os.path.basename(input_file))[0] |
1387 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1389 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
1388 if options.jarjar: | 1390 if options.jarjar: |
1389 with open(options.jarjar) as f: | 1391 with open(options.jarjar) as f: |
1390 JniParams.SetJarJarMappings(f.read()) | 1392 JniParams.SetJarJarMappings(f.read()) |
1391 GenerateJNIHeader(input_file, output_file, options) | 1393 GenerateJNIHeader(input_file, output_file, options) |
1392 | 1394 |
1393 | 1395 |
1394 if __name__ == '__main__': | 1396 if __name__ == '__main__': |
1395 sys.exit(main(sys.argv)) | 1397 sys.exit(main(sys.argv)) |
OLD | NEW |