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 |
| 7 """Insert a version string into a library as a section '.chromium.version'. |
| 8 """ |
| 9 |
| 10 import optparse |
| 11 import os |
| 12 import sys |
| 13 import tempfile |
| 14 |
| 15 from util import build_utils |
| 16 |
| 17 def InsertChromiumVersion(android_objcopy, |
| 18 library_path, |
| 19 version_string): |
| 20 # Remove existing .chromium.version section from .so |
| 21 objcopy_command = [android_objcopy, |
| 22 '--remove-section=.chromium.version', |
| 23 library_path] |
| 24 build_utils.CheckOutput(objcopy_command) |
| 25 |
| 26 # Add a .chromium.version section. |
| 27 with tempfile.NamedTemporaryFile() as stream: |
| 28 stream.write(version_string) |
| 29 stream.flush() |
| 30 objcopy_command = [android_objcopy, |
| 31 '--add-section', '.chromium.version=%s' % stream.name, |
| 32 library_path] |
| 33 build_utils.CheckOutput(objcopy_command) |
| 34 |
| 35 def main(args): |
| 36 args = build_utils.ExpandFileArgs(args) |
| 37 parser = optparse.OptionParser() |
| 38 |
| 39 parser.add_option('--android-objcopy', |
| 40 help='Path to the toolchain\'s objcopy binary') |
| 41 parser.add_option('--libraries-source-dir', |
| 42 help='Directory of native libraries') |
| 43 parser.add_option('--libraries', |
| 44 help='List of libraries') |
| 45 parser.add_option('--version-string', |
| 46 help='Version string to be inserted') |
| 47 parser.add_option('--stamp', help='Path to touch on success') |
| 48 |
| 49 options, _ = parser.parse_args(args) |
| 50 libraries = build_utils.ParseGypList(options.libraries) |
| 51 |
| 52 for library in libraries: |
| 53 library_path = os.path.join(options.libraries_source_dir, library) |
| 54 |
| 55 InsertChromiumVersion(options.android_objcopy, |
| 56 library_path, |
| 57 options.version_string) |
| 58 |
| 59 if options.stamp: |
| 60 build_utils.Touch(options.stamp) |
| 61 |
| 62 return 0 |
| 63 |
| 64 |
| 65 if __name__ == '__main__': |
| 66 sys.exit(main(sys.argv[1:])) |
OLD | NEW |