Skip to content

Commit

Permalink
Make JavaToolchain use the new Expander API
Browse files Browse the repository at this point in the history
Progress on bazelbuild#2475.

PiperOrigin-RevId: 170671644
  • Loading branch information
ulfjack authored and aehlig committed Oct 2, 2017
1 parent 06feddc commit f9a1f6f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/Expander.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +80,16 @@ public Expander withDataExecLocations() {
return withLocations(Options.ALLOW_DATA, Options.EXEC_PATHS);
}

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ public LocationExpander(
this.labelMap = labelMap;
}

/**
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;
Expand Down Expand Up @@ -137,14 +136,6 @@ private static ImmutableListMultimap<String, String> getCompatibleJavacOptions(

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");
}
}

0 comments on commit f9a1f6f

Please sign in to comment.