use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testAbstractActionInterface.
@Test
public void testAbstractActionInterface() throws Exception {
scratch.file("test/rules.bzl", "def _undertest_impl(ctx):", " out1 = ctx.outputs.out1", " out2 = ctx.outputs.out2", " ctx.file_action(output=out1, content='foo123')", " ctx.action(outputs=[out2], inputs=[out1], command='cp ' + out1.path + ' ' + out2.path)", " return struct(out1=out1, out2=out2)", "undertest_rule = rule(", " implementation = _undertest_impl,", " outputs = {'out1': '%{name}1.txt',", " 'out2': '%{name}2.txt'},", " _skylark_testable = True,", ")", testingRuleDefinition);
scratch.file("test/BUILD", simpleBuildDefinition);
SkylarkRuleContext ruleContext = createRuleContext("//test:testing");
update("ruleContext", ruleContext);
update("file1", eval("ruleContext.attr.dep.out1"));
update("file2", eval("ruleContext.attr.dep.out2"));
update("action1", eval("ruleContext.attr.dep[Actions].by_file[file1]"));
update("action2", eval("ruleContext.attr.dep[Actions].by_file[file2]"));
assertThat(eval("action1.inputs")).isInstanceOf(SkylarkNestedSet.class);
assertThat(eval("action1.outputs")).isInstanceOf(SkylarkNestedSet.class);
assertThat(eval("action1.argv")).isEqualTo(Runtime.NONE);
assertThat(eval("action2.content")).isEqualTo(Runtime.NONE);
assertThat(eval("action1.substitutions")).isEqualTo(Runtime.NONE);
assertThat(eval("list(action1.inputs)")).isEqualTo(eval("[]"));
assertThat(eval("list(action1.outputs)")).isEqualTo(eval("[file1]"));
assertThat(eval("list(action2.inputs)")).isEqualTo(eval("[file1]"));
assertThat(eval("list(action2.outputs)")).isEqualTo(eval("[file2]"));
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testDeriveArtifact.
@Test
public void testDeriveArtifact() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.new_file('a/b.txt')");
PathFragment fragment = ((Artifact) result).getRootRelativePath();
assertEquals("foo/a/b.txt", fragment.getPathString());
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testSkylarkRuleContextGetDefaultShellEnv.
@Test
public void testSkylarkRuleContextGetDefaultShellEnv() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.configuration.default_shell_env");
assertThat(result).isInstanceOf(SkylarkDict.class);
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testCheckPlaceholders.
@Test
public void testCheckPlaceholders() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.check_placeholders('%{name}', ['name'])");
assertEquals(true, result);
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testDefinedMakeVariable.
@Test
public void testDefinedMakeVariable() throws Exception {
SkylarkRuleContext ctx = createRuleContext("//foo:baz");
String java = (String) evalRuleContextCode(ctx, "ruleContext.var['JAVA']");
// Get the last path segment
java = java.substring(java.lastIndexOf('/'));
assertEquals("/java" + OsUtils.executableExtension(), java);
}
Aggregations