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