diff options
Diffstat (limited to 'src/test/java/com')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java | 5 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java | 104 |
2 files changed, 89 insertions, 20 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java index 8707f46565..4d64a293cb 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java @@ -77,7 +77,10 @@ public class CcToolchainFeaturesTest { return variables.build(); } - private CcToolchainFeatures buildFeatures(String... toolchain) throws Exception { + /** + * Creates a CcToolchainFeatures from features described in the given toolchain fragment. + */ + public static CcToolchainFeatures buildFeatures(String... toolchain) throws Exception { CToolchain.Builder toolchainBuilder = CToolchain.newBuilder(); TextFormat.merge(Joiner.on("").join(toolchain), toolchainBuilder); return new CcToolchainFeatures(toolchainBuilder.buildPartial()); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java index 54bc4919d6..74ba8c565a 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.cpp; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -31,6 +32,7 @@ import com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinatio import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; +import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.rules.cpp.CppLinkAction.Builder; import com.google.devtools.build.lib.rules.cpp.Link.LinkStaticness; import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; @@ -65,6 +67,54 @@ public class CppLinkActionTest extends BuildViewTestCase { }, masterConfig); } + @Test + public void testToolchainFeatureFlags() throws Exception { + FeatureConfiguration featureConfiguration = + CcToolchainFeaturesTest.buildFeatures( + "feature {", + " name: 'a'", + " flag_set {", + " action: 'c++-link'", + " flag_group { flag: 'some_flag' }", + " }", + "}") + .getFeatureConfiguration("a"); + + CppLinkAction linkAction = + createLinkBuilder( + Link.LinkTargetType.EXECUTABLE, + "out", + ImmutableList.<Artifact>of(), + ImmutableList.<LibraryToLink>of(), + featureConfiguration) + .build(); + assertThat(linkAction.getArgv()).contains("some_flag"); + } + + @Test + public void testToolchainFeatureEnv() throws Exception { + FeatureConfiguration featureConfiguration = + CcToolchainFeaturesTest.buildFeatures( + "feature {", + " name: 'a'", + " env_set {", + " action: 'c++-link'", + " env_entry { key: 'foo', value: 'bar' }", + " }", + "}") + .getFeatureConfiguration("a"); + + CppLinkAction linkAction = + createLinkBuilder( + Link.LinkTargetType.EXECUTABLE, + "out", + ImmutableList.<Artifact>of(), + ImmutableList.<LibraryToLink>of(), + featureConfiguration) + .build(); + assertThat(linkAction.getEnvironment()).containsEntry("foo", "bar"); + } + /** * This mainly checks that non-static links don't have identical keys. Many options are only * allowed on non-static links, and we test several of them here. @@ -100,6 +150,8 @@ public class CppLinkActionTest extends BuildViewTestCase { builder.setWholeArchive((i & 16) == 0); builder.setFake((i & 32) == 0); builder.setRuntimeSolibDir((i & 64) == 0 ? null : new PathFragment("so1")); + builder.setFeatureConfiguration(new FeatureConfiguration()); + return builder.build(); } }); @@ -134,6 +186,7 @@ public class CppLinkActionTest extends BuildViewTestCase { (i & 1) == 0 ? ImmutableList.of(oFile) : ImmutableList.of(oFile2)); builder.setLinkType( (i & 2) == 0 ? LinkTargetType.STATIC_LIBRARY : LinkTargetType.DYNAMIC_LIBRARY); + builder.setFeatureConfiguration(new FeatureConfiguration()); return builder.build(); } }); @@ -188,11 +241,15 @@ public class CppLinkActionTest extends BuildViewTestCase { objects.add(getOutputArtifact("object" + i + ".o")); } - CppLinkAction linkAction = createLinkBuilder( - Link.LinkTargetType.EXECUTABLE, "binary2", objects.build(), - ImmutableList.<LibraryToLink>of()) - .setFake(true) - .build(); + CppLinkAction linkAction = + createLinkBuilder( + Link.LinkTargetType.EXECUTABLE, + "binary2", + objects.build(), + ImmutableList.<LibraryToLink>of(), + new FeatureConfiguration()) + .setFake(true) + .build(); // Ensure that minima are enforced. ResourceSet resources = linkAction.estimateResourceConsumptionLocal(); @@ -215,22 +272,31 @@ public class CppLinkActionTest extends BuildViewTestCase { assertTrue(resources.getIoUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage() || resources.getIoUsage() == scaledSet.getIoUsage()); } - private Builder createLinkBuilder(Link.LinkTargetType type, String outputPath, - Iterable<Artifact> nonLibraryInputs, ImmutableList<LibraryToLink> libraryInputs) + + private Builder createLinkBuilder( + Link.LinkTargetType type, + String outputPath, + Iterable<Artifact> nonLibraryInputs, + ImmutableList<LibraryToLink> libraryInputs, + FeatureConfiguration featureConfiguration) throws Exception { RuleContext ruleContext = createDummyRuleContext(); - Builder builder = new CppLinkAction.Builder( - ruleContext, - new Artifact(new PathFragment(outputPath), getTargetConfiguration().getBinDirectory()), - ruleContext.getConfiguration(), - null) - .addNonLibraryInputs(nonLibraryInputs) - .addLibraries(NestedSetBuilder.wrap(Order.LINK_ORDER, libraryInputs)) - .setLinkType(type) - .setCrosstoolInputs(NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER)) - .setLinkStaticness(type.isStaticLibraryLink() - ? LinkStaticness.FULLY_STATIC - : LinkStaticness.MOSTLY_STATIC); + Builder builder = + new CppLinkAction.Builder( + ruleContext, + new Artifact( + new PathFragment(outputPath), getTargetConfiguration().getBinDirectory()), + ruleContext.getConfiguration(), + null) + .addNonLibraryInputs(nonLibraryInputs) + .addLibraries(NestedSetBuilder.wrap(Order.LINK_ORDER, libraryInputs)) + .setLinkType(type) + .setCrosstoolInputs(NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER)) + .setLinkStaticness( + type.isStaticLibraryLink() + ? LinkStaticness.FULLY_STATIC + : LinkStaticness.MOSTLY_STATIC) + .setFeatureConfiguration(featureConfiguration); return builder; } |