Search in sources :

Example 96 with ConfiguredTarget

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

Example 97 with ConfiguredTarget

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

Example 98 with ConfiguredTarget

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

Example 99 with ConfiguredTarget

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

Example 100 with ConfiguredTarget

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