Search in sources :

Example 1 with JavaCompileAction

use of com.google.devtools.build.lib.rules.java.JavaCompileAction in project bazel by bazelbuild.

the class SkylarkJavaLiteProtoLibraryTest method testJavacOpts.

/** Protobufs should always be compiled with the default and proto javacopts. */
@Test
public void testJavacOpts() throws Exception {
    ConfiguredTarget rule = scratchConfiguredTarget("x", "lite_pb2", "load('//tools/build_rules/java_lite_proto_library:java_lite_proto_library.bzl',", "      'java_lite_proto_library')", "java_lite_proto_library(name = 'lite_pb2', deps = [':proto_lib'])", "proto_library(name = 'proto_lib',", "              srcs = ['input1.proto', 'input2.proto'])");
    JavaCompilationArgs compilationArgs = getProvider(JavaCompilationArgsProvider.class, rule).getJavaCompilationArgs();
    assertThat(compilationArgs.getInstrumentationMetadata()).isEmpty();
    JavaSourceJarsProvider sourceJarsProvider = getProvider(JavaSourceJarsProvider.class, rule);
    assertThat(sourceJarsProvider).isNotNull();
    assertThat(prettyJarNames(sourceJarsProvider.getSourceJars())).containsExactly("x/proto_lib-lite-src.jar");
    ImmutableListMultimap<String, Artifact> runtimeJars = Multimaps.index(compilationArgs.getRuntimeJars(), ROOT_RELATIVE_PATH_STRING);
    Artifact jar = Iterables.getOnlyElement(runtimeJars.get("x/libproto_lib-lite.jar"));
    JavaCompileAction action = (JavaCompileAction) getGeneratingAction(jar);
    List<String> commandLine = ImmutableList.copyOf(action.buildCommandLine());
    assertThat(commandLine).contains("-protoMarkerForTest");
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) JavaCompilationArgs(com.google.devtools.build.lib.rules.java.JavaCompilationArgs) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) JavaCompileAction(com.google.devtools.build.lib.rules.java.JavaCompileAction) Test(org.junit.Test)

Example 2 with JavaCompileAction

use of com.google.devtools.build.lib.rules.java.JavaCompileAction in project bazel by bazelbuild.

the class SkylarkJavaLiteProtoLibraryTest method testCommandLineContainsTargetLabelAndRuleKind.

@Test
public void testCommandLineContainsTargetLabelAndRuleKind() throws Exception {
    scratch.file("java/lib/BUILD", "load('//tools/build_rules/java_lite_proto_library:java_lite_proto_library.bzl',", "      'java_lite_proto_library')", "java_lite_proto_library(name = 'lite_pb2', deps = [':proto'])", "proto_library(name = 'proto', srcs = ['dummy.proto'])");
    JavaCompileAction javacAction = (JavaCompileAction) getGeneratingAction(getConfiguredTarget("//java/lib:lite_pb2"), "java/lib/libproto-lite.jar");
    List<String> commandLine = ImmutableList.copyOf(javacAction.buildCommandLine());
    MoreAsserts.assertContainsSublist(commandLine, "--rule_kind", "proto_library");
    MoreAsserts.assertContainsSublist(commandLine, "--target_label", "//java/lib:proto");
}
Also used : JavaCompileAction(com.google.devtools.build.lib.rules.java.JavaCompileAction) Test(org.junit.Test)

Aggregations

JavaCompileAction (com.google.devtools.build.lib.rules.java.JavaCompileAction)2 Test (org.junit.Test)2 Artifact (com.google.devtools.build.lib.actions.Artifact)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 JavaCompilationArgs (com.google.devtools.build.lib.rules.java.JavaCompilationArgs)1 JavaCompilationArgsProvider (com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider)1 JavaSourceJarsProvider (com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider)1