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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 datatype=items[0], | 330 datatype=items[0], |
331 name=(items[1] if len(items) > 1 else 'p%s' % len(ret)), | 331 name=(items[1] if len(items) > 1 else 'p%s' % len(ret)), |
332 ) | 332 ) |
333 ret += [param] | 333 ret += [param] |
334 return ret | 334 return ret |
335 | 335 |
336 @staticmethod | 336 @staticmethod |
337 def RemapClassName(class_name): | 337 def RemapClassName(class_name): |
338 """Remaps class names using the jarjar mapping table.""" | 338 """Remaps class names using the jarjar mapping table.""" |
339 for old, new in JniParams._remappings: | 339 for old, new in JniParams._remappings: |
340 if old in class_name: | 340 if old.endswith('**') and old[:-2] in class_name: |
| 341 return class_name.replace(old[:-2], new, 1) |
| 342 if '*' not in old and class_name.endswith(old): |
341 return class_name.replace(old, new, 1) | 343 return class_name.replace(old, new, 1) |
| 344 |
342 return class_name | 345 return class_name |
343 | 346 |
344 @staticmethod | 347 @staticmethod |
345 def SetJarJarMappings(mappings): | 348 def SetJarJarMappings(mappings): |
346 """Parse jarjar mappings from a string.""" | 349 """Parse jarjar mappings from a string.""" |
347 JniParams._remappings = [] | 350 JniParams._remappings = [] |
348 for line in mappings.splitlines(): | 351 for line in mappings.splitlines(): |
349 keyword, src, dest = line.split() | 352 rule = line.split() |
350 if keyword != 'rule': | 353 if rule[0] != 'rule': |
351 continue | 354 continue |
352 assert src.endswith('.**') | 355 _, src, dest = rule |
353 src = src[:-2].replace('.', '/') | 356 src = src.replace('.', '/') |
354 dest = dest.replace('.', '/') | 357 dest = dest.replace('.', '/') |
| 358 if src.endswith('**'): |
| 359 src_real_name = src[:-2] |
| 360 else: |
| 361 assert not '*' in src |
| 362 src_real_name = src |
| 363 |
355 if dest.endswith('@0'): | 364 if dest.endswith('@0'): |
356 JniParams._remappings.append((src, dest[:-2] + src)) | 365 JniParams._remappings.append((src, dest[:-2] + src_real_name)) |
| 366 elif dest.endswith('@1'): |
| 367 assert '**' in src |
| 368 JniParams._remappings.append((src, dest[:-2])) |
357 else: | 369 else: |
358 assert dest.endswith('@1') | 370 assert not '@' in dest |
359 JniParams._remappings.append((src, dest[:-2])) | 371 JniParams._remappings.append((src, dest)) |
360 | 372 |
361 | 373 |
362 def ExtractJNINamespace(contents): | 374 def ExtractJNINamespace(contents): |
363 re_jni_namespace = re.compile('.*?@JNINamespace\("(.*?)"\)') | 375 re_jni_namespace = re.compile('.*?@JNINamespace\("(.*?)"\)') |
364 m = re.findall(re_jni_namespace, contents) | 376 m = re.findall(re_jni_namespace, contents) |
365 if not m: | 377 if not m: |
366 return '' | 378 return '' |
367 return m[0] | 379 return m[0] |
368 | 380 |
369 | 381 |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 root_name = os.path.splitext(os.path.basename(input_file))[0] | 1421 root_name = os.path.splitext(os.path.basename(input_file))[0] |
1410 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1422 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
1411 if options.jarjar: | 1423 if options.jarjar: |
1412 with open(options.jarjar) as f: | 1424 with open(options.jarjar) as f: |
1413 JniParams.SetJarJarMappings(f.read()) | 1425 JniParams.SetJarJarMappings(f.read()) |
1414 GenerateJNIHeader(input_file, output_file, options) | 1426 GenerateJNIHeader(input_file, output_file, options) |
1415 | 1427 |
1416 | 1428 |
1417 if __name__ == '__main__': | 1429 if __name__ == '__main__': |
1418 sys.exit(main(sys.argv)) | 1430 sys.exit(main(sys.argv)) |
OLD | NEW |