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()));
}
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);
}
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);
}
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"));
}
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());
}
Aggregations