Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
|
rmcilroy
2014/06/27 11:14:54
nit - please add a docstring comment here describi
simonb (inactive)
2014/06/30 16:23:23
Done.
| |
| 7 import json | |
| 8 import optparse | |
| 9 import os | |
| 10 import shutil | |
| 11 import sys | |
| 12 import tempfile | |
| 13 | |
| 14 from util import build_utils | |
| 15 | |
| 16 | |
|
rmcilroy
2014/06/27 11:14:54
nit - single newline here (I believe, though still
simonb (inactive)
2014/06/30 16:23:23
Done.
| |
| 17 def PackArmLibraryRelocations(android_pack_relocations, | |
| 18 android_objcopy, | |
| 19 library_path, | |
| 20 output_path): | |
| 21 if not build_utils.IsTimeStale(output_path, [library_path]): | |
| 22 return | |
| 23 | |
| 24 # Copy and add a 'NULL' .android.rel.dyn section for the packing tool. | |
| 25 with tempfile.NamedTemporaryFile() as stream: | |
|
rmcilroy
2014/06/27 11:14:54
nit - /s/stream/section_contents_tmp
simonb (inactive)
2014/06/30 16:23:23
Doesn't seem to offer much benefit. Let me know i
rmcilroy
2014/07/01 11:13:02
To me it makes the code more readable. "stream.wr
| |
| 26 stream.write('NULL') | |
| 27 stream.flush() | |
| 28 objcopy_command = [android_objcopy, | |
| 29 '--add-section', '.android.rel.dyn=%s' % stream.name, | |
| 30 library_path, output_path] | |
| 31 build_utils.CheckOutput(objcopy_command) | |
| 32 | |
| 33 # Pack R_ARM_RELATIVE relocations. | |
| 34 pack_command = [android_pack_relocations, output_path] | |
| 35 build_utils.CheckOutput(pack_command) | |
| 36 | |
| 37 | |
| 38 def CopyArmLibraryUnchanged(library_path, output_path): | |
| 39 if not build_utils.IsTimeStale(output_path, [library_path]): | |
| 40 return | |
| 41 | |
| 42 shutil.copy(library_path, output_path) | |
| 43 | |
| 44 | |
| 45 def main(): | |
| 46 parser = optparse.OptionParser() | |
| 47 | |
| 48 parser.add_option('--enable-packing', | |
| 49 help='Pack relocations if true, otherwise plain file copy') | |
|
rmcilroy
2014/06/27 11:14:54
Pack relocations if '1', otherwise plain file copy
simonb (inactive)
2014/06/30 16:23:23
Done. Looks better, thanks.
| |
| 50 parser.add_option('--android-pack-relocations', | |
| 51 help='Path to the ARM relocations packer binary') | |
| 52 parser.add_option('--android-objcopy', | |
| 53 help='Path to the toolchain\'s objcopy binary') | |
| 54 parser.add_option('--stripped-libraries-dir', | |
| 55 help='Directory for stripped libraries') | |
| 56 parser.add_option('--packed-libraries-dir', | |
| 57 help='Directory for packed libraries') | |
| 58 parser.add_option('--libraries-file', | |
| 59 help='Path to json file containing list of libraries') | |
| 60 parser.add_option('--stamp', help='Path to touch on success') | |
| 61 | |
| 62 options, _ = parser.parse_args() | |
| 63 enable_packing = options.enable_packing.lower() in ['true', 't', 'yes', '1'] | |
| 64 | |
| 65 with open(options.libraries_file, 'r') as libfile: | |
| 66 libraries = json.load(libfile) | |
| 67 | |
| 68 for library in libraries: | |
| 69 library_path = os.path.join(options.stripped_libraries_dir, library) | |
| 70 output_path = os.path.join(options.packed_libraries_dir, library) | |
| 71 | |
| 72 if enable_packing and library != 'libchromium_android_linker.so': | |
|
rmcilroy
2014/06/27 11:14:54
This hardcoded name is getting sprinkled around th
simonb (inactive)
2014/06/30 16:23:23
Done.
| |
| 73 PackArmLibraryRelocations(options.android_pack_relocations, | |
| 74 options.android_objcopy, | |
| 75 library_path, | |
| 76 output_path) | |
| 77 else: | |
| 78 CopyArmLibraryUnchanged(library_path, output_path) | |
| 79 | |
| 80 | |
| 81 if options.stamp: | |
| 82 build_utils.Touch(options.stamp) | |
| 83 | |
| 84 return 0 | |
| 85 | |
| 86 | |
| 87 if __name__ == '__main__': | |
| 88 sys.exit(main()) | |
| OLD | NEW |