summaryrefslogtreecommitdiffstats
path: root/build/android/gyp/insert_chromium_version.py
blob: 171f9d41b8d1d70f281b6c5fb6a65c2d347e25fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/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.

"""Insert a version string into a library as a section '.chromium.version'.
"""

import optparse
import os
import sys
import tempfile

from util import build_utils

def InsertChromiumVersion(android_objcopy,
                          library_path,
                          version_string):
  # Remove existing .chromium.version section from .so
  objcopy_command = [android_objcopy,
                     '--remove-section=.chromium.version',
                     library_path]
  build_utils.CheckOutput(objcopy_command)

  # Add a .chromium.version section.
  with tempfile.NamedTemporaryFile() as stream:
    stream.write(version_string)
    stream.flush()
    objcopy_command = [android_objcopy,
                       '--add-section', '.chromium.version=%s' % stream.name,
                       library_path]
    build_utils.CheckOutput(objcopy_command)

def main(args):
  args = build_utils.ExpandFileArgs(args)
  parser = optparse.OptionParser()

  parser.add_option('--android-objcopy',
      help='Path to the toolchain\'s objcopy binary')
  parser.add_option('--stripped-libraries-dir',
      help='Directory of native libraries')
  parser.add_option('--libraries',
      help='List of libraries')
  parser.add_option('--version-string',
      help='Version string to be inserted')
  parser.add_option('--stamp', help='Path to touch on success')

  options, _ = parser.parse_args(args)
  libraries = build_utils.ParseGypList(options.libraries)

  for library in libraries:
    library_path = os.path.join(options.stripped_libraries_dir, library)

    InsertChromiumVersion(options.android_objcopy,
                          library_path,
                          options.version_string)

  if options.stamp:
    build_utils.Touch(options.stamp)

  return 0


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))