|
14 | 14 |
|
15 | 15 | package com.google.devtools.build.lib.rules.genrule;
|
16 | 16 |
|
| 17 | +import com.google.common.base.Joiner; |
17 | 18 | import com.google.common.collect.ImmutableList;
|
18 | 19 | import com.google.common.collect.ImmutableMap;
|
19 | 20 | import com.google.common.collect.Iterables;
|
|
56 | 57 | */
|
57 | 58 | public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
|
58 | 59 |
|
59 |
| - private static final Pattern CROSSTOOL_MAKE_VARIABLE = |
60 |
| - Pattern.compile("\\$\\((CC|CC_FLAGS|AR|NM|OBJCOPY|STRIP|GCOVTOOL)\\)"); |
61 |
| - private static final Pattern JDK_MAKE_VARIABLE = |
62 |
| - Pattern.compile("\\$\\((JAVABASE|JAVA)\\)"); |
| 60 | + private static final ImmutableList<String> CROSSTOOL_MAKE_VARIABLES = ImmutableList.of("CC", |
| 61 | + "CC_FLAGS", "AR", "NM", "OBJCOPY", "STRIP", "GCOVTOOL"); |
| 62 | + |
| 63 | + private static final ImmutableList<String> JDK_MAKE_VARIABLES = ImmutableList.of("JAVABASE", |
| 64 | + "JAVA"); |
| 65 | + |
| 66 | + private static Pattern matchesMakeVariables(Iterable<String> variables) { |
| 67 | + return Pattern.compile("\\$\\((" + Joiner.on("|").join(variables) + ")\\)"); |
| 68 | + } |
| 69 | + |
| 70 | + private static final Pattern CROSSTOOL_MAKE_VARIABLE_PATTERN = |
| 71 | + matchesMakeVariables(CROSSTOOL_MAKE_VARIABLES); |
| 72 | + private static final Pattern JDK_MAKE_VARIABLE = matchesMakeVariables(JDK_MAKE_VARIABLES); |
63 | 73 |
|
64 | 74 | protected static boolean requiresCrosstool(String command) {
|
65 |
| - return CROSSTOOL_MAKE_VARIABLE.matcher(command).find(); |
| 75 | + return CROSSTOOL_MAKE_VARIABLE_PATTERN.matcher(command).find(); |
66 | 76 | }
|
67 | 77 |
|
68 | 78 | protected boolean requiresJdk(String command) {
|
@@ -341,9 +351,13 @@ public String lookupVariable(String variableName) throws ExpansionException {
|
341 | 351 | }
|
342 | 352 | }
|
343 | 353 |
|
344 |
| - String valueFromToolchains = resolveVariableFromToolchains(variableName); |
345 |
| - if (valueFromToolchains != null) { |
346 |
| - return valueFromToolchains; |
| 354 | + // Make variables provided by the :cc_toolchain attributes should not be overridden by |
| 355 | + // those provided by the toolchains attribute. |
| 356 | + if (!CROSSTOOL_MAKE_VARIABLES.contains(variableName)) { |
| 357 | + String valueFromToolchains = resolveVariableFromToolchains(variableName); |
| 358 | + if (valueFromToolchains != null) { |
| 359 | + return valueFromToolchains; |
| 360 | + } |
347 | 361 | }
|
348 | 362 |
|
349 | 363 | return super.lookupVariable(variableName);
|
|
0 commit comments