diff options
author | Cal Peyser <cpeyser@google.com> | 2016-04-04 15:48:34 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2016-04-05 14:03:55 +0000 |
commit | 5116c1a9e3d869df7b6cdb847e4ac2614565a1e6 (patch) | |
tree | e58a4cb2a53711988d3a727591c77af04b938bda /src/test/java/com/google/devtools/build/lib | |
parent | 539d24456d5f7cf589b1abae3ac9fe67c1a2a464 (diff) |
Introduces action_config. Does this by:
1) Introducing the action_config message in the crosstool protobuf definition. The only part of that definition that are implemented in this CL is the "tool" section, other parts will be implemented in future CLs. The proto fields are here now to avoid being delayed by release cycles at each step of the implementation.
2) Refactoring the implementation of the "feature algebra" that computes the enabled features for a given toolchain. An interface called "CrosstoolActivatable" is used to represent any participant int the feature algebra, and can be either a feature or an action_config.
--
MOS_MIGRATED_REVID=118943663
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java | 167 |
1 files changed, 166 insertions, 1 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 79b99ba2c3..4b3526bc5c 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 @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; import com.google.devtools.build.lib.testutil.Suite; import com.google.devtools.build.lib.testutil.TestSpec; import com.google.devtools.build.lib.testutil.TestUtils; +import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain; import com.google.protobuf.TextFormat; @@ -87,7 +88,7 @@ public class CcToolchainFeaturesTest { FeatureConfiguration configuration = features.getFeatureConfiguration(Arrays.asList(requestedFeatures)); ImmutableSet.Builder<String> enabledFeatures = ImmutableSet.builder(); - for (String feature : features.getFeatureNames()) { + for (String feature : features.getActivatableNames()) { if (configuration.isEnabled(feature)) { enabledFeatures.add(feature); } @@ -584,4 +585,168 @@ public class CcToolchainFeaturesTest { assertThat(features.getFeatureConfiguration("b").getCommandLine(CppCompileAction.CPP_COMPILE, createVariables("v", "1"))).containsExactly("-f", "1"); } + + @Test + public void testSimpleActionTool() throws Exception { + FeatureConfiguration configuration = + buildFeatures( + "action_config {", + " config_name: 'action-a'", + " action_name: 'action-a'", + " tool {", + " tool_path: 'toolchain/a'", + " }", + "}", + "feature {", + " name: 'activates-action-a'", + " implies: 'action-a'", + "}") + .getFeatureConfiguration("activates-action-a"); + PathFragment crosstoolPath = new PathFragment("crosstool/"); + PathFragment toolPath = configuration.getToolPathFragmentForAction("action-a", crosstoolPath); + assertThat(toolPath.toString()).isEqualTo("crosstool/toolchain/a"); + } + + @Test + public void testActionToolFromFeatureSet() throws Exception { + CcToolchainFeatures toolchainFeatures = + buildFeatures( + "action_config {", + " config_name: 'action-a'", + " action_name: 'action-a'", + " tool {", + " tool_path: 'toolchain/features-a-and-b'", + " with_feature: {", + " feature: 'feature-a'", + " feature: 'feature-b'", + " }", + " }", + " tool {", + " tool_path: 'toolchain/feature-a'", + " with_feature: { feature: 'feature-a' }", + " }", + " tool {", + " tool_path: 'toolchain/feature-b'", + " with_feature: { feature: 'feature-b' }", + " }", + " tool {", + " tool_path: 'toolchain/default'", + " }", + "}", + "feature {", + " name: 'feature-a'", + "}", + "feature {", + " name: 'feature-b'", + "}", + "feature {", + " name: 'activates-action-a'", + " implies: 'action-a'", + "}"); + + PathFragment crosstoolPath = new PathFragment("crosstool/"); + + FeatureConfiguration featureAConfiguration = + toolchainFeatures.getFeatureConfiguration("feature-a", "activates-action-a"); + assertThat( + featureAConfiguration + .getToolPathFragmentForAction("action-a", crosstoolPath) + .toString()) + .isEqualTo("crosstool/toolchain/feature-a"); + + FeatureConfiguration featureBConfiguration = + toolchainFeatures.getFeatureConfiguration("feature-b", "activates-action-a"); + assertThat( + featureBConfiguration + .getToolPathFragmentForAction("action-a", crosstoolPath) + .toString()) + .isEqualTo("crosstool/toolchain/feature-b"); + + FeatureConfiguration featureAAndBConfiguration = + toolchainFeatures.getFeatureConfiguration("feature-a", "feature-b", "activates-action-a"); + assertThat( + featureAAndBConfiguration + .getToolPathFragmentForAction("action-a", crosstoolPath) + .toString()) + .isEqualTo("crosstool/toolchain/features-a-and-b"); + + FeatureConfiguration noFeaturesConfiguration = + toolchainFeatures.getFeatureConfiguration("activates-action-a"); + assertThat( + noFeaturesConfiguration + .getToolPathFragmentForAction("action-a", crosstoolPath) + .toString()) + .isEqualTo("crosstool/toolchain/default"); + } + + @Test + public void testErrorForNoMatchingTool() throws Exception { + CcToolchainFeatures toolchainFeatures = + buildFeatures( + "action_config {", + " config_name: 'action-a'", + " action_name: 'action-a'", + " tool {", + " tool_path: 'toolchain/feature-a'", + " with_feature: { feature: 'feature-a' }", + " }", + "}", + "feature {", + " name: 'feature-a'", + "}", + "feature {", + " name: 'activates-action-a'", + " implies: 'action-a'", + "}"); + + PathFragment crosstoolPath = new PathFragment("crosstool/"); + + FeatureConfiguration noFeaturesConfiguration = + toolchainFeatures.getFeatureConfiguration("activates-action-a"); + + try { + noFeaturesConfiguration.getToolPathFragmentForAction("action-a", crosstoolPath); + fail("Expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage()) + .contains("Matching tool for action action-a not found for given feature configuration"); + } + } + + @Test + public void testInvalidActionConfigurationDuplicateActionConfigs() throws Exception { + try { + buildFeatures( + "action_config {", + " config_name: 'action-a'", + " action_name: 'action-1'", + "}", + "action_config {", + " config_name: 'action-a'", + " action_name: 'action-2'", + "}"); + fail("Expected InvalidConfigurationException"); + } catch (InvalidConfigurationException e) { + assertThat(e.getMessage()) + .contains("feature or action config 'action-a' was specified multiple times."); + } + } + + @Test + public void testInvalidActionConfigurationMultipleActionConfigsForAction() throws Exception { + try { + buildFeatures( + "action_config {", + " config_name: 'name-a'", + " action_name: 'action-a'", + "}", + "action_config {", + " config_name: 'name-b'", + " action_name: 'action-a'", + "}"); + fail("Expected InvalidConfigurationException"); + } catch (InvalidConfigurationException e) { + assertThat(e.getMessage()).contains("multiple action configs for action 'action-a'"); + } + } } |