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

Unified Diff: ios/web_view/internal/hide_symbols.py

Issue 2665333002: Add a BUILD target and a script to build a public static library for ios/web_view. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« ios/web_view/BUILD.gn ('K') | « ios/web_view/internal/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web_view/internal/hide_symbols.py
diff --git a/ios/web_view/internal/hide_symbols.py b/ios/web_view/internal/hide_symbols.py
new file mode 100755
index 0000000000000000000000000000000000000000..1ed9016e09dc564c460e74e1e2e3518a3aa38482
--- /dev/null
+++ b/ios/web_view/internal/hide_symbols.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+# Copyright 2017 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.
+
+# Create a static library which exposes only symbols which are explicitly marked
+# as visible e.g., by __attribute__((visibility("default"))).
+#
+# See BUILD.gn in this directory for usage example.
+#
+# This way, we can reduce risk of symbol conflict when linking it into apps
+# by exposing internal symbols, especially in third-party libraries.
+
+import optparse
+import subprocess
+
+
+def main():
+ parser = optparse.OptionParser()
+ parser.add_option(
+ '--input_lib',
+ help='The path to an input .a file which contains symbols which must be '
+ 'always linked.')
+ parser.add_option(
+ '--deps_lib',
+ help='The path to a complete static library (.a file) which contains all '
+ 'dependencies of --input_lib. .o files in this library are also '
+ 'added to the output library, but only if they are referred from '
+ '--input_lib.')
+ parser.add_option(
+ '--output_obj',
+ help='Outputs the generated .o file here. This is an intermediate file.')
+ parser.add_option(
+ '--output_lib',
+ help='Outputs the generated .a file here.')
+ (options, args) = parser.parse_args()
+ assert not args
+
+ # ld -r concatenates multiple .o files and .a files into a single .o file,
+ # while "hiding" symbols not marked as visible.
+ command = [
+ 'xcrun', 'ld', '-r',
+ # By default, ld only pulls .o files out of a static library if needed to
+ # resolve some symbol reference. We apply -force_load option to input_lib
+ # (but not to deps_lib) to force pulling all .o files.
+ '-force_load', options.input_lib,
+ options.deps_lib,
+ '-o', options.output_obj
+ ]
+ subprocess.check_call(command)
+
+ # Creates a .a file which contains a single .o file.
+ command = [
+ 'xcrun', 'ar', '-r',
+ options.output_lib,
+ options.output_obj,
+ ]
+ subprocess.check_call(command)
+
+
+if __name__ == "__main__":
+ main()
« ios/web_view/BUILD.gn ('K') | « ios/web_view/internal/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698