Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / build / android / gyp / insert_chromium_version.py
blob171f9d41b8d1d70f281b6c5fb6a65c2d347e25fb
1 #!/usr/bin/env python
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.
7 """Insert a version string into a library as a section '.chromium.version'.
8 """
10 import optparse
11 import os
12 import sys
13 import tempfile
15 from util import build_utils
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)
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)
35 def main(args):
36 args = build_utils.ExpandFileArgs(args)
37 parser = optparse.OptionParser()
39 parser.add_option('--android-objcopy',
40 help='Path to the toolchain\'s objcopy binary')
41 parser.add_option('--stripped-libraries-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')
49 options, _ = parser.parse_args(args)
50 libraries = build_utils.ParseGypList(options.libraries)
52 for library in libraries:
53 library_path = os.path.join(options.stripped_libraries_dir, library)
55 InsertChromiumVersion(options.android_objcopy,
56 library_path,
57 options.version_string)
59 if options.stamp:
60 build_utils.Touch(options.stamp)
62 return 0
65 if __name__ == '__main__':
66 sys.exit(main(sys.argv[1:]))