aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-10-02 10:05:01 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-10-02 10:32:02 +0200
commitf9a1f6f121a87478b5180ec5c9d01ec6d327b54c (patch)
tree5ba833117d83eb73fce5b2d0fb3f7d947b962b60 /src/main/java/com/google/devtools/build/lib
parent06feddcd3e56ae31cb3eaa8ce648b5c4f3da399c (diff)
Make JavaToolchain use the new Expander API
Progress on #2475. PiperOrigin-RevId: 170671644
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/Expander.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java11
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");
}
}