Skip to content

Commit 2fe639e

Browse files
gregestrencopybara-github
authored andcommitted
Starlarkify coverage, annotation processing tests.
PiperOrigin-RevId: 878534391 Change-Id: I931d4a360e32fe15a9e937495f693d91ce1a8993
1 parent bbfb117 commit 2fe639e

File tree

1 file changed

+0
-126
lines changed

1 file changed

+0
-126
lines changed

src/test/java/com/google/devtools/build/lib/rules/java/JavaStarlarkApiTest.java

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import static com.google.common.truth.Truth.assertThat;
1717
import static com.google.common.truth.Truth.assertWithMessage;
1818
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.prettyArtifactNames;
19-
import static com.google.devtools.build.lib.rules.java.JavaCompileActionTestHelper.getProcessorNames;
20-
import static com.google.devtools.build.lib.rules.java.JavaCompileActionTestHelper.getProcessorPath;
2119
import static com.google.devtools.build.lib.rules.java.JavaInfo.PROVIDER;
2220
import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuild;
2321
import static java.util.Arrays.stream;
@@ -27,7 +25,6 @@
2725
import com.google.devtools.build.lib.actions.Artifact;
2826
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
2927
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
30-
import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo;
3128
import com.google.devtools.build.lib.analysis.util.AnalysisMock;
3229
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
3330
import com.google.devtools.build.lib.cmdline.Label;
@@ -745,125 +742,6 @@ def _impl(ctx):
745742
assertThat(prettyArtifactNames(files.toList(Artifact.class))).containsExactly("a/a.txt");
746743
}
747744

748-
@Test
749-
public void testJavaLibraryCollectsCoverageDependenciesFromResources() throws Exception {
750-
useConfiguration("--collect_code_coverage");
751-
752-
scratch.file(
753-
"java/BUILD",
754-
"""
755-
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
756-
load("@rules_java//java:defs.bzl", "java_library")
757-
java_library(
758-
name = "lib",
759-
resources = [":libjni.so"],
760-
)
761-
762-
cc_binary(
763-
name = "libjni.so",
764-
srcs = ["jni.cc"],
765-
linkshared = 1,
766-
)
767-
""");
768-
769-
InstrumentedFilesInfo target = getInstrumentedFilesProvider("//java:lib");
770-
771-
assertThat(prettyArtifactNames(target.getInstrumentedFiles())).containsExactly("java/jni.cc");
772-
assertThat(prettyArtifactNames(target.getInstrumentationMetadataFiles()))
773-
.containsExactly("java/_objs/libjni.so/jni.gcno");
774-
}
775-
776-
@Test
777-
public void testSkipAnnotationProcessing() throws Exception {
778-
JavaTestUtil.writeBuildFileForJavaToolchain(scratch);
779-
scratch.file(
780-
"foo/custom_rule.bzl",
781-
"load('@rules_java//java:defs.bzl', 'java_common', 'JavaInfo',"
782-
+ " 'JavaPluginInfo')",
783-
"def _impl(ctx):",
784-
" output_jar = ctx.actions.declare_file('lib' + ctx.label.name + '.jar')",
785-
" compilation_provider = java_common.compile(",
786-
" ctx,",
787-
" source_files = ctx.files.srcs,",
788-
" output = output_jar,",
789-
" java_toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo],",
790-
" deps = [p[JavaInfo] for p in ctx.attr.deps],",
791-
" plugins = [p[JavaPluginInfo] for p in ctx.attr.plugins],",
792-
" enable_annotation_processing = False,",
793-
" )",
794-
" return [DefaultInfo(files = depset([output_jar])), compilation_provider]",
795-
"java_custom_library = rule(",
796-
" implementation = _impl,",
797-
" outputs = {",
798-
" 'my_output': 'lib%{name}.jar'",
799-
" },",
800-
" attrs = {",
801-
" 'srcs': attr.label_list(allow_files=True),",
802-
" 'deps': attr.label_list(providers=[JavaInfo]),",
803-
" 'plugins': attr.label_list(providers=[JavaPluginInfo]),",
804-
" '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
805-
" },",
806-
" toolchains = ['" + TestConstants.JAVA_TOOLCHAIN_TYPE + "'],",
807-
" fragments = ['java']",
808-
")");
809-
scratch.file(
810-
"foo/BUILD",
811-
"""
812-
load(":custom_rule.bzl", "java_custom_library")
813-
load("@rules_java//java:defs.bzl", "java_library", "java_plugin")
814-
815-
java_plugin(
816-
name = "processor",
817-
srcs = ["processor.java"],
818-
data = ["processor_data.txt"],
819-
generates_api = 1, # so Turbine would normally run it
820-
processor_class = "Foo",
821-
)
822-
823-
java_library(
824-
name = "exports_processor",
825-
exported_plugins = [":processor"],
826-
)
827-
828-
java_custom_library(
829-
name = "custom",
830-
srcs = ["custom.java"],
831-
plugins = [":processor"],
832-
deps = [":exports_processor"],
833-
)
834-
835-
java_custom_library(
836-
name = "custom_noproc",
837-
srcs = ["custom.java"],
838-
)
839-
""");
840-
841-
ConfiguredTarget custom = getConfiguredTarget("//foo:custom");
842-
ConfiguredTarget customNoproc = getConfiguredTarget("//foo:custom_noproc");
843-
assertNoEvents();
844-
845-
JavaCompileAction javacAction =
846-
(JavaCompileAction) getGeneratingActionForLabel("//foo:libcustom.jar");
847-
assertThat(javacAction.getMnemonic()).isEqualTo("Javac");
848-
assertThat(getProcessorNames(javacAction)).isEmpty();
849-
assertThat(getProcessorPath(javacAction)).isNotEmpty();
850-
assertThat(artifactFilesNames(javacAction.getInputs())).contains("processor_data.txt");
851-
852-
JavaCompileAction turbineAction =
853-
(JavaCompileAction) getGeneratingAction(getBinArtifact("libcustom-hjar.jar", custom));
854-
assertThat(turbineAction.getMnemonic()).isEqualTo("JavacTurbine");
855-
ImmutableList<String> args = turbineAction.getArguments();
856-
assertThat(args).doesNotContain("--processors");
857-
858-
// enable_annotation_processing=False shouldn't disable direct classpaths if there are no
859-
// annotation processors that need to be disabled
860-
SpawnAction turbineActionNoProc =
861-
(SpawnAction)
862-
getGeneratingAction(getBinArtifact("libcustom_noproc-hjar.jar", customNoproc));
863-
assertThat(turbineActionNoProc.getMnemonic()).isEqualTo("Turbine");
864-
assertThat(turbineActionNoProc.getArguments()).doesNotContain("--processors");
865-
}
866-
867745
@Test
868746
public void testCompileWithDisablingCompileJarIsPrivateApi() throws Exception {
869747
JavaTestUtil.writeBuildFileForJavaToolchain(scratch);
@@ -1297,10 +1175,6 @@ def _impl(ctx):
12971175
assertThat(provider.toFlags()).containsExactly("--add-exports=java.base/java.lang=ALL-UNNAMED");
12981176
}
12991177

1300-
private InstrumentedFilesInfo getInstrumentedFilesProvider(String label) throws Exception {
1301-
return getConfiguredTarget(label).get(InstrumentedFilesInfo.STARLARK_CONSTRUCTOR);
1302-
}
1303-
13041178
@Test
13051179
public void hermeticStaticLibs() throws Exception {
13061180
scratch.file("a/libStatic.a");

0 commit comments

Comments
 (0)