Skip to content

Commit

Permalink
Removing javac attribute from java_toolchain rule.
Browse files Browse the repository at this point in the history
javac can be specified using tools attribute. It is not provided by JavaToolchain provider any more.

LocationBuilder in JavaToolchain class can be removed, because alias resolution in $location function was fixed with b/117612331.

RELNOTES[inc]: Removing javac attribute from java_toolchain.

PiperOrigin-RevId: 343801252
  • Loading branch information
comius authored and copybara-github committed Nov 23, 2020
1 parent 72adb5b commit 549db25
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
import static com.google.common.collect.Iterables.getOnlyElement;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
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.PrerequisiteArtifacts;
Expand All @@ -33,9 +31,7 @@
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
Expand All @@ -61,7 +57,6 @@ public ConfiguredTarget create(RuleContext ruleContext)
ruleContext.attributes().get("javac_supports_workers", Type.BOOLEAN);
boolean javacSupportsMultiplexWorkers =
ruleContext.attributes().get("javac_supports_multiplex_workers", Type.BOOLEAN);
Artifact javac = ruleContext.getPrerequisiteArtifact("javac");
FilesToRunProvider javabuilder = ruleContext.getExecutablePrerequisite("javabuilder");
FilesToRunProvider headerCompiler = ruleContext.getExecutablePrerequisite("header_compiler");
FilesToRunProvider headerCompilerDirect =
Expand Down Expand Up @@ -89,29 +84,17 @@ public ConfiguredTarget create(RuleContext ruleContext)
getCompatibleJavacOptions(ruleContext);

NestedSet<Artifact> tools = PrerequisiteArtifacts.nestedSet(ruleContext, "tools");
if (javac != null) {
tools = NestedSetBuilder.fromNestedSet(tools).add(javac).build();
}

TransitiveInfoCollection javacDep = ruleContext.getPrerequisite("javac");

ImmutableMap.Builder<Label, ImmutableCollection<Artifact>> locationsBuilder =
ImmutableMap.builder();
if (javacDep != null) {
locationsBuilder.put(AliasProvider.getDependencyLabel(javacDep), ImmutableList.of(javac));
}
ImmutableMap<Label, ImmutableCollection<Artifact>> locations = locationsBuilder.build();

ImmutableList<String> jvmOpts = getJvmOpts(ruleContext, locations, "jvm_opts");
ImmutableList<String> jvmOpts = getJvmOpts(ruleContext, "jvm_opts");
ImmutableList<String> javabuilderJvmOpts =
ImmutableList.<String>builder()
.addAll(jvmOpts)
.addAll(getJvmOpts(ruleContext, locations, "javabuilder_jvm_opts"))
.addAll(getJvmOpts(ruleContext, "javabuilder_jvm_opts"))
.build();
ImmutableList<String> turbineJvmOpts =
ImmutableList.<String>builder()
.addAll(jvmOpts)
.addAll(getJvmOpts(ruleContext, locations, "turbine_jvm_opts"))
.addAll(getJvmOpts(ruleContext, "turbine_jvm_opts"))
.build();

ImmutableList<JavaPackageConfigurationProvider> packageConfiguration =
Expand Down Expand Up @@ -196,9 +179,8 @@ private static ImmutableListMultimap<String, String> getCompatibleJavacOptions(

private static ImmutableList<String> getJvmOpts(
RuleContext ruleContext,
ImmutableMap<Label, ImmutableCollection<Artifact>> locations,
String attribute) {
return ruleContext.getExpander().withExecLocations(locations).list(attribute);
return ruleContext.getExpander().withExecLocations(ImmutableMap.of()).list(attribute);
}

private static BootClassPathInfo getBootClassPathInfo(RuleContext ruleContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,6 @@ The Java target version (e.g., '6' or '7'). It specifies for which Java runtime
True if JavaBuilder supports running as a multiplex persistent worker, false if it doesn't.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("javac_supports_multiplex_workers", BOOLEAN).value(true))
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(javac) -->
Label of the javac jar.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr("javac", LABEL_LIST)
// This needs to be in the execution configuration.
.cfg(ExecutionTransitionFactory.create())
.singleArtifact()
.allowedFileTypes(FileTypeSet.ANY_FILE))
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(tools) -->
Labels of tools available for label-expansion in jvm_opts.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
Expand Down

0 comments on commit 549db25

Please sign in to comment.