aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Cal Peyser <cpeyser@google.com>2016-06-07 14:05:47 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-06-07 17:53:12 +0000
commit133638cf44a6d0428beec12169c205a447f48ec0 (patch)
tree9b2f8432446fd3be714541b7010377e78fa5b8a0 /src/main/java/com/google/devtools
parent6eea9bd27fc88129ccb2d74c1b550e83ebf39f17 (diff)
Allow flags to be applied to an action using an action_config. A flag set on
an action_config specifies no action, and is automatically applied to the action being configured. -- MOS_MIGRATED_REVID=124240929
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java62
1 files changed, 51 insertions, 11 deletions
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 0a2bf6e9e9..b94a60482d 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
@@ -431,7 +431,15 @@ public class CcToolchainFeatures implements Serializable {
private final ImmutableList<FlagGroup> flagGroups;
private FlagSet(CToolchain.FlagSet flagSet) throws InvalidConfigurationException {
- this.actions = ImmutableSet.copyOf(flagSet.getActionList());
+ this(flagSet, ImmutableSet.copyOf(flagSet.getActionList()));
+ }
+
+ /**
+ * Constructs a FlagSet for the given set of actions.
+ */
+ private FlagSet(CToolchain.FlagSet flagSet, ImmutableSet<String> actions)
+ throws InvalidConfigurationException {
+ this.actions = actions;
this.expandIfAllAvailable = ImmutableSet.copyOf(flagSet.getExpandIfAllAvailableList());
ImmutableList.Builder<FlagGroup> builder = ImmutableList.builder();
for (CToolchain.FlagGroup flagGroup : flagSet.getFlagGroupList()) {
@@ -591,34 +599,52 @@ public class CcToolchainFeatures implements Serializable {
/**
- * A container for information on a particular blaze action.
- *
+ * A container for information on a particular blaze action.
+ *
* <p>An ActionConfig can select a tool for its blaze action based on the set of active
* features. Internally, an ActionConfig maintains an ordered list (the order being that of the
- * list of tools in the crosstool action_config message) of such tools and the feature sets for
+ * list of tools in the crosstool action_config message) of such tools and the feature sets for
* which they are valid. For a given feature configuration, the ActionConfig will consider the
* first tool in that list with a feature set that matches the configuration to be the tool for
* its blaze action.
- *
+ *
* <p>ActionConfigs can be activated by features. That is, a particular feature can cause an
- * ActionConfig to be applied in its "implies" field. Blaze may include certain actions in
- * the action graph only if a corresponding ActionConfig is activated in the toolchain - this
- * provides the crosstool with a mechanism for adding certain actions to the action graph based
+ * ActionConfig to be applied in its "implies" field. Blaze may include certain actions in
+ * the action graph only if a corresponding ActionConfig is activated in the toolchain - this
+ * provides the crosstool with a mechanism for adding certain actions to the action graph based
* on feature configuration.
- *
+ *
* <p>It is invalid for a toolchain to contain two action configs for the same blaze action. In
* that case, blaze will throw an error when it consumes the crosstool.
*/
@Immutable
- private static class ActionConfig implements Serializable, CrosstoolSelectable {
+ static class ActionConfig implements Serializable, CrosstoolSelectable {
+
+ public static final String FLAG_SET_WITH_ACTION_ERROR =
+ "action_config %s specifies actions. An action_config's flag sets automatically apply "
+ + "to the configured action. Thus, you must not specify action lists in an "
+ + "action_config's flag set.";
+
private final String configName;
private final String actionName;
private final List<CToolchain.Tool> tools;
+ private final ImmutableList<FlagSet> flagSets;
- private ActionConfig(CToolchain.ActionConfig actionConfig) {
+ private ActionConfig(CToolchain.ActionConfig actionConfig)
+ throws InvalidConfigurationException {
this.configName = actionConfig.getConfigName();
this.actionName = actionConfig.getActionName();
this.tools = actionConfig.getToolList();
+ ImmutableList.Builder<FlagSet> flagSetBuilder = ImmutableList.builder();
+ for (CToolchain.FlagSet flagSet : actionConfig.getFlagSetList()) {
+ if (!flagSet.getActionList().isEmpty()) {
+ throw new InvalidConfigurationException(
+ String.format(FLAG_SET_WITH_ACTION_ERROR, configName));
+ }
+
+ flagSetBuilder.add(new FlagSet(flagSet, ImmutableSet.of(actionName)));
+ }
+ this.flagSets = flagSetBuilder.build();
}
@Override
@@ -660,6 +686,15 @@ public class CcToolchainFeatures implements Serializable {
+ "found for given feature configuration");
}
}
+
+ /**
+ * Adds the flags that apply to this action to {@code commandLine}.
+ */
+ private void expandCommandLine(Variables variables, List<String> commandLine) {
+ for (FlagSet flagSet : flagSets) {
+ flagSet.expandCommandLine(actionName, variables, commandLine);
+ }
+ }
}
/**
@@ -1068,6 +1103,11 @@ public class CcToolchainFeatures implements Serializable {
for (Feature feature : enabledFeatures) {
feature.expandCommandLine(action, variables, commandLine);
}
+
+ if (actionIsConfigured(action)) {
+ actionConfigByActionName.get(action).expandCommandLine(variables, commandLine);
+ }
+
return commandLine;
}