diff options
author | 2017-08-30 03:10:41 +0200 | |
---|---|---|
committer | 2017-08-30 13:48:58 +0200 | |
commit | fc41c430e4de4594a1d699f573d191cbad52a2fb (patch) | |
tree | 60bfc201402d9b810952ac62ba564247415294cf /src/test/java/com/google/devtools | |
parent | 75f97c1194c82bdd59f0a8c2809e7bfa464b01d4 (diff) |
Move ObjcProvider FLAG into a new provider type (TransitiveSourcesProvider) that is accessible to the c++ rules.
PiperOrigin-RevId: 166934390
Diffstat (limited to 'src/test/java/com/google/devtools')
8 files changed, 103 insertions, 65 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryTest.java index 01754e5c23..b0d0953965 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinaryTest.java @@ -223,4 +223,9 @@ public class IosExtensionBinaryTest extends ObjcRuleTestCase { public void testCompilesSources() throws Exception { checkCompilesSources(RULE_TYPE); } + + @Test + public void testLinkActionWithTransitiveCppDependency() throws Exception { + checkLinkActionWithTransitiveCppDependency(RULE_TYPE, EXTRA_LINK_ARGS); + } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionBinaryTest.java index 0fadc47f2d..f2416eac8e 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionBinaryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyIosExtensionBinaryTest.java @@ -29,9 +29,10 @@ public class LegacyIosExtensionBinaryTest extends IosExtensionBinaryTest { return ObjcCrosstoolMode.OFF; } + @Override @Test public void testLinkActionWithTransitiveCppDependency() throws Exception { - checkLinkActionWithTransitiveCppDependency(RULE_TYPE, EXTRA_LINK_ARGS); + // Transitive source data is not known to the legacy rules. } @Test diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcBinaryTest.java index d0c08a6e6b..55475fe905 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcBinaryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcBinaryTest.java @@ -37,9 +37,10 @@ public class LegacyObjcBinaryTest extends ObjcBinaryTest { return ObjcCrosstoolMode.OFF; } + @Override @Test public void testLinkActionWithTransitiveCppDependency() throws Exception { - checkLinkActionWithTransitiveCppDependency(RULE_TYPE, new ExtraLinkArgs()); + // Transitive sources data is not available to the legacy rules. } @Test diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcLibraryTest.java index 2028571aa2..abbae40ccf 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/LegacyObjcLibraryTest.java @@ -59,24 +59,6 @@ public class LegacyObjcLibraryTest extends ObjcLibraryTest { useConfiguration(ObjcCrosstoolMode.OFF, args); } - @Override - @Test - public void testObjcSourcesFeatureCC() throws Exception { - // Features are not exported by legacy actions. - } - - @Override - @Test - public void testObjcSourcesFeatureObjc() throws Exception { - // Features are not exported by legacy actions. - } - - @Override - @Test - public void testObjcSourcesFeatureObjcPlusPlus() throws Exception { - // Features are not exported by legacy actions. - } - @Test public void testLibFileIsCorrectForSlashInTargetName() throws Exception { ConfiguredTarget target = diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryTest.java index 4775e2df30..255841d605 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryTest.java @@ -935,4 +935,9 @@ public class ObjcBinaryTest extends ObjcRuleTestCase { public void testGenruleDependency() throws Exception { checkGenruleDependency(RULE_TYPE); } + + @Test + public void testLinkActionWithTransitiveCppDependency() throws Exception { + checkLinkActionWithTransitiveCppDependency(RULE_TYPE, new ExtraLinkArgs()); + } } 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 08b1d0b191..056a607c39 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 @@ -1566,45 +1566,4 @@ public class ObjcLibraryTest extends ObjcRuleTestCase { public void testCustomModuleMap() throws Exception { checkCustomModuleMap(RULE_TYPE); } - - private boolean containsObjcFeature(String srcName) throws Exception { - MockObjcSupport.setup( - mockToolsConfig, - "feature {", - " name: 'contains_objc_sources'", - " flag_set {", - " flag_group {", - " flag: 'DUMMY_FLAG'", - " }", - " action: 'c++-compile'", - " }", - "}"); - createLibraryTargetWriter("//bottom:lib").setList("srcs", srcName).write(); - createLibraryTargetWriter("//middle:lib") - .setList("srcs", "b.cc") - .setList("deps", "//bottom:lib") - .write(); - createLibraryTargetWriter("//top:lib") - .setList("srcs", "a.cc") - .setList("deps", "//middle:lib") - .write(); - - CommandAction compileAction = compileAction("//top:lib", "a.o"); - return compileAction.getArguments().contains("DUMMY_FLAG"); - } - - @Test - public void testObjcSourcesFeatureCC() throws Exception { - assertThat(containsObjcFeature("c.cc")).isFalse(); - } - - @Test - public void testObjcSourcesFeatureObjc() throws Exception { - assertThat(containsObjcFeature("c.m")).isTrue(); - } - - @Test - public void testObjcSourcesFeatureObjcPlusPlus() throws Exception { - assertThat(containsObjcFeature("c.mm")).isTrue(); - } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java index b48d242c6b..7baa058ad7 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java @@ -26,7 +26,6 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STORYBOARD; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.BundlingRule.FAMILIES_ATTR; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.BundlingRule.INFOPLIST_ATTR; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.CLANG; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.CLANG_PLUSPLUS; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.DSYMUTIL; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.LIPO; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.ReleaseBundlingRule.APP_ICON_ATTR; @@ -644,9 +643,10 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase { ruleType.scratchTarget(scratch, "srcs", "['c.m']", "deps", "['//lib2:lib2']"); CommandAction action = linkAction("//x:x"); - assertThat(action.getArguments().get(2)) - .startsWith( - MOCK_XCRUNWRAPPER_PATH + " " + CLANG_PLUSPLUS + " -stdlib=libc++ -std=gnu++11"); + String commandLine = Joiner.on(" ").join(action.getArguments()); + assertThat(commandLine).contains("wrapped_clang++"); + assertThat(commandLine).contains("-stdlib=libc++"); + assertThat(commandLine).contains("-std=gnu++11"); } protected Map<String, String> mobileProvisionProfiles(BundleMergeProtos.Control control) { diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/TransitiveSourcesTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/TransitiveSourcesTest.java new file mode 100644 index 0000000000..015c7d18fe --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/TransitiveSourcesTest.java @@ -0,0 +1,85 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.rules.objc; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.devtools.build.lib.analysis.ConfiguredTarget; +import com.google.devtools.build.lib.packages.util.MockObjcSupport; +import com.google.devtools.build.lib.rules.cpp.CppCompileAction; +import com.google.devtools.build.lib.rules.cpp.CppLinkAction; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for propagation of the presence of categories of source in the transitive deps of a target. + */ +@RunWith(JUnit4.class) +public class TransitiveSourcesTest extends ObjcRuleTestCase { + + @Before + public void setup() throws Exception { + MockObjcSupport.setup( + mockToolsConfig, + "feature {", + " name: 'contains_objc_source'", + " flag_set {", + " flag_group {", + " flag: 'DUMMY_FLAG'", + " }", + " action: 'c++-compile'", + " action: 'c++-link-executable'", + " action: 'objc++-executable'", + " }", + "}"); + useConfiguration(); + } + + private CppCompileAction getCppCompileAction(String label) throws Exception { + ConfiguredTarget target = getConfiguredTarget(label); + return actionsTestUtil() + .findTransitivePrerequisitesOf( + getFilesToBuild(target).iterator().next(), CppCompileAction.class) + .get(0); + } + + private CppLinkAction getExecutableCppLinkAction(String label) throws Exception { + return (CppLinkAction) getGeneratingAction(getExecutable(label)); + } + + @Test + public void testCcBinaryTransitiveObjcFeature() throws Exception { + scratch.file("bottom/BUILD", "objc_library(name='lib', srcs=['a.m'])"); + scratch.file("middle/BUILD", "cc_library(name='lib', srcs=['a.cc'], deps=['//bottom:lib'])"); + scratch.file("top/BUILD", "cc_binary(name='bin', srcs=['a.cc'], deps=['//middle:lib'])"); + + assertThat(getCppCompileAction("//top:bin").getArguments()).contains("DUMMY_FLAG"); + assertThat(getExecutableCppLinkAction("//top:bin").getArguments()).contains("DUMMY_FLAG"); + } + + @Test + public void testAppleBinaryTransitiveObjcFeature() throws Exception { + scratch.file("bottom/BUILD", "objc_library(name='lib', srcs=['a.m'])"); + scratch.file("middle/BUILD", "cc_library(name='lib', srcs=['a.cc'], deps=['//bottom:lib'])"); + scratch.file( + "top/BUILD", + "apple_binary(name='bin', platform_type='ios', srcs=['a.cc'], deps=['//middle:lib'])"); + + assertThat(getCppCompileAction("//top:bin").getArguments()).contains("DUMMY_FLAG"); + assertThat(linkAction("//top:bin").getArguments()).contains("DUMMY_FLAG"); + } +} |