Skip to content

Commit

Permalink
Fix dependency issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
iirina committed May 31, 2019
1 parent bfbef3b commit e0833c6
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ public Object getDefault(AttributeMap rule) {
return rule.get("create_executable", BOOLEAN);
}
}))
.add(
attr("$jacocorunner", LABEL)
.value(env.getToolsLabel("//tools/jdk:JacocoCoverageRunner")))
.addRequiredToolchains(CppRuleClasses.ccToolchainTypeAttribute(env))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,22 +670,12 @@ public Iterable<String> getJvmFlags(
public String addCoverageSupport(JavaCompilationHelper helper, Artifact executable) {
// This method can be called only for *_binary/*_test targets.
Preconditions.checkNotNull(executable);

if (!helper.addCoverageSupport()) {
// Fallback to $jacocorunner attribute if no jacocorunner was found in the toolchain.

// Add the coverage runner to the list of dependencies when compiling in coverage mode.
TransitiveInfoCollection runnerTarget =
helper.getRuleContext().getPrerequisite("$jacocorunner", Mode.TARGET);
if (JavaInfo.getProvider(JavaCompilationArgsProvider.class, runnerTarget) != null) {
helper.addLibrariesToAttributes(ImmutableList.of(runnerTarget));
} else {
helper
.getRuleContext()
.ruleError(
"this rule depends on "
+ helper.getRuleContext().attributes().get("$jacocorunner", BuildType.LABEL)
+ " which is not a java_library rule, or contains errors");
}
helper
.getRuleContext()
.ruleError(
"No jacocorunner attribute was found on the java_toolchain");
}

// We do not add the instrumented jar to the runtime classpath, but provide it in the shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
.override(attr(":java_launcher", LABEL).value(JavaSemantics.JAVA_LAUNCHER))
// Input files for test actions collecting code coverage
.add(attr(":lcov_merger", LABEL).value(BaseRuleClasses.getCoverageOutputGeneratorLabel()))
.add(
attr("$jacocorunner", LABEL)
.value(env.getToolsLabel("//tools/jdk:JacocoCoverageRunner")))
/* <!-- #BLAZE_RULE(java_test).ATTRIBUTE(test_class) -->
The Java class to be loaded by the test runner.<br/>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,17 @@ public ImmutableList<Artifact> getBootclasspathOrDefault() {
}

public boolean addCoverageSupport() {
TransitiveInfoCollection jacocoRunner = javaToolchain.getJacocoRunner();
if (jacocoRunner != null
&& JavaInfo.getProvider(JavaCompilationArgsProvider.class, jacocoRunner) != null) {
addLibrariesToAttributes(ImmutableList.of(jacocoRunner));
return true;
FilesToRunProvider jacocoRunner = javaToolchain.getJacocoRunner();
if (jacocoRunner == null) {
return false;
}
Artifact jacocoRunnerJar = jacocoRunner.getExecutable();
if(isStrict()) {
attributes.addDirectJar(jacocoRunnerJar);
}
return false;
attributes.addCompileTimeClassPathEntry(jacocoRunnerJar);
attributes.addRuntimeClassPathEntry(jacocoRunnerJar);
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public Builder addRuntimeClassPathEntries(NestedSet<Artifact> classPathEntries)
return this;
}

public Builder addCompileTimeClassPathEntry(Artifact entry) {
Preconditions.checkArgument(!built);
compileTimeClassPath.add(entry);
return this;
}

public Builder addCompileTimeClassPathEntries(NestedSet<Artifact> entries) {
Preconditions.checkArgument(!built);
compileTimeClassPath.addTransitive(entries);
Expand Down Expand Up @@ -233,6 +239,12 @@ public Builder addDirectJars(NestedSet<Artifact> directJars) {
return this;
}

public Builder addDirectJar(Artifact directJar) {
Preconditions.checkArgument(!built);
this.directJars.add(directJar);
return this;
}

public Builder addCompileTimeDependencyArtifacts(NestedSet<Artifact> dependencyArtifacts) {
Preconditions.checkArgument(!built);
compileTimeDependencyArtifacts.addTransitive(dependencyArtifacts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
ruleContext.getPrerequisites(
"package_configuration", Mode.HOST, JavaPackageConfigurationProvider.class));

TransitiveInfoCollection jacocoRunner = ruleContext.getPrerequisite("jacocorunner", Mode.HOST);
FilesToRunProvider jacocoRunner = ruleContext.getExecutablePrerequisite("jacocorunner", Mode.HOST);

JavaToolchainProvider provider =
JavaToolchainProvider.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static JavaToolchainProvider create(
FilesToRunProvider ijar,
ImmutableListMultimap<String, String> compatibleJavacOptions,
ImmutableList<JavaPackageConfigurationProvider> packageConfiguration,
TransitiveInfoCollection jacocoRunner,
FilesToRunProvider jacocoRunner,
JavaSemantics javaSemantics) {
return new JavaToolchainProvider(
label,
Expand Down Expand Up @@ -142,7 +142,7 @@ public static JavaToolchainProvider create(
private final ImmutableList<String> javabuilderJvmOptions;
private final boolean javacSupportsWorkers;
private final ImmutableList<JavaPackageConfigurationProvider> packageConfiguration;
private final TransitiveInfoCollection jacocoRunner;
private final FilesToRunProvider jacocoRunner;
private final JavaSemantics javaSemantics;

@VisibleForSerialization
Expand All @@ -169,7 +169,7 @@ public static JavaToolchainProvider create(
ImmutableList<String> javabuilderJvmOptions,
boolean javacSupportsWorkers,
ImmutableList<JavaPackageConfigurationProvider> packageConfiguration,
TransitiveInfoCollection jacocoRunner,
FilesToRunProvider jacocoRunner,
JavaSemantics javaSemantics) {
super(ImmutableMap.of(), Location.BUILTIN);

Expand Down Expand Up @@ -339,7 +339,7 @@ public ImmutableList<JavaPackageConfigurationProvider> packageConfiguration() {
return packageConfiguration;
}

public TransitiveInfoCollection getJacocoRunner() {
public FilesToRunProvider getJacocoRunner() {
return jacocoRunner;
}

Expand Down
1 change: 1 addition & 0 deletions src/test/shell/bazel/bazel_coverage_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \

JAVA_TOOLCHAIN="$1"; shift
add_to_bazelrc "build --java_toolchain=${JAVA_TOOLCHAIN}"
add_to_bazelrc "build --host_java_toolchain=${JAVA_TOOLCHAIN}"

JAVA_TOOLS_ZIP="$1"; shift
if [[ "${JAVA_TOOLS_ZIP}" != "released" ]]; then
Expand Down
7 changes: 6 additions & 1 deletion tools/jdk/BUILD.java_tools
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ java_toolchain(
":java_compiler_jar",
":jdk_compiler_jar",
],
jacocorunner = ":jacoco_coverage_runner"
jacocorunner = ":jacoco_coverage_runner_filegroup"
)

filegroup(
Expand All @@ -72,6 +72,11 @@ filegroup(
srcs = ["java_tools/GenClass_deploy.jar"],
)

filegroup(
name = "jacoco_coverage_runner_filegroup",
srcs = ["java_tools/JacocoCoverage_jarjar_deploy.jar"],
)

java_import(
name = "jacoco_coverage_runner",
jars = ["java_tools/JacocoCoverage_jarjar_deploy.jar"],
Expand Down

0 comments on commit e0833c6

Please sign in to comment.