Skip to content

Commit

Permalink
Post configuration creation messages for better logging.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 537050693
Change-Id: I15f13b50f24816c5f1d193013a76b34986c6e7a2
  • Loading branch information
gregestren authored and copybara-github committed Jun 1, 2023
1 parent 711f1b0 commit b9e1ec7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ java_library(
srcs = [
"config/BuildConfigurationInfo.java",
"config/BuildConfigurationValue.java",
"config/ConfigRequestedEvent.java",
"config/OutputDirectories.java",
],
deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.devtools.build.lib.actions.TotalAndConfiguredTargetOnlyMetric;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.ConfigRequestedEvent;
import com.google.devtools.build.lib.analysis.config.ConfigurationResolver.TopLevelTargetsAndConfigsResult;
import com.google.devtools.build.lib.analysis.config.CoreOptions;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
Expand Down Expand Up @@ -251,32 +252,33 @@ public AnalysisResult update(
eventBus.post(new AnalysisPhaseStartedEvent(labelToTargetMap.values()));

// Prepare the analysis phase
BuildConfigurationValue configuration;
BuildConfigurationValue topLevelConfig;
TopLevelTargetsAndConfigsResult topLevelTargetsWithConfigsResult;
// Configuration creation.
// TODO(gregce): Consider dropping this phase and passing on-the-fly target / exec configs as
// needed. This requires cleaning up the invalidation in SkyframeBuildView.setConfigurations.
try (SilentCloseable c = Profiler.instance().profile("createConfigurations")) {
configuration = skyframeExecutor.createConfiguration(eventHandler, targetOptions, keepGoing);
topLevelConfig = skyframeExecutor.createConfiguration(eventHandler, targetOptions, keepGoing);
eventBus.post(new ConfigRequestedEvent(topLevelConfig, /* parentChecksum= */ null));
}
if (buildConfigurationsCreatedCallback != null) {
buildConfigurationsCreatedCallback.run(configuration);
buildConfigurationsCreatedCallback.run(topLevelConfig);
}
try (SilentCloseable c = Profiler.instance().profile("AnalysisUtils.getTargetsWithConfigs")) {
topLevelTargetsWithConfigsResult =
AnalysisUtils.getTargetsWithConfigs(
configuration,
topLevelConfig,
labelToTargetMap.values(),
eventHandler,
ruleClassProvider,
skyframeExecutor);
}

skyframeBuildView.setConfiguration(
eventHandler, configuration, viewOptions.maxConfigChangesToShow);
eventHandler, topLevelConfig, viewOptions.maxConfigChangesToShow);

eventBus.post(new MakeEnvironmentEvent(configuration.getMakeEnvironment()));
eventBus.post(configuration.toBuildEvent());
eventBus.post(new MakeEnvironmentEvent(topLevelConfig.getMakeEnvironment()));
eventBus.post(topLevelConfig.toBuildEvent());

Collection<TargetAndConfiguration> topLevelTargetsWithConfigs =
topLevelTargetsWithConfigsResult.getTargetsAndConfigs();
Expand All @@ -285,6 +287,10 @@ public AnalysisResult update(
Multimap<Label, BuildConfigurationValue> byLabel = ArrayListMultimap.create();
for (TargetAndConfiguration pair : topLevelTargetsWithConfigs) {
byLabel.put(pair.getLabel(), pair.getConfiguration());
if (pair.getConfiguration() != null && !pair.getConfiguration().equals(topLevelConfig)) {
// Log top-level rule transitioned configurations.
eventBus.post(new ConfigRequestedEvent(pair.getConfiguration(), topLevelConfig.checksum()));
}
}
for (Target target : labelToTargetMap.values()) {
eventBus.post(new TargetConfiguredEvent(target, byLabel.get(target.getLabel())));
Expand Down Expand Up @@ -479,7 +485,7 @@ public AnalysisResult update(
eventHandler,
eventBus,
loadingResult,
configuration,
topLevelConfig,
topLevelOptions,
viewOptions,
skyframeAnalysisResult,
Expand Down Expand Up @@ -525,7 +531,7 @@ public AnalysisResult update(
eventHandler,
eventBus,
loadingResult,
configuration,
topLevelConfig,
topLevelOptions,
viewOptions,
skyframeAnalysisResult,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2023 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.analysis.config;

import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable;
import javax.annotation.Nullable;

/** A Bazel invocation requested a {@link BuildConfigurationValue}. */
public class ConfigRequestedEvent implements Postable {
private final BuildConfigurationValue config;

@Nullable private final String parentChecksum;

/**
* Requested configuration event.
*
* @param config the configuration
* @param parentChecksum the configuration that produces this one from a transition. If null, the
* current configuration is top-level.
*/
public ConfigRequestedEvent(BuildConfigurationValue config, @Nullable String parentChecksum) {
this.config = config;
this.parentChecksum = parentChecksum;
}

public BuildConfigurationValue getConfig() {
return config;
}

@Nullable
public String getParentChecksum() {
return parentChecksum;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,19 @@ public ImmutableList<Dependency> resolveConfiguration(
return ImmutableList.of(resolvedDep);
}

return resolveGenericTransition(dependencyBuilder, dependencyKey, eventHandler);
var ans = resolveGenericTransition(dependencyBuilder, dependencyKey, eventHandler);
if (ans != null) {
ans.stream()
.filter(d -> d.getConfiguration() != null)
// No need to log no-op transitions.
.filter(d -> !d.getConfiguration().equals(ctgValue.getConfiguration()))
.forEach(
d ->
eventHandler.post(
new ConfigRequestedEvent(
d.getConfiguration(), ctgValue.getConfiguration().checksum())));
}
return ans;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.devtools.build.lib.analysis.ToolchainCollection;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.analysis.config.ConfigConditions;
import com.google.devtools.build.lib.analysis.config.ConfigRequestedEvent;
import com.google.devtools.build.lib.analysis.config.ConfigurationResolver;
import com.google.devtools.build.lib.analysis.config.TransitionResolver;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
Expand Down Expand Up @@ -282,6 +283,15 @@ public SkyValue compute(SkyKey key, Environment env)
}
Preconditions.checkNotNull(prereqs.getDepValueMap());

// If this CT applied an incoming rule transition, log it.
BuildConfigurationValue config = prereqs.getTargetAndConfiguration().getConfiguration();
if (config != null && !config.getKey().equals(configuredTargetKey.getConfigurationKey())) {
env.getListener()
.post(
new ConfigRequestedEvent(
config, configuredTargetKey.getConfigurationKey().getOptionsChecksum()));
}

// If one of our dependencies is platform-incompatible with this build, so are we.
Optional<RuleConfiguredTargetValue> incompatibleTarget =
IncompatibleTargetChecker.createIndirectlyIncompatibleTarget(
Expand Down

0 comments on commit b9e1ec7

Please sign in to comment.