Skip to content

Commit

Permalink
Create gen source jar in java_common.compile().
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 193029216
  • Loading branch information
iirina authored and Copybara-Service committed Apr 16, 2018
1 parent 83ed546 commit 81d999d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ public static PathFragment getHostJavaExecutable(RuleContext ruleContext) {
return JavaRuntimeInfo.forHost(ruleContext).javaBinaryExecPath();
}

public static PathFragment getHostJavaExecutable(JavaRuntimeInfo javaRuntime) {
return javaRuntime.javaBinaryExecPath();
}

public static PathFragment getJavaExecutable(RuleContext ruleContext) {
return JavaRuntimeInfo.from(ruleContext).javaBinaryExecPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,18 +479,28 @@ public Artifact createManifestProtoOutput(Artifact outputJar) {
* @param manifestProto The artifact for the manifest proto emitted from JavaBuilder
* @param genClassJar The artifact for the gen jar to output
*/
public void createGenJarAction(Artifact classJar, Artifact manifestProto,
public void createGenJarAction(
Artifact classJar,
Artifact manifestProto,
Artifact genClassJar) {
createGenJarAction(
classJar, manifestProto, genClassJar, JavaRuntimeInfo.forHost(getRuleContext()));
}

public void createGenJarAction(Artifact classJar,
Artifact manifestProto,
Artifact genClassJar,
JavaRuntimeInfo hostJavabase) {
getRuleContext()
.registerAction(
new SpawnAction.Builder()
.addInput(manifestProto)
.addInput(classJar)
.addOutput(genClassJar)
.addTransitiveInputs(
JavaRuntimeInfo.forHost(getRuleContext()).javaBaseInputsMiddleman())
hostJavabase.javaBaseInputsMiddleman())
.setJarExecutable(
JavaCommon.getHostJavaExecutable(ruleContext),
JavaCommon.getHostJavaExecutable(hostJavabase),
getGenClassJar(ruleContext),
javaToolchain.getJvmOptions())
.addCommandLine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,21 @@ public JavaCompilationArtifacts build(
hostJavabase,
jacocoInstrumental);
Artifact outputDepsProto = helper.createOutputDepsProtoArtifact(output, artifactsBuilder);

Artifact manifestProtoOutput = helper.createManifestProtoOutput(output);

Artifact genSourceJar = null;
Artifact genClassJar = null;
if (helper.usesAnnotationProcessing()) {
genClassJar = helper.createGenJar(output);
genSourceJar = helper.createGensrcJar(output);
helper.createGenJarAction(output, manifestProtoOutput, genClassJar, hostJavabase);
}

helper.createCompileAction(
output,
/* manifestProtoOutput= */ null,
/* gensrcOutputJar= */ null,
manifestProtoOutput,
genSourceJar,
outputDepsProto,
/* instrumentationMetadataJar= */ null,
/* nativeHeaderOutput= */ null);
Expand All @@ -226,7 +237,8 @@ public JavaCompilationArtifacts build(
Artifact iJar = helper.createCompileTimeJarAction(output, artifactsBuilder);

if (createOutputSourceJar) {
helper.createSourceJarAction(outputSourceJar, null, javaToolchainProvider, hostJavabase);
helper.createSourceJarAction(
outputSourceJar, genSourceJar, javaToolchainProvider, hostJavabase);
}
ImmutableList<Artifact> outputSourceJars =
outputSourceJar == null ? ImmutableList.of() : ImmutableList.of(outputSourceJar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,14 @@ public void testJavaCommonCompileTransitiveSourceJars() throws Exception {
" host_javabase = ctx.attr._host_javabase",
" )",
" return struct(",
" files = depset([output_jar]),",
" files = depset([output_jar] + compilation_provider.source_jars),",
" providers = [compilation_provider]",
" )",
"java_custom_library = rule(",
" implementation = _impl,",
" outputs = {",
" 'my_output': 'lib%{name}.jar'",
" 'my_output': 'lib%{name}.jar',",
" 'my_src_output': 'lib%{name}-src.jar'",
" },",
" attrs = {",
" 'srcs': attr.label_list(allow_files=['.java']),",
Expand All @@ -365,6 +366,8 @@ public void testJavaCommonCompileTransitiveSourceJars() throws Exception {
assertThat(artifactFilesNames(sourceJars)).containsExactly("libcustom-src.jar");
assertThat(artifactFilesNames(transitiveSourceJars))
.containsExactly("libdep-src.jar", "libcustom-src.jar");

assertThat(getGeneratingAction(configuredTarget, "java/test/libcustom-src.jar")).isNotNull();
}

@Test
Expand Down

0 comments on commit 81d999d

Please sign in to comment.