use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCmdJoinPaths.
@Test
public void testCmdJoinPaths() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "f = depset(ruleContext.files.srcs)", "cmd_helper.join_paths(':', f)");
assertEquals("foo/a.txt:foo/b.img", result);
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testBinDirPath.
@Test
public void testBinDirPath() throws Exception {
SkylarkRuleContext ctx = createRuleContext("//foo:bar");
Object result = evalRuleContextCode(ctx, "ruleContext.bin_dir.path");
assertEquals(ctx.getConfiguration().getBinFragment().getPathString(), result);
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionEnvAndExecInfo.
@Test
public void testCreateSpawnActionEnvAndExecInfo() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
evalRuleContextCode(ruleContext, "env = {'a' : 'b'}", "ruleContext.action(", " inputs = ruleContext.files.srcs,", " outputs = ruleContext.files.srcs,", " env = env,", " execution_requirements = env,", " mnemonic = 'DummyMnemonic',", " command = 'dummy_command',", " progress_message = 'dummy_message')");
SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertEquals(ImmutableMap.of("a", "b"), action.getEnvironment());
assertEquals(ImmutableMap.of("a", "b"), action.getExecutionInfo());
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testExpandLocation.
@Test
public void testExpandLocation() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
// If there is only a single target, both "location" and "locations" should work
runExpansion(ruleContext, "location :jl", "[blaze]*-out/.*/bin/foo/libjl.jar");
runExpansion(ruleContext, "locations :jl", "[blaze]*-out/.*/bin/foo/libjl.jar");
runExpansion(ruleContext, "location //foo:jl", "[blaze]*-out/.*/bin/foo/libjl.jar");
// Multiple targets and "location" should result in an error
checkReportedErrorStartsWith(ruleContext, "in genrule rule //foo:bar: label '//foo:gl' " + "in $(location) expression expands to more than one file, please use $(locations " + "//foo:gl) instead.", "ruleContext.expand_location('$(location :gl)')");
// We have to use "locations" for multiple targets
runExpansion(ruleContext, "locations :gl", "[blaze]*-out/.*/bin/foo/gl.a [blaze]*-out/.*/bin/foo/gl.gcgox");
// LocationExpander just returns the input string if there is no label
runExpansion(ruleContext, "location", "\\$\\(location\\)");
checkReportedErrorStartsWith(ruleContext, "in genrule rule //foo:bar: label '//foo:abc' in $(locations) expression " + "is not a declared prerequisite of this rule", "ruleContext.expand_location('$(locations :abc)')");
}
use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionArgumentsWithCommand.
@Test
public void testCreateSpawnActionArgumentsWithCommand() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
createTestSpawnAction(ruleContext);
SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertArtifactFilenames(action.getInputs(), "a.txt", "b.img");
assertArtifactFilenames(action.getOutputs(), "a.txt", "b.img");
MoreAsserts.assertContainsSublist(action.getArguments(), "-c", "dummy_command", "", "--a", "--b");
assertEquals("DummyMnemonic", action.getMnemonic());
assertEquals("dummy_message", action.getProgressMessage());
assertEquals(targetConfig.getLocalShellEnvironment(), action.getEnvironment());
}
Aggregations