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"));
}
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();
}
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");
}
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");
}
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();
}
Aggregations