Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: components/cronet/tools/hide_symbols.py

Issue 2807283002: [Cronet] Build static libcronet.a for iOS with complete dependencies. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/cronet/ios/sample/main.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 os
17 import subprocess
18
19
20 # Mapping from GN's target_cpu attribute to ld's -arch parameter.
21 # Taken from the definition of config("compiler") in:
22 # //build/config/mac/BUILD.gn
23 GN_CPU_TO_LD_ARCH = {
24 'x64': 'x86_64',
25 'x86': 'i386',
26 'armv7': 'armv7',
27 'arm': 'armv7',
28 'arm64': 'arm64',
29 }
30
31
32 def main():
33 parser = optparse.OptionParser()
34 parser.add_option(
35 '--input_libs',
36 help='Comma-separated paths to input .a files which contain symbols '
37 'which must be always linked.')
38 parser.add_option(
39 '--deps_lib',
40 help='The path to a complete static library (.a file) which contains all '
41 'dependencies of --input_libs. .o files in this library are also '
42 'added to the output library, but only if they are referred from '
43 '--input_libs.')
44 parser.add_option(
45 '--output_obj',
46 help='Outputs the generated .o file here. This is an intermediate file.')
47 parser.add_option(
48 '--output_lib',
49 help='Outputs the generated .a file here.')
50 parser.add_option(
51 '--current_cpu',
52 help='The current processor architecture in the format of the target_cpu '
53 'attribute in GN.')
54 (options, args) = parser.parse_args()
55 assert not args
56
57 # ld -r concatenates multiple .o files and .a files into a single .o file,
58 # while "hiding" symbols not marked as visible.
59 command = [
60 'xcrun', 'ld',
61 '-arch', GN_CPU_TO_LD_ARCH[options.current_cpu],
mef 2017/04/11 21:05:09 This gets an error in debug simulator build: ld:
Hiroshi Ichikawa 2017/04/12 04:35:25 Does it happen only on trybot, or does it happen o
mef 2017/04/12 15:57:50 It happens locally, but only for one configuration
62 '-r',
63 ]
64 for input_lib in options.input_libs.split(','):
65 # By default, ld only pulls .o files out of a static library if needed to
66 # resolve some symbol reference. We apply -force_load option to input_lib
67 # (but not to deps_lib) to force pulling all .o files.
68 command += ['-force_load', input_lib]
69 command += [
70 options.deps_lib,
71 '-o', options.output_obj
72 ]
73 subprocess.check_call(command)
74
75 if os.path.exists(options.output_lib):
76 os.remove(options.output_lib)
77
78 # Creates a .a file which contains a single .o file.
79 command = [
80 'xcrun', 'ar', '-r',
81 options.output_lib,
82 options.output_obj,
83 ]
84 subprocess.check_call(command)
85
86
87 if __name__ == "__main__":
88 main()
OLDNEW
« no previous file with comments | « components/cronet/ios/sample/main.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698