Search in sources :

Example 71 with ConfiguredTarget

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();
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 72 with ConfiguredTarget

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();
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) JavaSourceJarsProvider(com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 73 with ConfiguredTarget

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();
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 74 with ConfiguredTarget

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");
}
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 75 with ConfiguredTarget

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");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Aggregations

ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)222 Test (org.junit.Test)178 Artifact (com.google.devtools.build.lib.actions.Artifact)51 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)41 RuleConfiguredTarget (com.google.devtools.build.lib.analysis.RuleConfiguredTarget)25 Label (com.google.devtools.build.lib.cmdline.Label)17 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)15 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)13 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)12 Nullable (javax.annotation.Nullable)10 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)9 Variables (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables)9 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)7 Map (java.util.Map)7 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)6 TestAspects (com.google.devtools.build.lib.analysis.util.TestAspects)6 Attribute (com.google.devtools.build.lib.packages.Attribute)6 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)5 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)5 TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)5