aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-02-08 14:37:22 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2017-02-08 15:52:25 +0000
commitf5bb3d248ff1dd9e5157551bbf5052c61a7643ce (patch)
tree4a1cf59203887a3de1267b7659c2d90646fc2b5b /src
parent49d97f9bb4dd04ef62198ded7b53b2a8f8c603db (diff)
Add a boolean flag to a Feature to specify whether it is enabled by default.
This enables us to configure default features for each toolchain without having to hard-code anything in class such as CcCommon. -- PiperOrigin-RevId: 146904287 MOS_MIGRATED_REVID=146904287
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java20
-rw-r--r--src/main/protobuf/crosstool_config.proto7
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java7
4 files changed, 32 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
index 1c7d0d1e99..8e58a103fc 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
@@ -535,9 +535,10 @@ public final class CcCommon {
ImmutableSet.Builder<String> requestedFeatures = ImmutableSet.builder();
for (String feature :
Iterables.concat(
- ImmutableSet.of(toolchain.getCompilationMode().toString()),
- ImmutableSet.of(getHostOrNonHostFeature(ruleContext)),
+ ImmutableSet.of(
+ toolchain.getCompilationMode().toString(), getHostOrNonHostFeature(ruleContext)),
DEFAULT_FEATURES,
+ toolchain.getFeatures().getDefaultFeatures(),
ruleContext.getFeatures())) {
if (!unsupportedFeatures.contains(feature)) {
requestedFeatures.add(feature);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
index 47a9fa667e..f9295c684a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
@@ -1820,13 +1820,15 @@ public class CcToolchainFeatures implements Serializable {
* was disabled.
*/
private final ImmutableMultimap<CrosstoolSelectable, CrosstoolSelectable> requiredBy;
+
+ private final ImmutableList<String> defaultFeatures;
/**
- * A cache of feature selection results, so we do not recalculate the feature selection for
- * all actions.
+ * A cache of feature selection results, so we do not recalculate the feature selection for all
+ * actions.
*/
- private transient LoadingCache<Collection<String>, FeatureConfiguration>
- configurationCache = buildConfigurationCache();
+ private transient LoadingCache<Collection<String>, FeatureConfiguration> configurationCache =
+ buildConfigurationCache();
/**
* Constructs the feature configuration from a {@code CToolchain} protocol buffer.
@@ -1846,11 +1848,16 @@ public class CcToolchainFeatures implements Serializable {
// Also build a map from action -> action_config, for use in tool lookups
ImmutableMap.Builder<String, ActionConfig> actionConfigsByActionName = ImmutableMap.builder();
+ ImmutableList.Builder<String> defaultFeaturesBuilder = ImmutableList.builder();
for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
Feature feature = new Feature(toolchainFeature);
selectablesBuilder.add(feature);
selectablesByName.put(feature.getName(), feature);
+ if (toolchainFeature.getEnabled()) {
+ defaultFeaturesBuilder.add(feature.getName());
+ }
}
+ this.defaultFeatures = defaultFeaturesBuilder.build();
for (CToolchain.ActionConfig toolchainActionConfig : toolchain.getActionConfigList()) {
ActionConfig actionConfig = new ActionConfig(toolchainActionConfig);
@@ -2006,6 +2013,11 @@ public class CcToolchainFeatures implements Serializable {
return getFeatureConfiguration(Arrays.asList(requestedFeatures));
}
+ /** Returns the list of features that specify themselves as enabled by default. */
+ public ImmutableList<String> getDefaultFeatures() {
+ return defaultFeatures;
+ }
+
/**
* @return the selectable with the given {@code name}.
*
diff --git a/src/main/protobuf/crosstool_config.proto b/src/main/protobuf/crosstool_config.proto
index a6d9c64521..dbdd508aa7 100644
--- a/src/main/protobuf/crosstool_config.proto
+++ b/src/main/protobuf/crosstool_config.proto
@@ -178,7 +178,7 @@ message CToolchain {
}
// Contains all flag specifications for one feature.
- // Next ID: 7
+ // Next ID: 8
message Feature {
// The feature's name. Feature names are generally defined by Bazel; it is
// possible to introduce a feature without a change to Bazel by adding a
@@ -186,6 +186,11 @@ message CToolchain {
// feature in the BUILD file.
optional string name = 1;
+ // If 'true', this feature is enabled unless a rule type explicitly marks it
+ // as unssupported. Such features cannot be turned of from with in a BUILD
+ // file or the command line.
+ optional bool enabled = 7;
+
// If the given feature is enabled, the flag sets will be applied for the
// actions in the modes that they are specified for.
repeated FlagSet flag_set = 2;
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 52ebddbae2..188794f77d 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
@@ -1040,6 +1040,13 @@ public class CcToolchainFeaturesTest {
assertThat(features.getFeatureConfiguration("b").getCommandLine(CppCompileAction.CPP_COMPILE,
createVariables("v", "1"))).containsExactly("-f", "1");
}
+
+ @Test
+ public void testDefaultFeatures() throws Exception {
+ CcToolchainFeatures features =
+ buildFeatures("feature { name: 'a' }", "feature { name: 'b' enabled: true }");
+ assertThat(features.getDefaultFeatures()).containsExactly("b");
+ }
@Test
public void testActivateActionConfigFromFeature() throws Exception {