Search in sources :

Example 6 with ConfiguredTarget

use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.

the class SkylarkIntegrationTest method rulesReturningDeclaredProviders.

@Test
public void rulesReturningDeclaredProviders() throws Exception {
    scratch.file("test/extension.bzl", "my_provider = provider()", "def _impl(ctx):", "   return [my_provider(x = 1)]", "my_rule = rule(_impl)");
    scratch.file("test/BUILD", "load(':extension.bzl', 'my_rule')", "my_rule(name = 'r')");
    ConfiguredTarget configuredTarget = getConfiguredTarget("//test:r");
    ClassObjectConstructor.Key key = new SkylarkClassObjectConstructor.SkylarkKey(Label.create(configuredTarget.getLabel().getPackageIdentifier(), "extension.bzl"), "my_provider");
    SkylarkProviders skylarkProviders = configuredTarget.getProvider(SkylarkProviders.class);
    assertThat(skylarkProviders).isNotNull();
    SkylarkClassObject declaredProvider = skylarkProviders.getDeclaredProvider(key);
    assertThat(declaredProvider).isNotNull();
    assertThat(declaredProvider.getConstructor().getKey()).isEqualTo(key);
    assertThat(declaredProvider.getValue("x")).isEqualTo(1);
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) ClassObjectConstructor(com.google.devtools.build.lib.packages.ClassObjectConstructor) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) RuleConfiguredTarget(com.google.devtools.build.lib.analysis.RuleConfiguredTarget) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Test(org.junit.Test)

Example 7 with ConfiguredTarget

use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.

the class SkyframeExecutorTestUtils method getAllExistingConfiguredTargets.

/**
   * Returns all configured targets currently in the graph.
   */
public static Iterable<ConfiguredTarget> getAllExistingConfiguredTargets(SkyframeExecutor skyframeExecutor) {
    Collection<SkyValue> values = Maps.filterKeys(skyframeExecutor.getEvaluatorForTesting().getValues(), SkyFunctions.isSkyFunction(SkyFunctions.CONFIGURED_TARGET)).values();
    List<ConfiguredTarget> cts = Lists.newArrayList();
    for (SkyValue value : values) {
        if (value != null) {
            cts.add(((ConfiguredTargetValue) value).getConfiguredTarget());
        }
    }
    return cts;
}
Also used : SkyValue(com.google.devtools.build.skyframe.SkyValue) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget)

Example 8 with ConfiguredTarget

use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.

the class SkylarkAspectsTest method labelKeyedStringDictAllowsAspects.

@Test
public void labelKeyedStringDictAllowsAspects() throws Exception {
    scratch.file("test/aspect.bzl", "def _aspect_impl(target, ctx):", "   return struct(aspect_data=target.label.name)", "", "def _rule_impl(ctx):", "   return struct(", "       data=','.join(['{}:{}'.format(dep.aspect_data, val)", "                      for dep, val in ctx.attr.attr.items()]))", "", "MyAspect = aspect(", "   implementation=_aspect_impl,", ")", "my_rule = rule(", "   implementation=_rule_impl,", "   attrs = { 'attr' : ", "             attr.label_keyed_string_dict(aspects = [MyAspect]) },", ")");
    scratch.file("test/BUILD", "load('/test/aspect', 'my_rule')", "java_library(", "     name = 'yyy',", ")", "my_rule(", "     name = 'xxx',", "     attr = {':yyy': 'zzz'},", ")");
    AnalysisResult analysisResult = update("//test:xxx");
    ConfiguredTarget target = analysisResult.getTargetsToBuild().iterator().next();
    SkylarkProviders skylarkProviders = target.getProvider(SkylarkProviders.class);
    Object value = skylarkProviders.getValue("data");
    assertThat(value).isEqualTo("yyy:zzz");
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 9 with ConfiguredTarget

use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectOutputsToBinDirectory.

@Test
public void aspectOutputsToBinDirectory() throws Exception {
    scratch.file("foo/extension.bzl", "def _aspect_impl(target, ctx):", "   file = ctx.new_file('aspect-output-' + target.label.name)", "   ctx.file_action(file, 'data')", "   return struct(aspect_file = file)", "my_aspect = aspect(_aspect_impl)", "def _rule_impl(ctx):", "   pass", "rule_bin_out = rule(_rule_impl, output_to_genfiles=False)", "rule_gen_out = rule(_rule_impl, output_to_genfiles=True)", "def _main_rule_impl(ctx):", "   s = depset()", "   for d in ctx.attr.deps:", "       s = s | depset([d.aspect_file])", "   return struct(aspect_files = s)", "main_rule = rule(_main_rule_impl,", "   attrs = { 'deps' : attr.label_list(aspects = [my_aspect]) },", ")");
    scratch.file("foo/BUILD", "load('extension', 'rule_bin_out', 'rule_gen_out', 'main_rule')", "rule_bin_out(name = 'rbin')", "rule_gen_out(name = 'rgen')", "main_rule(name = 'main', deps = [':rbin', ':rgen'])");
    AnalysisResult analysisResult = update(ImmutableList.<String>of(), "//foo:main");
    ConfiguredTarget target = analysisResult.getTargetsToBuild().iterator().next();
    NestedSet<Artifact> aspectFiles = ((SkylarkNestedSet) target.getProvider(SkylarkProviders.class).getValue("aspect_files")).getSet(Artifact.class);
    assertThat(transform(aspectFiles, new Function<Artifact, String>() {

        @Override
        public String apply(Artifact artifact) {
            return artifact.getFilename();
        }
    })).containsExactly("aspect-output-rbin", "aspect-output-rgen");
    for (Artifact aspectFile : aspectFiles) {
        String rootPath = aspectFile.getRoot().getExecPath().toString();
        assertWithMessage("Artifact %s should not be in genfiles", aspectFile).that(rootPath).doesNotContain("genfiles");
        assertWithMessage("Artifact %s should be in bin", aspectFile).that(rootPath).endsWith("bin");
    }
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) SkylarkNestedSet(com.google.devtools.build.lib.syntax.SkylarkNestedSet) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 10 with ConfiguredTarget

use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectOnLabelAttr.

@Test
public void aspectOnLabelAttr() throws Exception {
    scratch.file("test/aspect.bzl", "def _aspect_impl(target, ctx):", "   return struct(aspect_data='foo')", "", "def _rule_impl(ctx):", "   return struct(data=ctx.attr.attr.aspect_data)", "", "MyAspect = aspect(", "   implementation=_aspect_impl,", ")", "my_rule = rule(", "   implementation=_rule_impl,", "   attrs = { 'attr' : ", "             attr.label(aspects = [MyAspect]) },", ")");
    scratch.file("test/BUILD", "load('/test/aspect', 'my_rule')", "java_library(", "     name = 'yyy',", ")", "my_rule(", "     name = 'xxx',", "     attr = ':yyy',", ")");
    AnalysisResult analysisResult = update("//test:xxx");
    ConfiguredTarget target = analysisResult.getTargetsToBuild().iterator().next();
    SkylarkProviders skylarkProviders = target.getProvider(SkylarkProviders.class);
    Object value = skylarkProviders.getValue("data");
    assertThat(value).isEqualTo("foo");
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) 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