-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.4.0] Add diff_against_dynamic_baseline option to experimental_output_direc… #19514
Merged
iancha1992
merged 3 commits into
bazelbuild:release-6.4.0
from
fmeum:release-6.4.0-diff
Sep 14, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On master this is
rawBaselineOptions.hasNoConfig()
, which was introduced by https://cs.opensource.google/bazel/bazel/+/ea049e46c84fdcef2e1acd83d07053b7fa0a5cb5. I "inlined" it based on the comment, but please let me know whether you would want me to cherry-pick the full function intoBuildOptions
.