Search in sources :

Example 6 with SkylarkRuleContext

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);
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 7 with SkylarkRuleContext

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);
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 8 with SkylarkRuleContext

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());
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 9 with SkylarkRuleContext

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)')");
}
Also used : SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 10 with SkylarkRuleContext

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());
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) 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