| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Pack ARM relative relocations in a library (or copy unchanged). | 7 """Pack ARM relative relocations in a library (or copy unchanged). |
| 8 | 8 |
| 9 If --enable-packing and --configuration-name=='Release', invoke the | 9 If --enable-packing and --configuration-name=='Release', invoke the |
| 10 relocation_packer tool to pack the .rel.dyn or .rela.dyn section in the given | 10 relocation_packer tool to pack the .rel.dyn or .rela.dyn section in the given |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 import sys | 28 import sys |
| 29 import tempfile | 29 import tempfile |
| 30 | 30 |
| 31 from util import build_utils | 31 from util import build_utils |
| 32 | 32 |
| 33 def PackArmLibraryRelocations(android_pack_relocations, | 33 def PackArmLibraryRelocations(android_pack_relocations, |
| 34 android_objcopy, | 34 android_objcopy, |
| 35 has_relocations_with_addends, | 35 has_relocations_with_addends, |
| 36 library_path, | 36 library_path, |
| 37 output_path): | 37 output_path): |
| 38 if not build_utils.IsTimeStale(output_path, [library_path]): | |
| 39 return | |
| 40 | |
| 41 # Select an appropriate name for the section we add. | 38 # Select an appropriate name for the section we add. |
| 42 if has_relocations_with_addends: | 39 if has_relocations_with_addends: |
| 43 new_section = '.android.rela.dyn' | 40 new_section = '.android.rela.dyn' |
| 44 else: | 41 else: |
| 45 new_section = '.android.rel.dyn' | 42 new_section = '.android.rel.dyn' |
| 46 | 43 |
| 47 # Copy and add a 'NULL' packed relocations section for the packing tool. | 44 # Copy and add a 'NULL' packed relocations section for the packing tool. |
| 48 with tempfile.NamedTemporaryFile() as stream: | 45 with tempfile.NamedTemporaryFile() as stream: |
| 49 stream.write('NULL') | 46 stream.write('NULL') |
| 50 stream.flush() | 47 stream.flush() |
| 51 objcopy_command = [android_objcopy, | 48 objcopy_command = [android_objcopy, |
| 52 '--add-section', '%s=%s' % (new_section, stream.name), | 49 '--add-section', '%s=%s' % (new_section, stream.name), |
| 53 library_path, output_path] | 50 library_path, output_path] |
| 54 build_utils.CheckOutput(objcopy_command) | 51 build_utils.CheckOutput(objcopy_command) |
| 55 | 52 |
| 56 # Pack R_ARM_RELATIVE relocations. | 53 # Pack R_ARM_RELATIVE relocations. |
| 57 pack_command = [android_pack_relocations, output_path] | 54 pack_command = [android_pack_relocations, output_path] |
| 58 build_utils.CheckOutput(pack_command) | 55 build_utils.CheckOutput(pack_command) |
| 59 | 56 |
| 60 | 57 |
| 61 def CopyArmLibraryUnchanged(library_path, output_path): | 58 def CopyArmLibraryUnchanged(library_path, output_path): |
| 62 if not build_utils.IsTimeStale(output_path, [library_path]): | |
| 63 return | |
| 64 | |
| 65 shutil.copy(library_path, output_path) | 59 shutil.copy(library_path, output_path) |
| 66 | 60 |
| 67 | 61 |
| 68 def main(args): | 62 def main(args): |
| 69 args = build_utils.ExpandFileArgs(args) | 63 args = build_utils.ExpandFileArgs(args) |
| 70 parser = optparse.OptionParser() | 64 parser = optparse.OptionParser() |
| 65 build_utils.AddDepfileOption(parser) |
| 66 parser.add_option('--clear-dir', action='store_true', |
| 67 help='If set, the destination directory will be deleted ' |
| 68 'before copying files to it. This is highly recommended to ' |
| 69 'ensure that no stale files are left in the directory.') |
| 71 | 70 |
| 72 parser.add_option('--configuration-name', | 71 parser.add_option('--configuration-name', |
| 73 default='Release', | 72 default='Release', |
| 74 help='Gyp configuration name (i.e. Debug, Release)') | 73 help='Gyp configuration name (i.e. Debug, Release)') |
| 75 parser.add_option('--enable-packing', | 74 parser.add_option('--enable-packing', |
| 76 choices=['0', '1'], | 75 choices=['0', '1'], |
| 77 help=('Pack relocations if 1 and configuration name is \'Release\',' | 76 help=('Pack relocations if 1 and configuration name is \'Release\',' |
| 78 ' otherwise plain file copy')) | 77 ' otherwise plain file copy')) |
| 79 parser.add_option('--has-relocations-with-addends', | 78 parser.add_option('--has-relocations-with-addends', |
| 80 choices=['0', '1'], | 79 choices=['0', '1'], |
| (...skipping 14 matching lines...) Expand all Loading... |
| 95 parser.add_option('--stamp', help='Path to touch on success') | 94 parser.add_option('--stamp', help='Path to touch on success') |
| 96 | 95 |
| 97 options, _ = parser.parse_args(args) | 96 options, _ = parser.parse_args(args) |
| 98 enable_packing = (options.enable_packing == '1' and | 97 enable_packing = (options.enable_packing == '1' and |
| 99 options.configuration_name == 'Release') | 98 options.configuration_name == 'Release') |
| 100 has_relocations_with_addends = (options.has_relocations_with_addends == '1') | 99 has_relocations_with_addends = (options.has_relocations_with_addends == '1') |
| 101 exclude_packing_set = set(shlex.split(options.exclude_packing_list)) | 100 exclude_packing_set = set(shlex.split(options.exclude_packing_list)) |
| 102 | 101 |
| 103 libraries = build_utils.ParseGypList(options.libraries) | 102 libraries = build_utils.ParseGypList(options.libraries) |
| 104 | 103 |
| 104 if options.clear_dir: |
| 105 build_utils.DeleteDirectory(options.packed_libraries_dir) |
| 106 |
| 105 build_utils.MakeDirectory(options.packed_libraries_dir) | 107 build_utils.MakeDirectory(options.packed_libraries_dir) |
| 106 | 108 |
| 107 for library in libraries: | 109 for library in libraries: |
| 108 library_path = os.path.join(options.stripped_libraries_dir, library) | 110 library_path = os.path.join(options.stripped_libraries_dir, library) |
| 109 output_path = os.path.join(options.packed_libraries_dir, library) | 111 output_path = os.path.join( |
| 112 options.packed_libraries_dir, os.path.basename(library)) |
| 110 | 113 |
| 111 if enable_packing and library not in exclude_packing_set: | 114 if enable_packing and library not in exclude_packing_set: |
| 112 PackArmLibraryRelocations(options.android_pack_relocations, | 115 PackArmLibraryRelocations(options.android_pack_relocations, |
| 113 options.android_objcopy, | 116 options.android_objcopy, |
| 114 has_relocations_with_addends, | 117 has_relocations_with_addends, |
| 115 library_path, | 118 library_path, |
| 116 output_path) | 119 output_path) |
| 117 else: | 120 else: |
| 118 CopyArmLibraryUnchanged(library_path, output_path) | 121 CopyArmLibraryUnchanged(library_path, output_path) |
| 119 | 122 |
| 123 if options.depfile: |
| 124 build_utils.WriteDepfile( |
| 125 options.depfile, |
| 126 libraries + build_utils.GetPythonDependencies()) |
| 127 |
| 120 if options.stamp: | 128 if options.stamp: |
| 121 build_utils.Touch(options.stamp) | 129 build_utils.Touch(options.stamp) |
| 122 | 130 |
| 123 return 0 | 131 return 0 |
| 124 | 132 |
| 125 | 133 |
| 126 if __name__ == '__main__': | 134 if __name__ == '__main__': |
| 127 sys.exit(main(sys.argv[1:])) | 135 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |