use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionCreatesSpawnAction.
@Test
public void testCreateSpawnActionCreatesSpawnAction() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
createTestSpawnAction(ruleContext);
ActionAnalysisMetadata action = Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertThat(action).isInstanceOf(SpawnAction.class);
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionShellCommandList.
@Test
public void testCreateSpawnActionShellCommandList() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
evalRuleContextCode(ruleContext, "ruleContext.action(", " inputs = ruleContext.files.srcs,", " outputs = ruleContext.files.srcs,", " mnemonic = 'DummyMnemonic',", " command = ['dummy_command', '--arg1', '--arg2'],", " progress_message = 'dummy_message')");
SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertThat(action.getArguments()).containsExactly("dummy_command", "--arg1", "--arg2").inOrder();
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateTemplateActionWithWrongEncoding.
/**
* Simulates the fact that the Parser currently uses Latin1 to read BUILD files, while users
* usually write those files using UTF-8 encoding. Currently, the string-valued 'substitutions'
* parameter of the template_action function contains a hack that assumes its input is a UTF-8
* encoded string which has been ingested as Latin 1. The hack converts the string to its
* "correct" UTF-8 value. Once {@link com.google.devtools.build.lib.syntax.ParserInputSource#create(com.google.devtools.build.lib.vfs.Path)}
* parses files using UTF-8 and the hack for the substituations parameter is removed, this test
* will fail.
*/
@Test
public void testCreateTemplateActionWithWrongEncoding() throws Exception {
// The following array contains bytes that represent a string of length two when treated as
// UTF-8 and a string of length four when treated as ISO-8859-1 (a.k.a. Latin 1).
byte[] bytesToDecode = { (byte) 0xC2, (byte) 0xA2, (byte) 0xC2, (byte) 0xA2 };
Charset latin1 = StandardCharsets.ISO_8859_1;
Charset utf8 = StandardCharsets.UTF_8;
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
TemplateExpansionAction action = (TemplateExpansionAction) evalRuleContextCode(ruleContext, "ruleContext.template_action(", " template = ruleContext.files.srcs[0],", " output = ruleContext.files.srcs[1],", " substitutions = {'a': '" + new String(bytesToDecode, latin1) + "'},", " executable = False)");
List<Substitution> substitutions = action.getSubstitutions();
assertThat(substitutions).hasSize(1);
assertThat(substitutions.get(0).getValue()).isEqualTo(new String(bytesToDecode, utf8));
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionNoExecutable.
@Test
public void testCreateSpawnActionNoExecutable() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
checkErrorContains(ruleContext, "You must specify either 'command' or 'executable' argument", "ruleContext.action(outputs=[])");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateTemplateAction.
@Test
public void testCreateTemplateAction() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
TemplateExpansionAction action = (TemplateExpansionAction) evalRuleContextCode(ruleContext, "ruleContext.template_action(", " template = ruleContext.files.srcs[0],", " output = ruleContext.files.srcs[1],", " substitutions = {'a': 'b'},", " executable = False)");
assertEquals("foo/a.txt", Iterables.getOnlyElement(action.getInputs()).getExecPathString());
assertEquals("foo/b.img", Iterables.getOnlyElement(action.getOutputs()).getExecPathString());
assertEquals("a", Iterables.getOnlyElement(action.getSubstitutions()).getKey());
assertEquals("b", Iterables.getOnlyElement(action.getSubstitutions()).getValue());
assertFalse(action.makeExecutable());
}
Aggregations