diff options
author | Sergio Campama <kaipi@google.com> | 2017-02-06 22:43:33 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2017-02-07 18:22:16 +0000 |
commit | c82899075bbdd475c4f86d826666216c770515a1 (patch) | |
tree | 6e3bdd3114c0115f5bac31800b27d635959a7b21 | |
parent | eba6a442159f838311082bc18b6fa32cbabad31e (diff) |
Adds -disable-autolink-framework to static libraries so that they are not added by default as -framework arguments when linking. This enables test bundles on not having to relink static frameworks that were also linked in to the test host app.
--
PiperOrigin-RevId: 146713403
MOS_MIGRATED_REVID=146713403
-rw-r--r-- | tools/build_defs/apple/swift.bzl | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/build_defs/apple/swift.bzl b/tools/build_defs/apple/swift.bzl index cbc4793a3c..12fdf6533b 100644 --- a/tools/build_defs/apple/swift.bzl +++ b/tools/build_defs/apple/swift.bzl @@ -25,6 +25,11 @@ def _parent_dirs(dirs): return set([f.rpartition("/")[0] for f in dirs]) +def _framework_names(dirs): + """Returns the framework name for each directory in dir.""" + return set([f.rpartition("/")[2].partition(".")[0] for f in dirs]) + + def _intersperse(separator, iterable): """Inserts separator before each item in iterable.""" result = [] @@ -241,10 +246,12 @@ def swiftc_args(ctx): objc_includes = set() # Everything that needs to be included with -I objc_module_maps = set() # Module maps for dependent targets objc_defines = set() + static_frameworks = set() for objc in objc_providers: objc_includes += objc.include objc_module_maps += objc.module_map + static_frameworks += _framework_names(objc.framework_dir) framework_dirs += _parent_dirs(objc.framework_dir) framework_dirs += _parent_dirs(objc.dynamic_framework_dir) @@ -265,6 +272,13 @@ def swiftc_args(ctx): framework_args = ["-F%s" % x for x in framework_dirs] define_args = ["-D%s" % x for x in swiftc_defines] + # Disable the LC_LINKER_OPTION load commands for static frameworks automatic + # linking. This is needed to correctly deduplicate static frameworks from also + # being linked into test binaries where it is also linked into the app binary. + autolink_args =_intersperse( + "-Xfrontend", + _intersperse("-disable-autolink-framework", static_frameworks)) + clang_args = _intersperse( "-Xcc", @@ -307,6 +321,7 @@ def swiftc_args(ctx): args.extend(framework_args) args.extend(clang_args) args.extend(define_args) + args.extend(autolink_args) args.extend(ctx.fragments.swift.copts()) args.extend(ctx.attr.copts) |