Search in sources :

Example 16 with ConfiguredTarget

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

the class SkylarkIntegrationTest method testRuleClassNonMandatoryEmptyOutputs.

@Test
public void testRuleClassNonMandatoryEmptyOutputs() throws Exception {
    scratch.file("test/skylark/extension.bzl", "def custom_rule_impl(ctx):", "  return struct(", "      o1=ctx.outputs.o1,", "      o2=ctx.outputs.o2)", "", "custom_rule = rule(implementation = custom_rule_impl,", "  attrs = {'o1': attr.output(), 'o2': attr.output_list()})");
    scratch.file("test/skylark/BUILD", "load('/test/skylark/extension', 'custom_rule')", "", "custom_rule(name = 'cr')");
    ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr");
    assertEquals(Runtime.NONE, target.get("o1"));
    assertEquals(MutableList.EMPTY, target.get("o2"));
}
Also used : 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 17 with ConfiguredTarget

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

the class SkylarkIntegrationTest method testAccessRunfiles.

@Test
public void testAccessRunfiles() throws Exception {
    scratch.file("test/skylark/extension.bzl", "def custom_rule_impl(ctx):", "  runfiles = ctx.attr.x.default_runfiles.files", "  return struct(files = runfiles)", "", "custom_rule = rule(implementation = custom_rule_impl,", "  attrs = {'x': attr.label(allow_files=True)})");
    scratch.file("test/skylark/BUILD", "load('/test/skylark/extension', 'custom_rule')", "", "cc_library(name = 'lib', data = ['a.txt'])", "custom_rule(name = 'cr1', x = ':lib')", "custom_rule(name = 'cr2', x = 'b.txt')");
    scratch.file("test/skylark/a.txt");
    scratch.file("test/skylark/b.txt");
    ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr1");
    List<String> baseArtifactNames = ActionsTestUtil.baseArtifactNames(target.getProvider(FileProvider.class).getFilesToBuild());
    assertThat(baseArtifactNames).containsExactly("a.txt");
    target = getConfiguredTarget("//test/skylark:cr2");
    baseArtifactNames = ActionsTestUtil.baseArtifactNames(target.getProvider(FileProvider.class).getFilesToBuild());
    assertThat(baseArtifactNames).isEmpty();
}
Also used : FileProvider(com.google.devtools.build.lib.analysis.FileProvider) 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 18 with ConfiguredTarget

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

the class SkylarkIntegrationTest method testHelperFunctionInRuleImplementation.

@Test
public void testHelperFunctionInRuleImplementation() throws Exception {
    scratch.file("test/skylark/extension.bzl", "def helper_func(attr1):", "  return depset(attr1)", "", "def custom_rule_impl(ctx):", "  attr1 = ctx.files.attr1", "  ftb = helper_func(attr1)", "  return struct(runfiles = ctx.runfiles(), files = ftb)", "", "custom_rule = rule(implementation = custom_rule_impl,", "  attrs = {'attr1': attr.label_list(mandatory=True, allow_files=True)})");
    scratch.file("test/skylark/BUILD", "load('/test/skylark/extension', 'custom_rule')", "", "custom_rule(name = 'cr', attr1 = [':a.txt'])");
    ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr");
    assertEquals("//test/skylark:cr", target.getLabel().toString());
    assertThat(ActionsTestUtil.baseArtifactNames(target.getProvider(FileProvider.class).getFilesToBuild())).containsExactly("a.txt");
}
Also used : 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 19 with ConfiguredTarget

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

the class SkylarkIntegrationTest method testInstrumentedFilesProviderWithCodeCoverageEnabled.

@Test
public void testInstrumentedFilesProviderWithCodeCoverageEnabled() throws Exception {
    scratch.file("test/skylark/extension.bzl", "def custom_rule_impl(ctx):", "  return struct(instrumented_files=struct(", "      extensions = ['txt'],", "      source_attributes = ['attr1'],", "      dependency_attributes = ['attr2']))", "", "custom_rule = rule(implementation = custom_rule_impl,", "  attrs = {", "      'attr1': attr.label_list(mandatory = True, allow_files=True),", "      'attr2': attr.label_list(mandatory = True)})");
    scratch.file("test/skylark/BUILD", "load('/test/skylark/extension', 'custom_rule')", "", "java_library(name='jl', srcs = [':A.java'])", "custom_rule(name = 'cr', attr1 = [':a.txt', ':a.random'], attr2 = [':jl'])");
    useConfiguration("--collect_code_coverage");
    ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr");
    assertEquals("//test/skylark:cr", target.getLabel().toString());
    InstrumentedFilesProvider provider = target.getProvider(InstrumentedFilesProvider.class);
    assertWithMessage("InstrumentedFilesProvider should be set.").that(provider).isNotNull();
    assertThat(ActionsTestUtil.baseArtifactNames(provider.getInstrumentedFiles())).containsExactly("a.txt", "A.java");
}
Also used : InstrumentedFilesProvider(com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider) 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 20 with ConfiguredTarget

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

the class FileWriteActionTest method testTransparentCompressionFlagOff.

@Test
public void testTransparentCompressionFlagOff() throws Exception {
    Artifact outputArtifact = getBinArtifactWithNoOwner("destination.txt");
    String contents = generateLongRandomString();
    useConfiguration("--experimental_transparent_compression=false");
    ConfiguredTarget target = scratchConfiguredTarget("a", "a", "filegroup(name='a', srcs=[])");
    RuleContext context = getRuleContext(target);
    FileWriteAction action = FileWriteAction.create(context, outputArtifact, contents, /*makeExecutable=*/
    false);
    assertThat(action.usesCompression()).isFalse();
}
Also used : RuleContext(com.google.devtools.build.lib.analysis.RuleContext) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) LazyString(com.google.devtools.build.lib.util.LazyString) 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