Skip to content

Commit

Permalink
Update usages of JavaPluginInfo provider to prepare for the Starlar…
Browse files Browse the repository at this point in the history
…k version

PiperOrigin-RevId: 539975999
Change-Id: If79362a070ca1bb37768d574443938a377077855
  • Loading branch information
hvadehra authored and Copybara-Service committed Jun 13, 2023
1 parent 608d7bc commit e66a87b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ public RuleConfiguredTargetBuilder addTransitiveInfoProviders(
Iterable<Artifact> apksUnderTest,
NativeLibs nativeLibs,
boolean isNeverlink,
boolean isLibrary) {
boolean isLibrary)
throws RuleErrorException {

idlHelper.addTransitiveInfoProviders(builder, classJar, outputs.manifestProto());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ public static void addPlugins(
attributes.addPlugin(activePlugins);
}

private JavaPluginInfo collectPlugins() {
private JavaPluginInfo collectPlugins() throws RuleErrorException {
List<JavaPluginInfo> result = new ArrayList<>();
Iterables.addAll(result, getDirectJavaPluginInfoForAttribute(ruleContext, ":java_plugins"));
Iterables.addAll(result, getDirectJavaPluginInfoForAttribute(ruleContext, "plugins"));
Expand All @@ -783,12 +783,16 @@ private JavaPluginInfo collectPlugins() {
}

private static Iterable<JavaPluginInfo> getDirectJavaPluginInfoForAttribute(
RuleContext ruleContext, String attribute) {
RuleContext ruleContext, String attribute) throws RuleErrorException {
if (ruleContext.attributes().has(attribute, BuildType.LABEL_LIST)) {
return ruleContext.getPrerequisites(attribute).stream()
.map(target -> target.get(JavaPluginInfo.PROVIDER))
.filter(Objects::nonNull)
.collect(toImmutableList());
ImmutableList.Builder<JavaPluginInfo> builder = ImmutableList.builder();
for (TransitiveInfoCollection target : ruleContext.getPrerequisites(attribute)) {
JavaPluginInfo javaPluginInfo = target.get(JavaPluginInfo.PROVIDER);
if (javaPluginInfo != null) {
builder.add(javaPluginInfo);
}
}
return builder.build();
}
return ImmutableList.of();
}
Expand All @@ -806,7 +810,8 @@ private static Iterable<JavaPluginInfo> getExportedJavaPluginInfoForAttribute(
return ImmutableList.of();
}

public static JavaPluginInfo getTransitivePlugins(RuleContext ruleContext) {
public static JavaPluginInfo getTransitivePlugins(RuleContext ruleContext)
throws RuleErrorException {
return JavaPluginInfo.mergeWithoutJavaOutputs(
Iterables.concat(
getDirectJavaPluginInfoForAttribute(ruleContext, "exported_plugins"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public JavaInfo javaInfo(
Object jdepsApi,
Sequence<?> nativeLibraries,
StarlarkThread thread)
throws EvalException {
throws EvalException, RuleErrorException {
Artifact outputJar = (Artifact) outputJarApi;
@Nullable Artifact compileJar = nullIfNone(compileJarApi, Artifact.class);
@Nullable Artifact sourceJar = nullIfNone(sourceJarApi, Artifact.class);
Expand All @@ -587,7 +587,7 @@ public JavaInfo javaInfo(
Sequence.cast(deps, JavaInfo.class, "deps"),
Sequence.cast(runtimeDeps, JavaInfo.class, "runtime_deps"),
Sequence.cast(exports, JavaInfo.class, "exports"),
Sequence.cast(exportedPlugins, JavaPluginInfo.class, "exported_plugins"),
JavaPluginInfo.wrapSequence(exportedPlugins, "exported_plugins"),
Sequence.cast(nativeLibraries, CcInfo.class, "native_libraries"),
thread.getCallerLocation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ JavaInfo createJavaInfo(
Sequence<JavaInfo> compileTimeDeps,
Sequence<JavaInfo> runtimeDeps,
Sequence<JavaInfo> exports,
Sequence<JavaPluginInfo> exportedPlugins,
Iterable<JavaPluginInfo> exportedPlugins,
Sequence<CcInfo> nativeLibraries,
Location location) {
JavaInfo.Builder javaInfoBuilder = JavaInfo.Builder.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.BuiltinProvider;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.rules.java.JavaPluginInfo.JavaPluginData;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput;
import com.google.devtools.build.lib.starlarkbuildapi.java.JavaPluginInfoApi;
Expand All @@ -46,6 +47,11 @@ public abstract class JavaPluginInfo extends NativeInfo
new AutoValue_JavaPluginInfo(
ImmutableList.of(), JavaPluginData.empty(), JavaPluginData.empty());

public static ImmutableList<JavaPluginInfo> wrapSequence(Sequence<?> plugins, String what)
throws EvalException, RuleErrorException {
return Sequence.cast(plugins, JavaPluginInfo.class, what).getImmutableList();
}

@Override
public Provider getProvider() {
return PROVIDER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.Provider;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.rules.cpp.CcInfo;
import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
Expand Down Expand Up @@ -113,7 +114,7 @@ public JavaInfo createJavaCompileAction(
Sequence<?> addExports, // <String> expected
Sequence<?> addOpens, // <String> expected
StarlarkThread thread)
throws EvalException, InterruptedException {
throws EvalException, InterruptedException, RuleErrorException {

boolean acceptJavaInfo =
!starlarkRuleContext
Expand All @@ -130,7 +131,7 @@ public JavaInfo createJavaCompileAction(
.filter(Objects::nonNull)
.collect(toImmutableList());
} else {
pluginsParam = Sequence.cast(plugins, JavaPluginInfo.class, "plugins").getImmutableList();
pluginsParam = JavaPluginInfo.wrapSequence(plugins, "plugins");
}

final ImmutableList<JavaPluginInfo> exportedPluginsParam;
Expand All @@ -144,9 +145,7 @@ public JavaInfo createJavaCompileAction(
.filter(Objects::nonNull)
.collect(toImmutableList());
} else {
exportedPluginsParam =
Sequence.cast(exportedPlugins, JavaPluginInfo.class, "exported_plugins")
.getImmutableList();
exportedPluginsParam = JavaPluginInfo.wrapSequence(exportedPlugins, "exported_plugins");
}
// checks for private API access
if (!enableCompileJarAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ java_library(
"//src/main/java/com/google/devtools/build/docgen/annot",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.Depset;
import com.google.devtools.build.lib.collect.nestedset.Depset.TypeException;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.starlarkbuildapi.FileApi;
import com.google.devtools.build.lib.starlarkbuildapi.StarlarkActionFactoryApi;
Expand Down Expand Up @@ -313,7 +314,7 @@ JavaInfoT createJavaCompileAction(
Sequence<?> addExports, // <String> expected.
Sequence<?> addOpens, // <String> expected.
StarlarkThread thread)
throws EvalException, InterruptedException;
throws EvalException, InterruptedException, RuleErrorException;

@StarlarkMethod(
name = "run_ijar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.devtools.build.docgen.annot.DocCategory;
import com.google.devtools.build.docgen.annot.StarlarkConstructor;
import com.google.devtools.build.lib.collect.nestedset.Depset;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.starlarkbuildapi.FileApi;
import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi;
Expand Down Expand Up @@ -352,6 +353,6 @@ interface JavaInfoProviderApi extends ProviderApi {
Object jdepsApi,
Sequence<?> nativeLibraries,
StarlarkThread thread)
throws EvalException;
throws EvalException, RuleErrorException;
}
}

0 comments on commit e66a87b

Please sign in to comment.