Search in sources :

Example 1 with LabelAndConfiguration

use of com.google.devtools.build.lib.analysis.LabelAndConfiguration in project bazel by bazelbuild.

the class ConfiguredTargetFunction method compute.

@Override
public SkyValue compute(SkyKey key, Environment env) throws ConfiguredTargetFunctionException, InterruptedException {
    SkyframeBuildView view = buildViewProvider.getSkyframeBuildView();
    NestedSetBuilder<Package> transitivePackages = NestedSetBuilder.stableOrder();
    NestedSetBuilder<Label> transitiveLoadingRootCauses = NestedSetBuilder.stableOrder();
    ConfiguredTargetKey configuredTargetKey = (ConfiguredTargetKey) key.argument();
    LabelAndConfiguration lc = LabelAndConfiguration.of(configuredTargetKey.getLabel(), configuredTargetKey.getConfiguration());
    BuildConfiguration configuration = lc.getConfiguration();
    PackageValue packageValue = (PackageValue) env.getValue(PackageValue.key(lc.getLabel().getPackageIdentifier()));
    if (packageValue == null) {
        return null;
    }
    // TODO(ulfjack): This tries to match the logic in TransitiveTargetFunction /
    // TargetMarkerFunction. Maybe we can merge the two?
    Package pkg = packageValue.getPackage();
    Target target;
    try {
        target = pkg.getTarget(lc.getLabel().getName());
    } catch (NoSuchTargetException e) {
        throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException(e.getMessage()));
    }
    if (pkg.containsErrors()) {
        transitiveLoadingRootCauses.add(lc.getLabel());
    }
    transitivePackages.add(pkg);
    // null).
    if (!target.isConfigurable()) {
        configuration = null;
    }
    // associates the error with the dep, which is misleading.
    if (useDynamicConfigurations(configuration) && configuration.trimConfigurations() && env.getValue(TransitiveTargetValue.key(lc.getLabel())) == null) {
        return null;
    }
    TargetAndConfiguration ctgValue = new TargetAndConfiguration(target, configuration);
    SkyframeDependencyResolver resolver = view.createDependencyResolver(env);
    // TODO(janakr): this acquire() call may tie up this thread indefinitely, reducing the
    // parallelism of Skyframe. This is a strict improvement over the prior state of the code, in
    // which we ran with #processors threads, but ideally we would call #tryAcquire here, and if we
    // failed, would exit this SkyFunction and restart it when permits were available.
    cpuBoundSemaphore.acquire();
    try {
        // Get the configuration targets that trigger this rule's configurable attributes.
        ImmutableMap<Label, ConfigMatchingProvider> configConditions = getConfigConditions(ctgValue.getTarget(), env, resolver, ctgValue, transitivePackages, transitiveLoadingRootCauses);
        if (env.valuesMissing()) {
            return null;
        }
        // attributes.
        if (!transitiveLoadingRootCauses.isEmpty() && configConditions != NO_CONFIG_CONDITIONS) {
            throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException(transitiveLoadingRootCauses.build()));
        }
        OrderedSetMultimap<Attribute, ConfiguredTarget> depValueMap = computeDependencies(env, resolver, ctgValue, ImmutableList.<Aspect>of(), configConditions, ruleClassProvider, view.getHostConfiguration(configuration), transitivePackages, transitiveLoadingRootCauses);
        if (env.valuesMissing()) {
            return null;
        }
        if (!transitiveLoadingRootCauses.isEmpty()) {
            throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException(transitiveLoadingRootCauses.build()));
        }
        Preconditions.checkNotNull(depValueMap);
        ConfiguredTargetValue ans = createConfiguredTarget(view, env, target, configuration, depValueMap, configConditions, transitivePackages);
        return ans;
    } catch (DependencyEvaluationException e) {
        if (e.getCause() instanceof ConfiguredValueCreationException) {
            throw new ConfiguredTargetFunctionException((ConfiguredValueCreationException) e.getCause());
        } else if (e.getCause() instanceof InconsistentAspectOrderException) {
            InconsistentAspectOrderException cause = (InconsistentAspectOrderException) e.getCause();
            throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException(cause.getMessage(), target.getLabel()));
        } else {
            // Cast to InvalidConfigurationException as a consistency check. If you add any
            // DependencyEvaluationException constructors, you may need to change this code, too.
            InvalidConfigurationException cause = (InvalidConfigurationException) e.getCause();
            throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException(cause.getMessage(), target.getLabel()));
        }
    } catch (AspectCreationException e) {
        // getAnalysisRootCause may be null if the analysis of the aspect itself failed.
        Label analysisRootCause = target.getLabel();
        if (e.getAnalysisRootCause() != null) {
            analysisRootCause = e.getAnalysisRootCause();
        }
        throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException(e.getMessage(), analysisRootCause));
    } finally {
        cpuBoundSemaphore.release();
    }
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) Target(com.google.devtools.build.lib.packages.Target) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) LabelAndConfiguration(com.google.devtools.build.lib.analysis.LabelAndConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) InconsistentAspectOrderException(com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException) AspectCreationException(com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException) TargetAndConfiguration(com.google.devtools.build.lib.analysis.TargetAndConfiguration) ConfigMatchingProvider(com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider) Package(com.google.devtools.build.lib.packages.Package)

