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'.
15 from util
import build_utils
17 def InsertChromiumVersion(android_objcopy
,
20 # Remove existing .chromium.version section from .so
21 objcopy_command
= [android_objcopy
,
22 '--remove-section=.chromium.version',
24 build_utils
.CheckOutput(objcopy_command
)
26 # Add a .chromium.version section.
27 with tempfile
.NamedTemporaryFile() as stream
:
28 stream
.write(version_string
)
30 objcopy_command
= [android_objcopy
,
31 '--add-section', '.chromium.version=%s' % stream
.name
,
33 build_utils
.CheckOutput(objcopy_command
)
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
,
57 options
.version_string
)
60 build_utils
.Touch(options
.stamp
)
65 if __name__
== '__main__':
66 sys
.exit(main(sys
.argv
[1:]))