diff options
author | bbaren <bbaren@google.com> | 2018-07-02 13:11:49 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-02 13:13:08 -0700 |
commit | eb952d08f76afa907bb34eaf7e1a69899102c523 (patch) | |
tree | 22be39bdf237bfd07783854cf451ec6fabd7dd66 | |
parent | 151717ce36ad3fa99b5aaf79328f632ebd4b0f7c (diff) |
Set Xcode version as a feature when building Objective-C
Add a new standard feature set to the Xcode version being used for
compilation. (The feature is named `xcode_VERSION`, where `VERSION` is
at least a two-component version number; `xcode_9.0` and `xcode_9.2` are
both possible values.) This provides CROSSTOOL authors a mechanism to
deploy compiler flags supported only in certain Xcode versions.
PiperOrigin-RevId: 203000420
3 files changed, 209 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index f6b6052895..ed95544092 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -223,6 +223,8 @@ public class CompilationSupport { private static final String GENERATE_LINKMAP_FEATURE_NAME = "generate_linkmap"; + private static final String XCODE_VERSION_FEATURE_NAME_PREFIX = "xcode_"; + /** Enabled if this target has objc sources in its transitive closure. */ private static final String CONTAINS_OBJC = "contains_objc_sources"; @@ -545,6 +547,9 @@ public class CompilationSupport { activatedCrosstoolSelectables.add(CppRuleClasses.PER_OBJECT_DEBUG_INFO); } + activatedCrosstoolSelectables.add(XCODE_VERSION_FEATURE_NAME_PREFIX + + XcodeConfig.getXcodeVersion(ruleContext).toStringWithMinimumComponents(2)); + activatedCrosstoolSelectables.addAll(ruleContext.getFeatures()); activatedCrosstoolSelectables.addAll(CcCommon.getCoverageFeatures(toolchain)); diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MOCK_OSX_CROSSTOOL b/src/test/java/com/google/devtools/build/lib/packages/util/MOCK_OSX_CROSSTOOL index 645830faed..a4828f4d39 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/MOCK_OSX_CROSSTOOL +++ b/src/test/java/com/google/devtools/build/lib/packages/util/MOCK_OSX_CROSSTOOL @@ -632,6 +632,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -2346,6 +2361,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -4055,6 +4085,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -5764,6 +5809,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -7477,6 +7537,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -9196,6 +9271,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -10918,6 +11008,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -12667,6 +12772,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -14386,6 +14506,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -16125,6 +16260,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -17867,6 +18017,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" @@ -19636,6 +19801,21 @@ toolchain { } } feature { + name: "xcode_5.8" + flag_set { + action: "preprocess-assemble" + action: "c-compile" + action: "c++-compile" + action: "c++-header-parsing" + action: "c++-header-preprocessing" + action: "objc-compile" + action: "objc++-compile" + flag_group { + flag: "-DXCODE_FEATURE_FOR_TESTING=xcode_5.8" + } + } + } + feature { name: "framework_paths" flag_set { action: "objc-compile" diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java index f6a40e57ff..ae879d288c 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java @@ -1269,6 +1269,30 @@ public class ObjcLibraryTest extends ObjcRuleTestCase { } @Test + public void testXcodeVersionFeature() throws Exception { + useConfiguration("--xcode_version=5.8"); + + createLibraryTargetWriter("//objc:lib") + .setAndCreateFiles("srcs", "a.m") + .write(); + CommandAction action = compileAction("//objc:lib", "a.o"); + + assertThat(action.getArguments()).contains("-DXCODE_FEATURE_FOR_TESTING=xcode_5.8"); + } + + @Test + public void testXcodeVersionFeatureUnused() throws Exception { + useConfiguration("--xcode_version=7.3"); + + createLibraryTargetWriter("//objc:lib") + .setAndCreateFiles("srcs", "a.m") + .write(); + CommandAction action = compileAction("//objc:lib", "a.o"); + + assertThat(action.getArguments()).doesNotContain("-DXCODE_FEATURE_FOR_TESTING=xcode_5.8"); + } + + @Test public void testIosSdkVersionCannotBeDefinedButEmpty() throws Exception { try { useConfiguration("--ios_sdk_version="); |