use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class FilegroupConfiguredTargetTest method testGlobMatchesRuleOutputsInsteadOfFileWithTheSameName.
@Test
public void testGlobMatchesRuleOutputsInsteadOfFileWithTheSameName() throws Exception {
scratch.file("pkg/file_or_rule");
scratch.file("pkg/a.txt");
ConfiguredTarget target = scratchConfiguredTarget("pkg", "my_rule", "filegroup(name = 'file_or_rule', srcs = ['a.txt'])", "filegroup(name = 'my_rule', srcs = glob(['file_or_rule']))");
assertThat(ActionsTestUtil.baseArtifactNames(getFilesToBuild(target))).containsExactly("a.txt");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class JavaSkylarkApiTest method constructJavaProvider.
@Test
public void constructJavaProvider() throws Exception {
scratch.file("foo/extension.bzl", "def _impl(ctx):", " my_provider = java_common.create_provider(", " compile_time_jars = ctx.files.compile_time_jars,", " runtime_jars = ctx.files.runtime_jars)", " return [my_provider]", "my_rule = rule(_impl, ", " attrs = { ", " 'compile_time_jars' : attr.label_list(allow_files=['.jar']),", " 'runtime_jars': attr.label_list(allow_files=['.jar'])", "})");
scratch.file("foo/liba.jar");
scratch.file("foo/libb.jar");
scratch.file("foo/BUILD", "load(':extension.bzl', 'my_rule')", "my_rule(name = 'myrule',", " compile_time_jars = ['liba.jar'],", " runtime_jars = ['libb.jar']", ")");
ConfiguredTarget target = getConfiguredTarget("//foo:myrule");
JavaCompilationArgsProvider provider = JavaProvider.getProvider(JavaCompilationArgsProvider.class, target);
assertThat(provider).isNotNull();
List<String> compileTimeJars = prettyJarNames(provider.getJavaCompilationArgs().getCompileTimeJars());
assertThat(compileTimeJars).containsExactly("foo/liba.jar");
List<String> runtimeJars = prettyJarNames(provider.getRecursiveJavaCompilationArgs().getRuntimeJars());
assertThat(runtimeJars).containsExactly("foo/libb.jar");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class JavaSkylarkApiTest method constructJavaProviderWithAnotherJavaProvider.
@Test
public void constructJavaProviderWithAnotherJavaProvider() throws Exception {
scratch.file("foo/extension.bzl", "def _impl(ctx):", " transitive_provider = java_common.merge(", " [dep[java_common.provider] for dep in ctx.attr.deps])", " my_provider = java_common.create_provider(", " compile_time_jars = ctx.files.compile_time_jars,", " runtime_jars = ctx.files.runtime_jars)", " return [java_common.merge([my_provider, transitive_provider])]", "my_rule = rule(_impl, ", " attrs = { ", " 'compile_time_jars' : attr.label_list(allow_files=['.jar']),", " 'runtime_jars': attr.label_list(allow_files=['.jar']),", " 'deps': attr.label_list()", "})");
scratch.file("foo/liba.jar");
scratch.file("foo/libb.jar");
scratch.file("foo/BUILD", "load(':extension.bzl', 'my_rule')", "java_library(name = 'java_dep',", " srcs = ['A.java'])", "my_rule(name = 'myrule',", " compile_time_jars = ['liba.jar'],", " runtime_jars = ['libb.jar'],", " deps = [':java_dep']", ")");
ConfiguredTarget target = getConfiguredTarget("//foo:myrule");
JavaCompilationArgsProvider provider = JavaProvider.getProvider(JavaCompilationArgsProvider.class, target);
assertThat(provider).isNotNull();
List<String> compileTimeJars = prettyJarNames(provider.getJavaCompilationArgs().getCompileTimeJars());
assertThat(compileTimeJars).containsExactly("foo/liba.jar", "foo/libjava_dep-hjar.jar");
List<String> runtimeJars = prettyJarNames(provider.getRecursiveJavaCompilationArgs().getRuntimeJars());
assertThat(runtimeJars).containsExactly("foo/libb.jar", "foo/libjava_dep.jar");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class JavaSkylarkApiTest method strictDepsDisabled.
@Test
public void strictDepsDisabled() throws Exception {
scratch.file("foo/custom_library.bzl", "def _impl(ctx):", " java_provider = java_common.merge([dep[java_common.provider] for dep in ctx.attr.deps])", " if not ctx.attr.strict_deps:", " java_provider = java_common.make_non_strict(java_provider)", " return [java_provider]", "custom_library = rule(", " attrs = {", " 'deps': attr.label_list(),", " 'strict_deps': attr.bool()", " },", " implementation = _impl", ")");
scratch.file("foo/BUILD", "load(':custom_library.bzl', 'custom_library')", "custom_library(name = 'custom', deps = [':a'], strict_deps = False)", "java_library(name = 'a', srcs = ['java/A.java'], deps = [':b'])", "java_library(name = 'b', srcs = ['java/B.java'])");
ConfiguredTarget myRuleTarget = getConfiguredTarget("//foo:custom");
JavaCompilationArgsProvider javaCompilationArgsProvider = JavaProvider.getProvider(JavaCompilationArgsProvider.class, myRuleTarget);
List<String> directJars = prettyJarNames(javaCompilationArgsProvider.getJavaCompilationArgs().getRuntimeJars());
assertThat(directJars).containsExactly("foo/liba.jar", "foo/libb.jar");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class JavaSkylarkApiTest method constructJavaProviderJavaLibrary.
@Test
public void constructJavaProviderJavaLibrary() throws Exception {
scratch.file("foo/extension.bzl", "def _impl(ctx):", " my_provider = java_common.create_provider(", " compile_time_jars = ctx.files.compile_time_jars,", " runtime_jars = ctx.files.runtime_jars)", " return [my_provider]", "my_rule = rule(_impl, ", " attrs = { ", " 'compile_time_jars' : attr.label_list(allow_files=['.jar']),", " 'runtime_jars': attr.label_list(allow_files=['.jar'])", "})");
scratch.file("foo/liba.jar");
scratch.file("foo/libb.jar");
scratch.file("foo/BUILD", "load(':extension.bzl', 'my_rule')", "my_rule(name = 'myrule',", " compile_time_jars = ['liba.jar'],", " runtime_jars = ['libb.jar']", ")", "java_library(name = 'java_lib',", " srcs = ['C.java'],", " deps = [':myrule']", ")");
ConfiguredTarget target = getConfiguredTarget("//foo:java_lib");
JavaCompilationArgsProvider provider = JavaProvider.getProvider(JavaCompilationArgsProvider.class, target);
List<String> compileTimeJars = prettyJarNames(provider.getRecursiveJavaCompilationArgs().getCompileTimeJars());
assertThat(compileTimeJars).containsExactly("foo/libjava_lib-hjar.jar", "foo/liba.jar");
List<String> runtimeJars = prettyJarNames(provider.getRecursiveJavaCompilationArgs().getRuntimeJars());
assertThat(runtimeJars).containsExactly("foo/libjava_lib.jar", "foo/libb.jar");
}
Aggregations