Index: build/android/gyp/pack_arm_relocations.py |
diff --git a/build/android/gyp/pack_arm_relocations.py b/build/android/gyp/pack_arm_relocations.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..84df4f109c3a99c6d02001a08b1ebd4b4982679e |
--- /dev/null |
+++ b/build/android/gyp/pack_arm_relocations.py |
@@ -0,0 +1,88 @@ |
+#!/usr/bin/env python |
+# |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
rmcilroy
2014/06/27 11:14:54
nit - please add a docstring comment here describi
simonb (inactive)
2014/06/30 16:23:23
Done.
|
+import json |
+import optparse |
+import os |
+import shutil |
+import sys |
+import tempfile |
+ |
+from util import build_utils |
+ |
+ |
rmcilroy
2014/06/27 11:14:54
nit - single newline here (I believe, though still
simonb (inactive)
2014/06/30 16:23:23
Done.
|
+def PackArmLibraryRelocations(android_pack_relocations, |
+ android_objcopy, |
+ library_path, |
+ output_path): |
+ if not build_utils.IsTimeStale(output_path, [library_path]): |
+ return |
+ |
+ # Copy and add a 'NULL' .android.rel.dyn section for the packing tool. |
+ 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
|
+ stream.write('NULL') |
+ stream.flush() |
+ objcopy_command = [android_objcopy, |
+ '--add-section', '.android.rel.dyn=%s' % stream.name, |
+ library_path, output_path] |
+ build_utils.CheckOutput(objcopy_command) |
+ |
+ # Pack R_ARM_RELATIVE relocations. |
+ pack_command = [android_pack_relocations, output_path] |
+ build_utils.CheckOutput(pack_command) |
+ |
+ |
+def CopyArmLibraryUnchanged(library_path, output_path): |
+ if not build_utils.IsTimeStale(output_path, [library_path]): |
+ return |
+ |
+ shutil.copy(library_path, output_path) |
+ |
+ |
+def main(): |
+ parser = optparse.OptionParser() |
+ |
+ parser.add_option('--enable-packing', |
+ 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.
|
+ parser.add_option('--android-pack-relocations', |
+ help='Path to the ARM relocations packer binary') |
+ parser.add_option('--android-objcopy', |
+ help='Path to the toolchain\'s objcopy binary') |
+ parser.add_option('--stripped-libraries-dir', |
+ help='Directory for stripped libraries') |
+ parser.add_option('--packed-libraries-dir', |
+ help='Directory for packed libraries') |
+ parser.add_option('--libraries-file', |
+ help='Path to json file containing list of libraries') |
+ parser.add_option('--stamp', help='Path to touch on success') |
+ |
+ options, _ = parser.parse_args() |
+ enable_packing = options.enable_packing.lower() in ['true', 't', 'yes', '1'] |
+ |
+ with open(options.libraries_file, 'r') as libfile: |
+ libraries = json.load(libfile) |
+ |
+ for library in libraries: |
+ library_path = os.path.join(options.stripped_libraries_dir, library) |
+ output_path = os.path.join(options.packed_libraries_dir, library) |
+ |
+ 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.
|
+ PackArmLibraryRelocations(options.android_pack_relocations, |
+ options.android_objcopy, |
+ library_path, |
+ output_path) |
+ else: |
+ CopyArmLibraryUnchanged(library_path, output_path) |
+ |
+ |
+ if options.stamp: |
+ build_utils.Touch(options.stamp) |
+ |
+ return 0 |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |