Skip to content

Commit

Permalink
RELNOTES: aar_import now sets java.transitive_exports.
Browse files Browse the repository at this point in the history
This field is needed by the Android Studio with Bazel plugin.

PiperOrigin-RevId: 187053906
  • Loading branch information
aj-michael authored and Copybara-Service committed Feb 26, 2018
1 parent 06374a8 commit 677e6f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.java.JavaCommon;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts;
import com.google.devtools.build.lib.rules.java.JavaInfo;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar;
import com.google.devtools.build.lib.rules.java.JavaRuntimeInfo;
import com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider;
import com.google.devtools.build.lib.rules.java.JavaSemantics;
Expand Down Expand Up @@ -105,21 +105,14 @@ public ConfiguredTarget create(RuleContext ruleContext)
// build could be empty. The resources zip and merged jars are added here as a sanity check for
// Bazel developers so that `bazel build java/com/my_aar_import` will fail if the resource
// processing or jar merging steps fail.
NestedSetBuilder<Artifact> filesToBuildBuilder =
NestedSetBuilder.<Artifact>stableOrder().add(resourcesZip).add(mergedJar);
NestedSet<Artifact> filesToBuild =
NestedSetBuilder.<Artifact>stableOrder().add(resourcesZip).add(mergedJar).build();

Artifact nativeLibs = createAarArtifact(ruleContext, "native_libs.zip");
ruleContext.registerAction(createAarNativeLibsFilterActions(ruleContext, aar, nativeLibs));

JavaRuleOutputJarsProvider.Builder jarProviderBuilder =
new JavaRuleOutputJarsProvider.Builder().addOutputJar(mergedJar, null, ImmutableList.of());
for (TransitiveInfoCollection export : ruleContext.getPrerequisites("exports", Mode.TARGET)) {
for (OutputJar jar :
JavaInfo.getProvider(JavaRuleOutputJarsProvider.class, export).getOutputJars()) {
jarProviderBuilder.addOutputJar(jar);
filesToBuildBuilder.add(jar.getClassJar());
}
}

ImmutableList<TransitiveInfoCollection> targets =
ImmutableList.<TransitiveInfoCollection>builder()
Expand All @@ -140,7 +133,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
.addCompileTimeJarAsFullJar(mergedJar)
.build());

JavaInfo javaInfo =
JavaInfo.Builder javaInfoBuilder =
JavaInfo.Builder.create()
.addProvider(
JavaCompilationArgsProvider.class,
Expand All @@ -153,11 +146,13 @@ public ConfiguredTarget create(RuleContext ruleContext)
/* recursive = */ true,
JavaCommon.isNeverLink(ruleContext),
/* srcLessDepsExport = */ false)))
.addProvider(JavaRuleOutputJarsProvider.class, jarProviderBuilder.build())
.build();
.addProvider(JavaRuleOutputJarsProvider.class, jarProviderBuilder.build());

common.addTransitiveInfoProviders(
ruleBuilder, javaInfoBuilder, filesToBuild, /*classJar=*/ null);

return ruleBuilder
.setFilesToBuild(filesToBuildBuilder.build())
.setFilesToBuild(filesToBuild)
.addSkylarkTransitiveInfo(
JavaSkylarkApiProvider.NAME, JavaSkylarkApiProvider.fromRuleContext())
.addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY)
Expand All @@ -167,7 +162,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
AndroidCommon.collectTransitiveNativeLibs(ruleContext).add(nativeLibs).build()))
.addProvider(
JavaRuntimeJarProvider.class, new JavaRuntimeJarProvider(ImmutableList.of(mergedJar)))
.addNativeDeclaredProvider(javaInfo)
.addNativeDeclaredProvider(javaInfoBuilder.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.configuredtargets.FileConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.JavaInfo;
Expand Down Expand Up @@ -300,4 +301,10 @@ private String getAndroidManifest(String aarImport) throws Exception {
.getManifest()
.getRootRelativePathString();
}

@Test
public void testTransitiveExports() throws Exception {
assertThat(getConfiguredTarget("//a:bar").get(JavaInfo.PROVIDER).getTransitiveExports())
.containsExactly(Label.parseAbsolute("//a:foo"), Label.parseAbsolute("//java:baz"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib:build-base",
"//src/main/java/com/google/devtools/build/lib:java-compilation",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/test/java/com/google/devtools/build/lib:actions_testutil",
"//src/test/java/com/google/devtools/build/lib:analysis_testutil",
Expand Down

0 comments on commit 677e6f7

Please sign in to comment.