Search in sources :

Example 1 with FileWriteAction

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

the class BazelProtoLibraryTest method descriptorSets_ruleWithoutSrcsWritesEmptyFile.

/** Asserts that we register a FileWriteAction with empty contents if there are no srcs. */
@Test
public void descriptorSets_ruleWithoutSrcsWritesEmptyFile() throws Exception {
    scratch.file("x/BUILD", "proto_library(name='no_srcs')");
    Action action = getDescriptorWriteAction("//x:no_srcs");
    assertThat(action).isInstanceOf(FileWriteAction.class);
    assertThat(((FileWriteAction) action).getFileContents()).isEmpty();
}
Also used : FileWriteAction(com.google.devtools.build.lib.analysis.actions.FileWriteAction) Action(com.google.devtools.build.lib.actions.Action) FileWriteAction(com.google.devtools.build.lib.analysis.actions.FileWriteAction) Test(org.junit.Test)

Example 2 with FileWriteAction

use of com.google.devtools.build.lib.analysis.actions.FileWriteAction 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)

Aggregations

FileWriteAction (com.google.devtools.build.lib.analysis.actions.FileWriteAction)2 Test (org.junit.Test)2 Action (com.google.devtools.build.lib.actions.Action)1 SkylarkRuleContext (com.google.devtools.build.lib.rules.SkylarkRuleContext)1