aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-09-27 09:12:49 -0400
committerGravatar John Cater <jcater@google.com>2017-09-27 10:01:45 -0400
commitf58ba409ef6b65a38fdaa4ddf3e67c44e897f1d7 (patch)
tree75a6c073cde821e6409fe5998d04bb70f33c276e /src/main
parent9c445faa58aeff5ee70581bf5479472a08e3ef14 (diff)
Rewrite CppHelper linkopts expansion to take a list and return a list
Progress on #2475. PiperOrigin-RevId: 170187908
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java31
2 files changed, 26 insertions, 19 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 c945a72ae7..343d3c7dd0 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
@@ -127,17 +127,17 @@ public final class CcCommon {
*/
public ImmutableList<String> getLinkopts() {
Preconditions.checkState(hasAttribute("linkopts", Type.STRING_LIST));
- List<String> ourLinkopts = ruleContext.attributes().get("linkopts", Type.STRING_LIST);
- List<String> result = new ArrayList<>();
+ Iterable<String> ourLinkopts = ruleContext.attributes().get("linkopts", Type.STRING_LIST);
+ List<String> result;
if (ourLinkopts != null) {
boolean allowDashStatic = !cppConfiguration.forceIgnoreDashStatic()
&& (cppConfiguration.getDynamicMode() != DynamicMode.FULLY);
- for (String linkopt : ourLinkopts) {
- if (linkopt.equals("-static") && !allowDashStatic) {
- continue;
- }
- CppHelper.expandAttribute(ruleContext, result, "linkopts", linkopt, true);
+ if (!allowDashStatic) {
+ ourLinkopts = Iterables.filter(ourLinkopts, (v) -> !"-static".equals(v));
}
+ result = CppHelper.expandLinkopts(ruleContext, "linkopts", ourLinkopts);
+ } else {
+ result = ImmutableList.of();
}
if (ApplePlatform.isApplePlatform(cppConfiguration.getTargetCpu())
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
index 21714bbf33..83649b6267 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
@@ -199,20 +199,27 @@ public class CppHelper {
* (if attemptLabelExpansion == {@code true} and it does not look like make
* variable or flag) or tokenizes and expands make variables.
*/
- public static void expandAttribute(RuleContext ruleContext,
- List<String> result, String attrName, String attrValue, boolean attemptLabelExpansion) {
- if (attemptLabelExpansion && CppHelper.isLinkoptLabel(attrValue)) {
- if (!CppHelper.expandLabel(ruleContext, result, attrValue)) {
- ruleContext.attributeError(attrName, "could not resolve label '" + attrValue + "'");
+ public static List<String> expandLinkopts(
+ RuleContext ruleContext, String attrName, Iterable<String> values) {
+ List<String> result = new ArrayList<>();
+ ConfigurationMakeVariableContext makeVariableContext =
+ ruleContext.getConfigurationMakeVariableContext(
+ ImmutableList.of(new CcFlagsSupplier(ruleContext)));
+ for (String value : values) {
+ if (isLinkoptLabel(value)) {
+ if (!expandLabel(ruleContext, result, value)) {
+ ruleContext.attributeError(attrName, "could not resolve label '" + value + "'");
+ }
+ } else {
+ ruleContext
+ .tokenizeAndExpandMakeVars(
+ result,
+ attrName,
+ value,
+ makeVariableContext);
}
- } else {
- ruleContext.tokenizeAndExpandMakeVars(
- result,
- attrName,
- attrValue,
- ruleContext.getConfigurationMakeVariableContext(
- ImmutableList.of(new CcFlagsSupplier(ruleContext))));
}
+ return result;
}
/**