diff options
author | Manuel Klimek <klimek@google.com> | 2015-08-06 14:38:16 +0000 |
---|---|---|
committer | David Chen <dzc@google.com> | 2015-08-06 22:15:56 +0000 |
commit | d53d10bfc61096158f3b7ee7e8aab2f782398716 (patch) | |
tree | fd8b25e56b95b5a8bf0c6f5bb900c7bd084f93f9 /src/main/java/com/google/devtools/build/lib | |
parent | 37428d23fb9a60ee74cc2ad2c50db045aa3bcbf5 (diff) |
Feature configuration: add a field required_variables on flag_sets.
This allows to prevent expansion of flag sets based on whether build variables
are available. If required_variables is not set, and a variable that is
referenced in the flag_set's flags is not available, the build will fail.
We need the new behavior when some input files (for example profile data in
FDO enabled builds) are only available for a subset of the translation units of
a given target.
--
MOS_MIGRATED_REVID=100028996
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java | 14 |
1 files changed, 14 insertions, 0 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 67581afe06..c2d7825f6b 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 @@ -393,10 +393,12 @@ public class CcToolchainFeatures implements Serializable { @Immutable private static class FlagSet implements Serializable { private final ImmutableSet<String> actions; + private final ImmutableSet<String> expandIfAllAvailable; private final ImmutableList<FlagGroup> flagGroups; private FlagSet(CToolchain.FlagSet flagSet) throws InvalidConfigurationException { this.actions = ImmutableSet.copyOf(flagSet.getActionList()); + this.expandIfAllAvailable = ImmutableSet.copyOf(flagSet.getExpandIfAllAvailableList()); ImmutableList.Builder<FlagGroup> builder = ImmutableList.builder(); for (CToolchain.FlagGroup flagGroup : flagSet.getFlagGroupList()) { builder.add(new FlagGroup(flagGroup)); @@ -408,6 +410,11 @@ public class CcToolchainFeatures implements Serializable { * Adds the flags that apply to the given {@code action} to {@code commandLine}. */ private void expandCommandLine(String action, Variables variables, List<String> commandLine) { + for (String variable : expandIfAllAvailable) { + if (!variables.isAvailable(variable)) { + return; + } + } if (!actions.contains(action)) { return; } @@ -738,6 +745,13 @@ public class CcToolchainFeatures implements Serializable { } return new NestedView(viewMap, sequenceName, sequenceVariables.get(sequenceName)); } + + /** + * Returns whether {@code variable} is set. + */ + private boolean isAvailable(String variable) { + return variables.containsKey(variable) || sequenceVariables.containsKey(variable); + } } /** |