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