| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 # Copyright 2017 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 # Create a static library which exposes only symbols which are explicitly marked |
| 8 # as visible e.g., by __attribute__((visibility("default"))). |
| 9 # |
| 10 # See BUILD.gn in this directory for usage example. |
| 11 # |
| 12 # This way, we can reduce risk of symbol conflict when linking it into apps |
| 13 # by exposing internal symbols, especially in third-party libraries. |
| 14 |
| 15 import optparse |
| 16 import subprocess |
| 17 |
| 18 |
| 19 def main(): |
| 20 parser = optparse.OptionParser() |
| 21 parser.add_option( |
| 22 '--input_lib', |
| 23 help='The path to an input .a file which contains symbols which must be ' |
| 24 'always linked.') |
| 25 parser.add_option( |
| 26 '--deps_lib', |
| 27 help='The path to a complete static library (.a file) which contains all ' |
| 28 'dependencies of --input_lib. .o files in this library are also ' |
| 29 'added to the output library, but only if they are referred from ' |
| 30 '--input_lib.') |
| 31 parser.add_option( |
| 32 '--output_obj', |
| 33 help='Outputs the generated .o file here. This is an intermediate file.') |
| 34 parser.add_option( |
| 35 '--output_lib', |
| 36 help='Outputs the generated .a file here.') |
| 37 (options, args) = parser.parse_args() |
| 38 assert not args |
| 39 |
| 40 # ld -r concatenates multiple .o files and .a files into a single .o file, |
| 41 # while "hiding" symbols not marked as visible. |
| 42 command = [ |
| 43 'xcrun', 'ld', '-r', |
| 44 # By default, ld only pulls .o files out of a static library if needed to |
| 45 # resolve some symbol reference. We apply -force_load option to input_lib |
| 46 # (but not to deps_lib) to force pulling all .o files. |
| 47 '-force_load', options.input_lib, |
| 48 options.deps_lib, |
| 49 '-o', options.output_obj |
| 50 ] |
| 51 subprocess.check_call(command) |
| 52 |
| 53 # Creates a .a file which contains a single .o file. |
| 54 command = [ |
| 55 'xcrun', 'ar', '-r', |
| 56 options.output_lib, |
| 57 options.output_obj, |
| 58 ] |
| 59 subprocess.check_call(command) |
| 60 |
| 61 |
| 62 if __name__ == "__main__": |
| 63 main() |
| OLD | NEW |