Search in sources :

Example 1 with TestEnvironmentProvider

use of com.google.devtools.build.lib.rules.test.TestEnvironmentProvider 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 TestEnvironmentProvider

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

the class RuleConfiguredTargetBuilder method initializeTestProvider.

private TestProvider initializeTestProvider(FilesToRunProvider filesToRunProvider) {
    int explicitShardCount = ruleContext.attributes().get("shard_count", Type.INTEGER);
    if (explicitShardCount < 0 && ruleContext.getRule().isAttributeValueExplicitlySpecified("shard_count")) {
        ruleContext.attributeError("shard_count", "Must not be negative.");
    }
    if (explicitShardCount > 50) {
        ruleContext.attributeError("shard_count", "Having more than 50 shards is indicative of poor test organization. " + "Please reduce the number of shards.");
    }
    TestActionBuilder testActionBuilder = new TestActionBuilder(ruleContext).setInstrumentedFiles(providersBuilder.getProvider(InstrumentedFilesProvider.class));
    TestEnvironmentProvider environmentProvider = (TestEnvironmentProvider) skylarkDeclaredProviders.build().get(TestEnvironmentProvider.SKYLARK_CONSTRUCTOR.getKey());
    if (environmentProvider != null) {
        testActionBuilder.addExtraEnv(environmentProvider.getEnvironment());
    }
    TestParams testParams = testActionBuilder.setFilesToRunProvider(filesToRunProvider).setExecutionRequirements((ExecutionInfoProvider) skylarkDeclaredProviders.build().get(ExecutionInfoProvider.SKYLARK_CONSTRUCTOR.getKey())).setShardCount(explicitShardCount).build();
    ImmutableList<String> testTags = ImmutableList.copyOf(ruleContext.getRule().getRuleTags());
    return new TestProvider(testParams, testTags);
}
Also used : TestProvider(com.google.devtools.build.lib.rules.test.TestProvider) TestActionBuilder(com.google.devtools.build.lib.rules.test.TestActionBuilder) InstrumentedFilesProvider(com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider) TestParams(com.google.devtools.build.lib.rules.test.TestProvider.TestParams) TestEnvironmentProvider(com.google.devtools.build.lib.rules.test.TestEnvironmentProvider)

Aggregations

TestEnvironmentProvider (com.google.devtools.build.lib.rules.test.TestEnvironmentProvider)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)1 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)1 DottedVersion (com.google.devtools.build.lib.rules.apple.DottedVersion)1 InstrumentedFilesProvider (com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider)1 TestActionBuilder (com.google.devtools.build.lib.rules.test.TestActionBuilder)1 TestProvider (com.google.devtools.build.lib.rules.test.TestProvider)1 TestParams (com.google.devtools.build.lib.rules.test.TestProvider.TestParams)1