diff options
Diffstat (limited to 'src/main')
3 files changed, 30 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Expander.java b/src/main/java/com/google/devtools/build/lib/analysis/Expander.java index 69f45f9cc4..ae42c935f2 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/Expander.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/Expander.java @@ -13,8 +13,12 @@ // limitations under the License. package com.google.devtools.build.lib.analysis; +import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.LocationExpander.Options; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.shell.ShellUtils; import com.google.devtools.build.lib.syntax.Type; import java.util.ArrayList; @@ -77,6 +81,16 @@ public final class Expander { } /** + * Returns a new instance that also expands locations, passing the given location map, as well as + * {@link Options#EXEC_PATHS} to the underlying {@link LocationExpander}. + */ + public Expander withExecLocations(ImmutableMap<Label, ImmutableCollection<Artifact>> locations) { + LocationExpander newLocationExpander = + new LocationExpander(ruleContext, locations, Options.EXEC_PATHS); + return new Expander(ruleContext, makeVariableContext, newLocationExpander); + } + + /** * Expands the given value string, tokenizes it, and then adds it to the given list. The attribute * name is only used for error reporting. */ diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java index 9d3fa1d127..46c1493b07 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java @@ -95,6 +95,21 @@ public class LocationExpander { } /** + * Creates location expander helper bound to specific target and with default location map. + * + * @param ruleContext BUILD rule + * @param labelMap A mapping of labels to build artifacts. + * @param options the list of options, see {@link Options} + */ + public LocationExpander( + RuleContext ruleContext, ImmutableMap<Label, ImmutableCollection<Artifact>> labelMap, + Options... options) { + this.ruleContext = ruleContext; + this.options = ImmutableSet.copyOf(options); + this.labelMap = labelMap; + } + + /** * Creates location expander helper bound to specific target. * * @param ruleContext the BUILD rule's context diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java index 35102f374e..8e03989803 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java @@ -21,7 +21,6 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.AliasProvider; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.FilesToRunProvider; -import com.google.devtools.build.lib.analysis.LocationExpander; import com.google.devtools.build.lib.analysis.PrerequisiteArtifacts; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; @@ -137,14 +136,6 @@ public final class JavaToolchain implements RuleConfiguredTargetFactory { private static ImmutableList<String> getJvmOpts( RuleContext ruleContext, ImmutableMap<Label, ImmutableCollection<Artifact>> locations) { - // LocationExpander is used directly instead of e.g. getExpandedStringListAttr because the - // latter hard-codes list of attributes that can provide prerequisites. - LocationExpander expander = - new LocationExpander(ruleContext, locations, /*allowDataAttributeEntriesInLabel=*/ false); - ImmutableList.Builder<String> result = ImmutableList.builder(); - for (String option : ruleContext.attributes().get("jvm_opts", Type.STRING_LIST)) { - result.add(expander.expand(option)); - } - return result.build(); + return ruleContext.getExpander().withExecLocations(locations).list("jvm_opts"); } } |