Skip to content

Commit

Permalink
Also forward the exported_plugins of the rules in the deps of an
Browse files Browse the repository at this point in the history
android_library rule when the android_library is being used as a forwarding rule
(i.e., has no sources).

RELNOTES: When used as a forwarding rule (i.e., has no sources), android_library
will also forward any exported_plugins in its dependencies.

--
MOS_MIGRATED_REVID=105787789
  • Loading branch information
ahumesky authored and philwo committed Oct 20, 2015
1 parent 98ea68a commit 49ceb1b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts;
import com.google.devtools.build.lib.rules.java.JavaCompilationHelper;
import com.google.devtools.build.lib.rules.java.JavaNativeLibraryProvider;
import com.google.devtools.build.lib.rules.java.JavaPluginInfoProvider;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider;
import com.google.devtools.build.lib.rules.java.JavaSemantics;
Expand Down Expand Up @@ -88,6 +89,7 @@ public class AndroidCommon {
private NestedSet<Artifact> transitiveSourceJars = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
private JavaCompilationArgs javaCompilationArgs = JavaCompilationArgs.EMPTY_ARGS;
private JavaCompilationArgs recursiveJavaCompilationArgs = JavaCompilationArgs.EMPTY_ARGS;
private JavaPluginInfoProvider transitiveJavaPluginInfoProvider = JavaPluginInfoProvider.EMPTY;
private JackCompilationHelper jackCompilationHelper;
private Artifact classJar;
private Artifact iJar;
Expand Down Expand Up @@ -566,8 +568,16 @@ private void initJava(
topLevelSourceJars = ImmutableList.of(srcJar);
transitiveSourceJars = javaCommon.collectTransitiveSourceJars(srcJar);

boolean hasSources = attributes.hasSourceFiles() || attributes.hasSourceJars();

if (!hasSources) {
// If this android rule has no sources, then it's a forwarding rule, so also forward
// any exported java plugins from its deps.
this.transitiveJavaPluginInfoProvider = JavaPluginInfoProvider.merge(
javaCommon.getPluginInfoProvidersForAttribute("deps", Mode.TARGET));
}

if (collectJavaCompilationArgs) {
boolean hasSources = attributes.hasSourceFiles() || attributes.hasSourceJars();
this.javaCompilationArgs =
collectJavaCompilationArgs(ruleContext, exportDeps, asNeverLink, hasSources);
this.recursiveJavaCompilationArgs = collectJavaCompilationArgs(
Expand Down Expand Up @@ -616,6 +626,7 @@ public RuleConfiguredTargetBuilder addTransitiveInfoProviders(
asNeverLink
? jackCompilationHelper.compileAsNeverlinkLibrary()
: jackCompilationHelper.compileAsLibrary())
.add(JavaPluginInfoProvider.class, transitiveJavaPluginInfoProvider)
.addOutputGroup(
OutputGroupProvider.HIDDEN_TOP_LEVEL, collectHiddenTopLevelArtifacts(ruleContext))
.addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveSourceJars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ private ImmutableList<JavaPluginInfoProvider> collectPlugins() {
return ImmutableList.copyOf(result);
}

Iterable<JavaPluginInfoProvider> getPluginInfoProvidersForAttribute(String attribute,
public Iterable<JavaPluginInfoProvider> getPluginInfoProvidersForAttribute(String attribute,
Mode mode) {
if (ruleContext.attributes().has(attribute, BuildType.LABEL_LIST)) {
return ruleContext.getPrerequisites(attribute, mode, JavaPluginInfoProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,9 @@ public RuleConfiguredTargetBuilder init(RuleContext ruleContext, final JavaCommo
NestedSet<LinkerInput> transitiveJavaNativeLibraries =
common.collectTransitiveJavaNativeLibraries();

ImmutableList<String> exportedProcessorClasses = ImmutableList.of();
NestedSet<Artifact> exportedProcessorClasspath =
NestedSetBuilder.emptySet(Order.NAIVE_LINK_ORDER);
ImmutableList.Builder<String> processorClasses = ImmutableList.builder();
NestedSetBuilder<Artifact> processorClasspath = NestedSetBuilder.naiveLinkOrder();
for (JavaPluginInfoProvider provider : Iterables.concat(
common.getPluginInfoProvidersForAttribute("exported_plugins", Mode.HOST),
common.getPluginInfoProvidersForAttribute("exports", Mode.TARGET))) {
processorClasses.addAll(provider.getProcessorClasses());
processorClasspath.addTransitive(provider.getProcessorClasspath());
}
exportedProcessorClasses = processorClasses.build();
exportedProcessorClasspath = processorClasspath.build();
JavaPluginInfoProvider javaPluginInfoProvider = JavaPluginInfoProvider.merge(Iterables.concat(
common.getPluginInfoProvidersForAttribute("exported_plugins", Mode.HOST),
common.getPluginInfoProvidersForAttribute("exports", Mode.TARGET)));

CcLinkParamsStore ccLinkParamsStore = new CcLinkParamsStore() {
@Override
Expand Down Expand Up @@ -249,8 +239,7 @@ protected void collect(CcLinkParams.Builder builder, boolean linkingStatically,
.add(JavaSourceJarsProvider.class, new JavaSourceJarsProvider(
transitiveSourceJars, ImmutableList.of(srcJar)))
// TODO(bazel-team): this should only happen for java_plugin
.add(JavaPluginInfoProvider.class, new JavaPluginInfoProvider(
exportedProcessorClasses, exportedProcessorClasspath))
.add(JavaPluginInfoProvider.class, javaPluginInfoProvider)
.add(ProguardSpecProvider.class, new ProguardSpecProvider(proguardSpecs))
.addOutputGroup(JavaSemantics.SOURCE_JARS_OUTPUT_GROUP, transitiveSourceJars)
.addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL, proguardSpecs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,34 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
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;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;

/**
* Provider for users of Java plugins.
*/
@Immutable
public final class JavaPluginInfoProvider implements TransitiveInfoProvider {

public static final JavaPluginInfoProvider EMPTY =
new JavaPluginInfoProvider(
ImmutableList.<String>of(),
NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER));

public static JavaPluginInfoProvider merge(Iterable<JavaPluginInfoProvider> providers) {

ImmutableList.Builder<String> processorClasses = ImmutableList.builder();
NestedSetBuilder<Artifact> processorClasspath = NestedSetBuilder.naiveLinkOrder();

for (JavaPluginInfoProvider provider : providers) {
processorClasses.addAll(provider.getProcessorClasses());
processorClasspath.addTransitive(provider.getProcessorClasspath());
}

return new JavaPluginInfoProvider(processorClasses.build(), processorClasspath.build());
}

private final ImmutableList<String> processorClasses;
private final NestedSet<Artifact> processorClasspath;

Expand Down

0 comments on commit 49ceb1b

Please sign in to comment.