Search in sources :

Example 1 with SkylarkClassObject

use of com.google.devtools.build.lib.packages.SkylarkClassObject in project bazel by bazelbuild.

the class TestSupport method getExtraProviders.

/**
   * Returns any additional providers that need to be exported to the rule context to the passed
   * builder.
   */
public Iterable<SkylarkClassObject> getExtraProviders() {
    IosDeviceProvider deviceProvider = (IosDeviceProvider) ruleContext.getPrerequisite(IosTest.TARGET_DEVICE, Mode.TARGET, IosDeviceProvider.SKYLARK_CONSTRUCTOR.getKey());
    DottedVersion xcodeVersion = deviceProvider.getXcodeVersion();
    AppleConfiguration configuration = ruleContext.getFragment(AppleConfiguration.class);
    ImmutableMap.Builder<String, String> envBuilder = ImmutableMap.builder();
    if (xcodeVersion != null) {
        envBuilder.putAll(configuration.getXcodeVersionEnv(xcodeVersion));
    }
    if (ruleContext.getConfiguration().isCodeCoverageEnabled()) {
        envBuilder.put("COVERAGE_GCOV_PATH", ruleContext.getHostPrerequisiteArtifact(IosTest.OBJC_GCOV_ATTR).getExecPathString());
        envBuilder.put("APPLE_COVERAGE", "1");
    }
    return ImmutableList.<SkylarkClassObject>of(new TestEnvironmentProvider(envBuilder.build()));
}
Also used : DottedVersion(com.google.devtools.build.lib.rules.apple.DottedVersion) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) TestEnvironmentProvider(com.google.devtools.build.lib.rules.test.TestEnvironmentProvider) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with SkylarkClassObject

use of com.google.devtools.build.lib.packages.SkylarkClassObject in project bazel by bazelbuild.

the class SkylarkIntegrationTest method rulesReturningDeclaredProviders.

@Test
public void rulesReturningDeclaredProviders() throws Exception {
    scratch.file("test/extension.bzl", "my_provider = provider()", "def _impl(ctx):", "   return [my_provider(x = 1)]", "my_rule = rule(_impl)");
    scratch.file("test/BUILD", "load(':extension.bzl', 'my_rule')", "my_rule(name = 'r')");
    ConfiguredTarget configuredTarget = getConfiguredTarget("//test:r");
    ClassObjectConstructor.Key key = new SkylarkClassObjectConstructor.SkylarkKey(Label.create(configuredTarget.getLabel().getPackageIdentifier(), "extension.bzl"), "my_provider");
    SkylarkProviders skylarkProviders = configuredTarget.getProvider(SkylarkProviders.class);
    assertThat(skylarkProviders).isNotNull();
    SkylarkClassObject declaredProvider = skylarkProviders.getDeclaredProvider(key);
    assertThat(declaredProvider).isNotNull();
    assertThat(declaredProvider.getConstructor().getKey()).isEqualTo(key);
    assertThat(declaredProvider.getValue("x")).isEqualTo(1);
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) ClassObjectConstructor(com.google.devtools.build.lib.packages.ClassObjectConstructor) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) RuleConfiguredTarget(com.google.devtools.build.lib.analysis.RuleConfiguredTarget) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Test(org.junit.Test)

Example 3 with SkylarkClassObject

use of com.google.devtools.build.lib.packages.SkylarkClassObject in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method declaredProvidersConcatSuccess.

@Test
public void declaredProvidersConcatSuccess() throws Exception {
    evalAndExport("data = provider()", "dx = data(x = 1)", "dy = data(y = 'abc')", "dxy = dx + dy", "x = dxy.x", "y = dxy.y");
    assertThat(lookup("x")).isEqualTo(1);
    assertThat(lookup("y")).isEqualTo("abc");
    SkylarkClassObjectConstructor dataConstructor = (SkylarkClassObjectConstructor) lookup("data");
    SkylarkClassObject dx = (SkylarkClassObject) lookup("dx");
    assertThat(dx.getConstructor()).isEqualTo(dataConstructor);
    SkylarkClassObject dy = (SkylarkClassObject) lookup("dy");
    assertThat(dy.getConstructor()).isEqualTo(dataConstructor);
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) Test(org.junit.Test)

Example 4 with SkylarkClassObject

use of com.google.devtools.build.lib.packages.SkylarkClassObject in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testStructConcatenationFieldValues.

@Test
public void testStructConcatenationFieldValues() throws Exception {
    // TODO(fwe): cannot be handled by current testing suite
    eval("x = struct(a = 1, b = 2)", "y = struct(c = 1, d = 2)", "z = x + y\n");
    SkylarkClassObject z = (SkylarkClassObject) lookup("z");
    assertEquals(1, z.getValue("a"));
    assertEquals(2, z.getValue("b"));
    assertEquals(1, z.getValue("c"));
    assertEquals(2, z.getValue("d"));
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) Test(org.junit.Test)

Example 5 with SkylarkClassObject

use of com.google.devtools.build.lib.packages.SkylarkClassObject in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method structsAsDeclaredProvidersTest.

@Test
public void structsAsDeclaredProvidersTest() throws Exception {
    evalAndExport("data = struct(x = 1)");
    SkylarkClassObject data = (SkylarkClassObject) lookup("data");
    assertThat(NativeClassObjectConstructor.STRUCT.isExported()).isTrue();
    assertThat(data.getConstructor()).isEqualTo(NativeClassObjectConstructor.STRUCT);
    assertThat(data.getConstructor().getKey()).isEqualTo(NativeClassObjectConstructor.STRUCT.getKey());
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) Test(org.junit.Test)

Aggregations

SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)27 Test (org.junit.Test)15 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)10 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)9 EvalException (com.google.devtools.build.lib.syntax.EvalException)6 Location (com.google.devtools.build.lib.events.Location)4 SkylarkClassObjectConstructor (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor)4 ClassObject (com.google.devtools.build.lib.syntax.ClassObject)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Artifact (com.google.devtools.build.lib.actions.Artifact)3 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)2 RuleConfiguredTarget (com.google.devtools.build.lib.analysis.RuleConfiguredTarget)2 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)2 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)2 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)2 ClassObjectConstructor (com.google.devtools.build.lib.packages.ClassObjectConstructor)2 SkylarkKey (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.SkylarkKey)2 SkylarkRuleContext (com.google.devtools.build.lib.rules.SkylarkRuleContext)2 Environment (com.google.devtools.build.lib.syntax.Environment)2 Mutability (com.google.devtools.build.lib.syntax.Mutability)2