diff options
author | 2018-04-24 17:25:59 -0700 | |
---|---|---|
committer | 2018-04-24 17:27:21 -0700 | |
commit | b88e3f4bbbbf12001b6aa11453f604d360b3d91b (patch) | |
tree | 7f1e3e994e0644588cdca4c1b28bd4dc380c1d27 /src/test/java/com/google/devtools/build | |
parent | c5c6ef83936cf90fd11038a84637e691beb47288 (diff) |
Make the static_link_cpp_runtimes feature settable
as a normal feature.
Prior to this cl, it was always set by examining
supports_embedded_runtimes.
DELTA_BY_EXTENSION=java=100,py=15
RELNOTES: None
PiperOrigin-RevId: 194172053
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java index ffe4ca9777..f01726a638 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainTest.java @@ -29,7 +29,9 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfig import com.google.devtools.build.lib.rules.cpp.CppConfiguration.DynamicMode; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; +import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain; import com.google.devtools.common.options.OptionsParsingException; +import com.google.protobuf.TextFormat; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -863,6 +865,8 @@ public class CcToolchainTest extends BuildViewTestCase { assertThat(toolchainProvider.supportsDynamicLinker()).isTrue(); } + // Tests CcCommon::enableStaticLinkCppRuntimesFeature when supports_embedded_runtimes is not + // present at all in the toolchain. @Test public void testStaticLinkCppRuntimesSetViaSupportsEmbeddedRuntimesUnset() throws Exception { writeDummyCcToolchain(); @@ -877,6 +881,8 @@ public class CcToolchainTest extends BuildViewTestCase { .isEqualTo(featureConfiguration.isEnabled(CppRuleClasses.STATIC_LINK_CPP_RUNTIMES)); } + // Tests CcCommon::enableStaticLinkCppRuntimesFeature when supports_embedded_runtimes is false + // in the toolchain. @Test public void testStaticLinkCppRuntimesSetViaSupportsEmbeddedRuntimesFalse() throws Exception { writeDummyCcToolchain(); @@ -890,4 +896,55 @@ public class CcToolchainTest extends BuildViewTestCase { assertThat(toolchainProvider.supportsEmbeddedRuntimes()) .isEqualTo(featureConfiguration.isEnabled(CppRuleClasses.STATIC_LINK_CPP_RUNTIMES)); } + + private FeatureConfiguration configureFeaturesForStaticLinkCppRuntimesTest( + String partialToolchain, String configurationToUse) throws Exception { + writeDummyCcToolchain(); + CToolchain.Builder toolchainBuilder = CToolchain.newBuilder(); + TextFormat.merge(partialToolchain, toolchainBuilder); + getAnalysisMock() + .ccSupport() + .setupCrosstool( + mockToolsConfig, + /* addEmbeddedRuntimes= */ true, + /* addModuleMap= */ false, + /* staticRuntimesLabel= */ null, + /* dynamicRuntimesLabel= */ null, + toolchainBuilder.buildPartial()); + useConfiguration(configurationToUse); + ConfiguredTarget target = getConfiguredTarget("//a:b"); + CcToolchainProvider toolchainProvider = + (CcToolchainProvider) target.get(ToolchainInfo.PROVIDER); + return CcCommon.configureFeaturesOrReportRuleError(getRuleContext(target), toolchainProvider); + } + + // Tests CcCommon::enableStaticLinkCppRuntimesFeature when supports_embedded_runtimes is true in + // the toolchain and the feature is not present at all. + @Test + public void testSupportsEmbeddedRuntimesNoFeatureAtAll() throws Exception { + FeatureConfiguration featureConfiguration = + configureFeaturesForStaticLinkCppRuntimesTest("supports_embedded_runtimes: true", ""); + assertThat(featureConfiguration.isEnabled(CppRuleClasses.STATIC_LINK_CPP_RUNTIMES)).isTrue(); + } + + // Tests CcCommon::enableStaticLinkCppRuntimesFeature when supports_embedded_runtimes is true in + // the toolchain and the feature is enabled. + @Test + public void testSupportsEmbeddedRuntimesFeatureEnabled() throws Exception { + FeatureConfiguration featureConfiguration = + configureFeaturesForStaticLinkCppRuntimesTest( + "supports_embedded_runtimes: true", "--features=static_link_cpp_runtimes"); + assertThat(featureConfiguration.isEnabled(CppRuleClasses.STATIC_LINK_CPP_RUNTIMES)).isTrue(); + } + + // Tests CcCommon::enableStaticLinkCppRuntimesFeature when supports_embedded_runtimes is true in + // the toolchain and the feature is disabled. + @Test + public void testStaticLinkCppRuntimesOverridesSupportsEmbeddedRuntimes() throws Exception { + FeatureConfiguration featureConfiguration = + configureFeaturesForStaticLinkCppRuntimesTest( + "supports_embedded_runtimes: true feature { name: 'static_link_cpp_runtimes' }", + "--features=-static_link_cpp_runtimes"); + assertThat(featureConfiguration.isEnabled(CppRuleClasses.STATIC_LINK_CPP_RUNTIMES)).isFalse(); + } } |