Example 2 with LabelAndConfiguration

use of com.google.devtools.build.lib.analysis.LabelAndConfiguration in project bazel by bazelbuild.

the class TestCompletionFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    TestCompletionValue.TestCompletionKey key = (TestCompletionValue.TestCompletionKey) skyKey.argument();
    LabelAndConfiguration lac = key.labelAndConfiguration();
    TopLevelArtifactContext ctx = key.topLevelArtifactContext();
    if (env.getValue(TargetCompletionValue.key(lac, ctx)) == null) {
        return null;
    }
    ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ConfiguredTargetValue.key(lac.getLabel(), lac.getConfiguration()));
    if (ctValue == null) {
        return null;
    }
    ConfiguredTarget ct = ctValue.getConfiguredTarget();
    if (key.exclusiveTesting()) {
        // Request test artifacts iteratively if testing exclusively.
        for (Artifact testArtifact : TestProvider.getTestStatusArtifacts(ct)) {
            if (env.getValue(ArtifactSkyKey.key(testArtifact, /*isMandatory=*/
            true)) == null) {
                return null;
            }
        }
    } else {
        env.getValues(ArtifactSkyKey.mandatoryKeys(TestProvider.getTestStatusArtifacts(ct)));
        if (env.valuesMissing()) {
            return null;
        }
    }
    return TestCompletionValue.TEST_COMPLETION_MARKER;
}
Also used : LabelAndConfiguration(com.google.devtools.build.lib.analysis.LabelAndConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 3 with LabelAndConfiguration

use of com.google.devtools.build.lib.analysis.LabelAndConfiguration in project bazel by bazelbuild.

the class AggregatingTestListener method testEvent.

/**
   * Records a new test run result and incrementally updates the target status.
   * This event is sent upon completion of executed test runs.
   */
@Subscribe
@AllowConcurrentEvents
public void testEvent(TestResult result) {
    Preconditions.checkState(statusMap.put(result.getTestStatusArtifact(), result) == null, "Duplicate result reported for an individual test shard");
    ActionOwner testOwner = result.getTestAction().getOwner();
    LabelAndConfiguration targetLabel = LabelAndConfiguration.of(testOwner.getLabel(), result.getTestAction().getConfiguration());
    // executed. Hence report that fact as a cached attempt.
    if (result.isCached()) {
        eventBus.post(TestAttempt.fromCachedTestResult(result));
    }
    TestSummary finalTestSummary = null;
    synchronized (summaryLock) {
        TestSummary.Builder summary = summaries.get(targetLabel);
        preconditionHelper.checkNotNull(summary);
        if (!remainingRuns.remove(targetLabel, result.getTestStatusArtifact())) {
            // This situation is likely to happen if --notest_keep_going is set with multiple targets.
            return;
        }
        summary = analyzer.incrementalAnalyze(summary, result);
        // If all runs are processed, the target is finished and ready to report.
        if (!remainingRuns.containsKey(targetLabel)) {
            finalTestSummary = summary.build();
        }
    }
    // Report finished targets.
    if (finalTestSummary != null) {
        eventBus.post(finalTestSummary);
    }
}
Also used : LabelAndConfiguration(com.google.devtools.build.lib.analysis.LabelAndConfiguration) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

LabelAndConfiguration (com.google.devtools.build.lib.analysis.LabelAndConfiguration)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)1 Subscribe (com.google.common.eventbus.Subscribe)1 ActionOwner (com.google.devtools.build.lib.actions.ActionOwner)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)1 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)1 TargetAndConfiguration (com.google.devtools.build.lib.analysis.TargetAndConfiguration)1 TopLevelArtifactContext (com.google.devtools.build.lib.analysis.TopLevelArtifactContext)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)1 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)1 Label (com.google.devtools.build.lib.cmdline.Label)1 Attribute (com.google.devtools.build.lib.packages.Attribute)1 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)1 Package (com.google.devtools.build.lib.packages.Package)1 Target (com.google.devtools.build.lib.packages.Target)1 AspectCreationException (com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException)1