use of com.google.devtools.build.lib.rules.java.ProtoJavaApiInfoProvider in project bazel by bazelbuild.
the class ActionReuser method reuseExistingActions.
/**
* If the underlying proto_library rule already registers the compile actions we need, just reuse
* them. This will preserve memory.
*
* <p>TODO(b/36191931): Delete when it's time.
*/
public static boolean reuseExistingActions(ConfiguredTarget base, RuleContext ruleContext, ConfiguredAspect.Builder aspect) {
if (!ruleContext.getConfiguration().getFragment(ProtoConfiguration.class).reuseJavaCompileActionsFromProtoLibrary()) {
return false;
}
ProtoJavaApiInfoProvider javaApi = base.getProvider(ProtoJavaApiInfoProvider.class);
if (javaApi == null) {
return false;
}
JavaCompilationArgs directJars = javaApi.getJavaCompilationArgsImmutable();
if (isEmpty(directJars.getCompileTimeJars()) || javaApi.sourceJarImmutable() == null) {
return false;
}
JavaCompilationArgs transitiveJars = JavaCompilationArgs.builder().addTransitiveArgs(javaApi.getTransitiveJavaCompilationArgsImmutable(), BOTH).addTransitiveDependencies(javaApi.getProtoRuntimeImmutable(), true).addTransitiveArgs(directJars, BOTH).build();
Artifact outputJar = getOnlyElement(directJars.getRuntimeJars());
Artifact compileTimeJar = getOnlyElement(directJars.getCompileTimeJars());
Artifact sourceJar = checkNotNull(javaApi.sourceJarImmutable());
JavaCompilationArgsProvider compilationArgsProvider = JavaCompilationArgsProvider.create(directJars, transitiveJars, NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER), NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER));
JavaSkylarkApiProvider.Builder skylarkApiProvider = JavaSkylarkApiProvider.builder().setRuleOutputJarsProvider(createOutputJarProvider(outputJar, compileTimeJar, sourceJar)).setSourceJarsProvider(createSrcJarProvider(sourceJar)).setCompilationArgsProvider(compilationArgsProvider);
NestedSet<Artifact> transitiveOutputJars = NestedSetBuilder.fromNestedSets(transform(ruleContext.getPrerequisites("deps", TARGET, JavaProtoLibraryTransitiveFilesToBuildProvider.class), GET_JARS)).add(outputJar).build();
aspect.addSkylarkTransitiveInfo(JavaSkylarkApiProvider.PROTO_NAME.getLegacyId(), skylarkApiProvider.build()).addProviders(new JavaProtoLibraryTransitiveFilesToBuildProvider(transitiveOutputJars), new JavaCompilationArgsAspectProvider(compilationArgsProvider));
return true;
}
Aggregations