aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Marcel Hlopko <hlopko@google.com>2017-01-03 14:28:07 +0000
committerGravatar John Cater <jcater@google.com>2017-01-03 15:06:24 +0000
commit2b6279a8a0afed3dcd1a4126aa141babaa7bd318 (patch)
tree955b7ad320ea7f8f4ef8c806dad6a414f4e017ef /src
parent536d9cb8c7bc9798dc8d5015bea6c7ec2501a312 (diff)
Add expand_if_equal crosstool.proto message
This will be used by LibrariesToLinkValue to switch on many different types of libraries. -- PiperOrigin-RevId: 143438434 MOS_MIGRATED_REVID=143438434
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java27
-rw-r--r--src/main/protobuf/crosstool_config.proto8
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java20
3 files changed, 55 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 2c3a139b7c..4e763cb538 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
@@ -331,6 +331,17 @@ public class CcToolchainFeatures implements Serializable {
}
}
+ @Immutable
+ private static class VariableWithValue {
+ public final String variable;
+ public final String value;
+
+ public VariableWithValue(String variable, String value) {
+ this.variable = variable;
+ this.value = value;
+ }
+ }
+
/**
* A group of flags. When iterateOverVariable is specified, we assume the variable is a sequence
* and the flag_group will be expanded repeatedly for every value in the sequence.
@@ -343,6 +354,7 @@ public class CcToolchainFeatures implements Serializable {
private final ImmutableSet<String> expandIfAllAvailable;
private final String expandIfTrue;
private final String expandIfFalse;
+ private final VariableWithValue expandIfEqual;
/**
* TODO(b/32655571): Cleanup and get rid of usedVariables field once implicit iteration is not
@@ -380,6 +392,13 @@ public class CcToolchainFeatures implements Serializable {
this.expandIfAllAvailable = ImmutableSet.copyOf(flagGroup.getExpandIfAllAvailableList());
this.expandIfTrue = Strings.emptyToNull(flagGroup.getExpandIfTrue());
this.expandIfFalse = Strings.emptyToNull(flagGroup.getExpandIfFalse());
+ if (flagGroup.hasExpandIfEqual()) {
+ this.expandIfEqual = new VariableWithValue(
+ flagGroup.getExpandIfEqual().getVariable(),
+ flagGroup.getExpandIfEqual().getValue());
+ } else {
+ this.expandIfEqual = null;
+ }
}
@Override
@@ -421,6 +440,14 @@ public class CcToolchainFeatures implements Serializable {
&& variables.getVariable(expandIfFalse).isTruthy()) {
return false;
}
+ if (expandIfEqual != null
+ && (!variables.isAvailable(expandIfEqual.variable)
+ || !variables
+ .getVariable(expandIfEqual.variable)
+ .getStringValue(expandIfEqual.variable)
+ .equals(expandIfEqual.value))) {
+ return false;
+ }
return true;
}
diff --git a/src/main/protobuf/crosstool_config.proto b/src/main/protobuf/crosstool_config.proto
index 190c3f546e..88d280d233 100644
--- a/src/main/protobuf/crosstool_config.proto
+++ b/src/main/protobuf/crosstool_config.proto
@@ -104,6 +104,14 @@ message CToolchain {
optional string expand_if_true = 5;
optional string expand_if_false = 6;
+
+ optional VariableWithValue expand_if_equal = 7;
+ }
+
+ message VariableWithValue {
+ required string variable = 1;
+
+ required string value = 2;
}
// A key/value pair to be added as an environment variable. The value of
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 9efbb6229d..949aa4297b 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
@@ -572,6 +572,26 @@ public class CcToolchainFeaturesTest {
}
@Test
+ public void testExpandIfEqual() throws Exception {
+ assertThat(
+ getCommandLineForFlagGroups(
+ "flag_group {"
+ + " expand_if_equal: { variable: 'var' value: 'equal_value' }"
+ + " flag: '-foo_%{var}'"
+ + "}"
+ + "flag_group {"
+ + " expand_if_equal: { variable: 'var' value: 'non_equal_value' }"
+ + " flag: '-bar_%{var}'"
+ + "}"
+ + "flag_group {"
+ + " expand_if_equal: { variable: 'non_existing_var' value: 'non_existing' }"
+ + " flag: '-baz_%{non_existing_var}'"
+ + "}",
+ createVariables("var", "equal_value")))
+ .containsExactly("-foo_equal_value");
+ }
+
+ @Test
public void testLegacyListVariableExpansion() throws Exception {
assertThat(getCommandLineForFlag("%{v}", createVariables("v", "1", "v", "2")))
.containsExactly("1", "2");