Search in sources :

Example 36 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testCreateFileAction.

@Test
public void testCreateFileAction() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    evalRuleContextCode(ruleContext, "ruleContext.file_action(", "  output = ruleContext.files.srcs[0],", "  content = 'hello world',", "  executable = False)");
    FileWriteAction action = (FileWriteAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
    assertEquals("foo/a.txt", Iterables.getOnlyElement(action.getOutputs()).getExecPathString());
    assertEquals("hello world", action.getFileContents());
    assertFalse(action.makeExecutable());
}
Also used : SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) FileWriteAction(com.google.devtools.build.lib.analysis.actions.FileWriteAction) Test(org.junit.Test)

Example 37 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testBadParamTypeErrorMessage.

@Test
public void testBadParamTypeErrorMessage() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    checkErrorContains(ruleContext, "method ctx.file_action(output: File, content: string, executable: bool) is not applicable " + "for arguments (File, int, bool): 'content' is 'int', but should be 'string'", "ruleContext.file_action(", "  output = ruleContext.files.srcs[0],", "  content = 1,", "  executable = False)");
}
Also used : SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 38 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testStructPlusArtifactErrorMessage.

@Test
public void testStructPlusArtifactErrorMessage() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    checkErrorContains(ruleContext, "unsupported operand type(s) for +: 'File' and 'struct'", "ruleContext.files.tools[0] + struct(a = 1)");
}
Also used : SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 39 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testRunfilesArtifactsFromNestedSetArtifacts.

@Test
public void testRunfilesArtifactsFromNestedSetArtifacts() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    Object result = evalRuleContextCode(ruleContext, "ftb = depset() + ruleContext.files.srcs", "ruleContext.runfiles(transitive_files = ftb)");
    assertEquals(ActionsTestUtil.baseArtifactNames(getRunfileArtifacts(result)), ImmutableList.of("a.txt", "b.img"));
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 40 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testRunfilesArtifactsFromIterableArtifacts.

@Test
public void testRunfilesArtifactsFromIterableArtifacts() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    Object result = evalRuleContextCode(ruleContext, "artifacts = ruleContext.files.srcs", "ruleContext.runfiles(files = artifacts)");
    assertEquals(ActionsTestUtil.baseArtifactNames(getRunfileArtifacts(result)), ImmutableList.of("a.txt", "b.img"));
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Aggregations

SkylarkRuleContext (com.google.devtools.build.lib.rules.SkylarkRuleContext)81 Test (org.junit.Test)79 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)47 Label (com.google.devtools.build.lib.cmdline.Label)6 Artifact (com.google.devtools.build.lib.actions.Artifact)5 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)5 SkylarkList (com.google.devtools.build.lib.syntax.SkylarkList)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)2 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)2 TemplateExpansionAction (com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction)2 SkylarkDict (com.google.devtools.build.lib.syntax.SkylarkDict)2 ImmutableList (com.google.common.collect.ImmutableList)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 RuleContext (com.google.devtools.build.lib.analysis.RuleContext)1 FileWriteAction (com.google.devtools.build.lib.analysis.actions.FileWriteAction)1 Substitution (com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction.Substitution)1 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)1 JavaSourceJarsProvider (com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider)1 SkylarkCallable (com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)1