Search in sources :

Example 71 with SkylarkRuleContext

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

the class SkylarkRuleContextTest method testFeatures.

@Test
public void testFeatures() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:cc_with_features");
    Object result = evalRuleContextCode(ruleContext, "ruleContext.features");
    assertThat((SkylarkList<?>) result).containsExactly("cc_include_scanning", "f1", "f2");
}
Also used : SkylarkList(com.google.devtools.build.lib.syntax.SkylarkList) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 72 with SkylarkRuleContext

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

the class SkylarkRuleContextTest method testCoverageInstrumentedDoesNotMatchFilter.

@Test
public void testCoverageInstrumentedDoesNotMatchFilter() throws Exception {
    setUpCoverageInstrumentedTest();
    useConfiguration("--collect_code_coverage", "--instrumentation_filter=:foo");
    SkylarkRuleContext ruleContext = createRuleContext("//test:bar");
    Object result = evalRuleContextCode(ruleContext, "ruleContext.coverage_instrumented()");
    assertThat((Boolean) result).isFalse();
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 73 with SkylarkRuleContext

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

the class SkylarkRuleContextTest method testGetRuleAttributeListValueNoGet.

@Test
public void testGetRuleAttributeListValueNoGet() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.outs");
    assertEquals(1, ((SkylarkList) result).size());
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 74 with SkylarkRuleContext

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

the class SkylarkRuleContextTest method testFileWriteActionInterface.

@Test
public void testFileWriteActionInterface() throws Exception {
    scratch.file("test/rules.bzl", getSimpleUnderTestDefinition("ctx.file_action(output=out, content='foo123')"), testingRuleDefinition);
    scratch.file("test/BUILD", simpleBuildDefinition);
    SkylarkRuleContext ruleContext = createRuleContext("//test:testing");
    update("ruleContext", ruleContext);
    update("file", eval("list(ruleContext.attr.dep.files)[0]"));
    update("action", eval("ruleContext.attr.dep[Actions].by_file[file]"));
    assertThat(eval("type(action)")).isEqualTo("Action");
    Object contentUnchecked = eval("action.content");
    assertThat(contentUnchecked).isInstanceOf(String.class);
    assertThat(contentUnchecked).isEqualTo("foo123");
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 75 with SkylarkRuleContext

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

the class SkylarkRuleContextTest method testDeriveArtifactLegacy.

@Test
public void testDeriveArtifactLegacy() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    Object result = evalRuleContextCode(ruleContext, "ruleContext.new_file(ruleContext.genfiles_dir," + "  'a/b.txt')");
    PathFragment fragment = ((Artifact) result).getRootRelativePath();
    assertEquals("foo/a/b.txt", fragment.getPathString());
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Artifact(com.google.devtools.build.lib.actions.Artifact) 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