use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testEmptyAction.
@Test
public void testEmptyAction() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
checkEmptyAction(ruleContext, "mnemonic = 'test'");
checkEmptyAction(ruleContext, "mnemonic = 'test', inputs = ruleContext.files.srcs");
checkErrorContains(ruleContext, "missing mandatory named-only argument 'mnemonic' while calling empty_action", "ruleContext.empty_action(inputs = ruleContext.files.srcs)");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionArgumentsWithExecutable.
@Test
public void testCreateSpawnActionArgumentsWithExecutable() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
evalRuleContextCode(ruleContext, "ruleContext.action(", " inputs = ruleContext.files.srcs,", " outputs = ruleContext.files.srcs,", " arguments = ['--a','--b'],", " executable = ruleContext.files.tools[0])");
SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertArtifactFilenames(action.getInputs(), "a.txt", "b.img", "t.exe");
assertArtifactFilenames(action.getOutputs(), "a.txt", "b.img");
MoreAsserts.assertContainsSublist(action.getArguments(), "foo/t.exe", "--a", "--b");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testExternalShortPath.
@Test
public void testExternalShortPath() throws Exception {
scratch.file("/bar/WORKSPACE");
scratch.file("/bar/bar.txt");
scratch.file("/bar/BUILD", "exports_files(['bar.txt'])");
FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"), "local_repository(name = 'foo', path = '/bar')");
scratch.file("test/BUILD", "genrule(", " name = 'lib',", " srcs = ['@foo//:bar.txt'],", " cmd = 'echo $(SRCS) $@',", " outs = ['lib.out'],", " executable = 1,", ")");
invalidatePackages();
SkylarkRuleContext ruleContext = createRuleContext("//test:lib");
String filename = evalRuleContextCode(ruleContext, "ruleContext.files.srcs[0].short_path").toString();
assertThat(filename).isEqualTo("../foo/bar.txt");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testLabelAttributeDefault.
@Test
public void testLabelAttributeDefault() throws Exception {
scratch.file("my_rule.bzl", "def _impl(ctx):", " return", "my_rule = rule(", " implementation = _impl,", " attrs = {", " 'explicit_dep': attr.label(default = Label('//:dep')),", " '_implicit_dep': attr.label(default = Label('//:dep')),", " 'explicit_dep_list': attr.label_list(default = [Label('//:dep')]),", " '_implicit_dep_list': attr.label_list(default = [Label('//:dep')]),", " }", ")");
scratch.file("BUILD", "filegroup(name='dep')", "load('/my_rule', 'my_rule')", "my_rule(name='r')");
invalidatePackages();
SkylarkRuleContext context = createRuleContext("//:r");
Label explicitDepLabel = (Label) evalRuleContextCode(context, "ruleContext.attr.explicit_dep.label");
assertThat(explicitDepLabel).isEqualTo(Label.parseAbsolute("//:dep"));
Label implicitDepLabel = (Label) evalRuleContextCode(context, "ruleContext.attr._implicit_dep.label");
assertThat(implicitDepLabel).isEqualTo(Label.parseAbsolute("//:dep"));
Label explicitDepListLabel = (Label) evalRuleContextCode(context, "ruleContext.attr.explicit_dep_list[0].label");
assertThat(explicitDepListLabel).isEqualTo(Label.parseAbsolute("//:dep"));
Label implicitDepListLabel = (Label) evalRuleContextCode(context, "ruleContext.attr._implicit_dep_list[0].label");
assertThat(implicitDepListLabel).isEqualTo(Label.parseAbsolute("//:dep"));
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testHostConfiguration.
@Test
public void testHostConfiguration() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.host_configuration");
assertSame(result, ruleContext.getRuleContext().getHostConfiguration());
}
Aggregations