use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class SkylarkJavaLiteProtoLibraryTest method testProtoLibraryBuildsCompiledJar.
@Test
public void testProtoLibraryBuildsCompiledJar() throws Exception {
ConfiguredTarget target = scratchConfiguredTarget("java", "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 = [':compiled'])", "proto_library(name = 'compiled',", " srcs = [ 'ok.proto' ])");
Artifact compiledJar = ActionsTestUtil.getFirstArtifactEndingWith(getFilesToBuild(target), "/libcompiled-lite.jar");
assertThat(compiledJar).isNotNull();
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class SkylarkJavaLiteProtoLibraryTest method testEmptySrcsForJavaApi.
@Test
public void testEmptySrcsForJavaApi() throws Exception {
ConfiguredTarget target = scratchConfiguredTarget("notbad", "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 = [':null_lib'])", "proto_library(name = 'null_lib')");
JavaCompilationArgsProvider compilationArgsProvider = getProvider(JavaCompilationArgsProvider.class, target);
assertThat(compilationArgsProvider).isNotNull();
assertThat(compilationArgsProvider.getJavaCompilationArgs()).isNotNull();
JavaSourceJarsProvider sourceJarsProvider = getProvider(JavaSourceJarsProvider.class, target);
assertThat(sourceJarsProvider).isNotNull();
assertThat(sourceJarsProvider.getSourceJars()).isNotNull();
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class SkylarkJavaLiteProtoLibraryTest method testJavaLiteProtoLibraryAspectProviders.
/** Tests that java_lite_proto_library's aspect exposes a Skylark provider named 'proto_java'. */
@Test
@Ignore
public // version of java_lite_proto_library.
void testJavaLiteProtoLibraryAspectProviders() throws Exception {
scratch.file("x/aspect.bzl", "def _foo_aspect_impl(target,ctx):", " proto_found = hasattr(target, 'proto_java')", " if hasattr(ctx.rule.attr, 'deps'):", " for dep in ctx.rule.attr.deps:", " proto_found = proto_found or dep.proto_found", " return struct(proto_found = proto_found)", "foo_aspect = aspect(_foo_aspect_impl, attr_aspects = ['deps'])", "def _foo_rule_impl(ctx):", " return struct(result = ctx.attr.dep.proto_found)", "foo_rule = rule(_foo_rule_impl, attrs = { 'dep' : attr.label(aspects = [foo_aspect])})");
scratch.file("x/BUILD", "load(':aspect.bzl', 'foo_rule')", "load('//tools/build_rules/java_lite_proto_library:java_lite_proto_library.bzl',", " 'java_lite_proto_library')", "java_lite_proto_library(name = 'foo_java_proto', deps = ['foo_proto'])", "proto_library(name = 'foo_proto', srcs = ['foo.proto'], java_lib = ':lib')", "foo_rule(name = 'foo_rule', dep = 'foo_java_proto')");
ConfiguredTarget target = getConfiguredTarget("//x:foo_rule");
Boolean result = (Boolean) target.get("result");
// "yes" means that "proto_java" was found on the proto_library + java_proto_library aspect.
assertThat(result).isTrue();
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget 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");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class SkylarkJavaLiteProtoLibraryTest method testBinaryDeps.
/** Tests that java_binaries which depend on proto_libraries depend on the right set of files. */
@Test
public void testBinaryDeps() throws Exception {
scratch.file("x/BUILD", "load('//" + RULE_DIRECTORY + ":java_lite_proto_library.bzl', ", " 'java_lite_proto_library')", "java_lite_proto_library(name = 'lite_pb2', deps = [':foo'])", "proto_library(name = 'foo', srcs = ['foo.proto', 'bar.proto'], deps = [':baz'])", "proto_library(name = 'baz', srcs = ['baz.proto'])");
ConfiguredTarget target = getConfiguredTarget("//x:lite_pb2");
NestedSet<Artifact> filesToBuild = getFilesToBuild(target);
Iterable<String> deps = prettyArtifactNames(actionsTestUtil.artifactClosureOf(filesToBuild));
// Should depend on compiler and Java proto1 API.
assertThat(deps).contains("net/proto2/compiler/public/protocol_compiler");
// Also should not depend on RPC APIs.
assertThat(deps).doesNotContain("apps/xplat/rpc/codegen/protoc-gen-rpc");
// Should depend on Java outputs.
assertThat(deps).contains("x/foo-lite-src.jar");
assertThat(deps).contains("x/baz-lite-src.jar");
// Should depend on Java libraries.
assertThat(deps).contains("x/libfoo-lite.jar");
assertThat(deps).contains("x/libbaz-lite.jar");
assertThat(deps).contains("protobuf/libjavalite_runtime-hjar.jar");
}
Aggregations