Search in sources :

Example 51 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testRunfilesArtifactsFromDefaultAndFiles.

@Test
public void testRunfilesArtifactsFromDefaultAndFiles() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
    Object result = evalRuleContextCode(ruleContext, "artifacts = ruleContext.files.srcs", // is an ImmutableList and Skylark interprets it as a tuple.
    "ruleContext.runfiles(collect_default = True, files = artifacts)");
    // From DEFAULT only libjl.jar comes, see testRunfilesAddFromDependencies().
    assertEquals(ActionsTestUtil.baseArtifactNames(getRunfileArtifacts(result)), ImmutableList.of("libjl.jar", "gl.a", "gl.gcgox"));
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 52 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testCodeCoverageConfigurationAccess.

@Test
public void testCodeCoverageConfigurationAccess() throws Exception {
    SkylarkRuleContext ctx = createRuleContext("//foo:baz");
    boolean coverage = (Boolean) evalRuleContextCode(ctx, "ruleContext.configuration.coverage_enabled");
    assertEquals(coverage, ctx.getRuleContext().getConfiguration().isCodeCoverageEnabled());
}
Also used : SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 53 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testRunfilesAddFromDependencies.

@Test
public void testRunfilesAddFromDependencies() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
    Object result = evalRuleContextCode(ruleContext, "ruleContext.runfiles(collect_default = True)");
    assertThat(ActionsTestUtil.baseArtifactNames(getRunfileArtifacts(result))).contains("libjl.jar");
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 54 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionUnknownParam.

@Test
public void testCreateSpawnActionUnknownParam() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    checkErrorContains(ruleContext, "unexpected keyword 'bad_param' in call to action(self: ctx, *, ", "ruleContext.action(outputs=[], bad_param = 'some text')");
}
Also used : SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 55 with SkylarkRuleContext

use of com.google.devtools.build.lib.rules.SkylarkRuleContext in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testEmptyLabelListTypeAttrInCtx.

@Test
public void testEmptyLabelListTypeAttrInCtx() throws Exception {
    SkylarkRuleContext ctx = createRuleContext("//foo:baz");
    Object result = evalRuleContextCode(ctx, "ruleContext.attr.srcs");
    assertEquals(MutableList.EMPTY, result);
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) 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