-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.4.0] Add diff_against_dynamic_baseline option to experimental_outp…
…ut_direc… (#19514) …tory_naming_scheme. To support, a new SkyFunction is introduced, BaselineOptionsFunction, with corresponding SkyValue and SkyKey. Also, a new function ExecutionTransitionFactory.createTransition was added to immediately create an ExecutionTransition. When --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline, the behavior is similar to diff_against_baseline, except when "is Exec" is true (that is, an ExecutionTransition has previously been applied), the baseline is chosen to be result of the ExecutionTransition being applied to the normal baseline. This is meant to resolve an issue with performance when using remote execution engines that collate requests from multiple users. They were seeing varying output paths for actions in an execution configuration depending on how much 'resetting' the exec transition was doing because of varying user commandlines. This relates to #14023 and #18002 PiperOrigin-RevId: 537097551 Change-Id: I72966406b7b8af0174a81b638bf0d1fb62466653 Co-authored-by: Googler <twigg@google.com>
- Loading branch information
Showing
11 changed files
with
344 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../java/com/google/devtools/build/lib/analysis/config/transitions/BaselineOptionsValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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.transitions; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import com.google.devtools.build.lib.analysis.config.BuildOptions; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; | ||
import com.google.devtools.build.lib.skyframe.SkyFunctions; | ||
import com.google.devtools.build.skyframe.SkyFunctionName; | ||
import com.google.devtools.build.skyframe.SkyKey; | ||
import com.google.devtools.build.skyframe.SkyValue; | ||
import com.google.errorprone.annotations.CheckReturnValue; | ||
|
||
/** | ||
* This contains the baseline options to compare against when constructing output paths. | ||
* | ||
* <p>When constructing the output mnemonic as part of making a {@link BuildConfigurationValue} and | ||
* the selected naming scheme is to diff against a baseline, this function returns the baseline to | ||
* use for that comparison. Differences in options between the given option and this baseline will | ||
* then be used to append a deconflicting ST-hash to the output mnemonic. | ||
* | ||
* <p>The afterExecTransition option in the key will apply the exec transition to the usual | ||
* baseline. It is expected that this is set whenever the given options have isExec set (and thus an | ||
* exec transition has already been applied to those options). The expectation here is that, as the | ||
* exec transition particularly sets many options, comparing against a post-exec baseline will yield | ||
* fewer diffenences. Note that some indicator must be added to the mnemonic (e.g. -exec-) in order | ||
* to deconflict for similar options where isExec is not set. | ||
*/ | ||
@CheckReturnValue | ||
@Immutable | ||
@ThreadSafe | ||
@AutoValue | ||
public abstract class BaselineOptionsValue implements SkyValue { | ||
public abstract BuildOptions toOptions(); | ||
|
||
public static BaselineOptionsValue create(BuildOptions toOptions) { | ||
return new AutoValue_BaselineOptionsValue(toOptions); | ||
} | ||
|
||
public static Key key(boolean afterExecTransition) { | ||
return Key.create(afterExecTransition); | ||
} | ||
|
||
/** {@link SkyKey} implementation used for {@link BaselineOptionsValue}. */ | ||
@CheckReturnValue | ||
@Immutable | ||
@ThreadSafe | ||
@AutoValue | ||
public abstract static class Key implements SkyKey { | ||
public abstract boolean afterExecTransition(); | ||
|
||
@Override | ||
public SkyFunctionName functionName() { | ||
return SkyFunctions.BASELINE_OPTIONS; | ||
} | ||
|
||
static Key create(boolean afterExecTransition) { | ||
return new AutoValue_BaselineOptionsValue_Key(afterExecTransition); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/com/google/devtools/build/lib/skyframe/BaselineOptionsFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// 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.skyframe; | ||
|
||
import com.google.devtools.build.lib.analysis.PlatformOptions; | ||
import com.google.devtools.build.lib.analysis.config.BuildOptions; | ||
import com.google.devtools.build.lib.analysis.config.CoreOptions; | ||
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory; | ||
import com.google.devtools.build.lib.analysis.config.transitions.BaselineOptionsValue; | ||
import com.google.devtools.build.lib.analysis.config.transitions.PatchTransition; | ||
import com.google.devtools.build.lib.analysis.config.transitions.TransitionUtil; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
import com.google.devtools.build.skyframe.SkyFunction; | ||
import com.google.devtools.build.skyframe.SkyFunctionException; | ||
import com.google.devtools.build.skyframe.SkyKey; | ||
import com.google.devtools.build.skyframe.SkyValue; | ||
import com.google.devtools.common.options.OptionsParsingException; | ||
import javax.annotation.Nullable; | ||
|
||
/** A builder for {@link BaselineOptionsValue} instances. */ | ||
public final class BaselineOptionsFunction implements SkyFunction { | ||
@Override | ||
@Nullable | ||
public SkyValue compute(SkyKey skyKey, Environment env) | ||
throws InterruptedException, BaselineOptionsFunctionException { | ||
BaselineOptionsValue.Key key = (BaselineOptionsValue.Key) skyKey.argument(); | ||
|
||
BuildOptions rawBaselineOptions = PrecomputedValue.BASELINE_CONFIGURATION.get(env); | ||
|
||
// Some test infrastructure only creates mock or partial top-level BuildOptions such that | ||
// PlatformOptions or even CoreOptions might not be included. | ||
// In that case, is not worth doing any special processing of the baseline. | ||
if (!rawBaselineOptions.getFragmentClasses().contains(PlatformOptions.class) | ||
|| !rawBaselineOptions.getFragmentClasses().contains(CoreOptions.class)) { | ||
return BaselineOptionsValue.create(rawBaselineOptions); | ||
} | ||
|
||
// Herein lies a hack to apply platform mappings to the baseline options. | ||
// TODO(blaze-configurability-team): this should become unnecessary once --platforms is marked | ||
// as EXPLICIT_IN_OUTPUT_PATH | ||
PlatformMappingValue platformMappingValue = | ||
(PlatformMappingValue) | ||
env.getValue( | ||
PlatformMappingValue.Key.create( | ||
rawBaselineOptions.get(PlatformOptions.class).platformMappings)); | ||
if (platformMappingValue == null) { | ||
return null; | ||
} | ||
try { | ||
BuildOptions mappedBaselineOptions = | ||
BuildConfigurationKey.withPlatformMapping(platformMappingValue, rawBaselineOptions) | ||
.getOptions(); | ||
|
||
if (key.afterExecTransition()) { | ||
// A null executionPlatform actually skips transition application so need some value here. | ||
// It is safe to supply some fake value here (as long as it is constant) since the baseline | ||
// should never be used to actually construct an action or do toolchain resolution | ||
// TODO(twigg): This can eventually be replaced by the actual exec platform once | ||
// platforms is explicitly in the output path (with the garbage value as a fallback). | ||
PatchTransition execTransition = | ||
ExecutionTransitionFactory.createTransition( | ||
Label.parseCanonicalUnchecked( | ||
"//this_is_a_faked_exec_platform_for_blaze_internals")); | ||
BuildOptions toOptions = | ||
execTransition.patch( | ||
TransitionUtil.restrict(execTransition, mappedBaselineOptions), env.getListener()); | ||
return BaselineOptionsValue.create(toOptions); | ||
} else { | ||
return BaselineOptionsValue.create(mappedBaselineOptions); | ||
} | ||
} catch (OptionsParsingException e) { | ||
throw new BaselineOptionsFunctionException(e); | ||
} | ||
} | ||
|
||
private static final class BaselineOptionsFunctionException extends SkyFunctionException { | ||
BaselineOptionsFunctionException(Exception e) { | ||
super(e, Transience.PERSISTENT); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.