Add --experimental_output_paths=content (without implementation)
This will enable content-based output paths, as described at
https://docs.google.com/document/d/17snvmic26-QdGuwVw55Gl0oOufw9sCVuOAvHqGZJFr4/edit#heading=h.5mcn15i0e1ch.
See https://github.com/bazelbuild/bazel/issues/8339.
Notes:
* I originally tried to put this in BuildRequestOptions since this goes
beyond configuration (it also affects execution-phase logic). But
piping that to the right consumers was a lot more awkward, so here
it is.
* One nice thing about keeping this in BuildConfiguration is switching it
automatically invalidates configured targets without having to pass
external Skyframe context.
* This should arguably be a startup option since it's effect on action
caches, the general build graph, action execution logic, and output
metadata services could be potentially far-reaching. I wouldn't
particularly call this a flag where it's safe to keep all Bazel's
incremental state when switching. But I'm trying to avoid use of
startup options and we might be able to get away just fine with
with judicious use of reset() calls to things like SkyframeBuildView.
For the current super-experimental alpha phase I think these risks
are worth the ease-of-use putting this in BuildConfiguration offers.
PiperOrigin-RevId: 249241985
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
index ef72c10..860161d 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
@@ -786,6 +786,21 @@
}
/**
+ * <b>>Experimental feature:</b> if true, qualifying outputs use path prefixes based on their
+ * content instead of the traditional <code>blaze-out/$CPU-$COMPILATION_MODE</code>.
+ *
+ * <p>This promises both more intrinsic correctness (outputs with different contents can't write
+ * to the same path) and efficiency (outputs with the <i>same</i> contents share the same path and
+ * therefore permit better action caching). But it's highly experimental and should not be relied
+ * on in any serious way any time soon.
+ *
+ * <p>See <a href="https://github.com/bazelbuild/bazel/issues/6526">#6526</a> for details.
+ */
+ public boolean useContentBasedOutputPaths() {
+ return options.outputPathsMode == CoreOptions.OutputPathsMode.CONTENT;
+ }
+
+ /**
* Returns compilation mode.
*/
public CompilationMode getCompilationMode() {
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java
index 2a01f9b..905e5a9 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java
@@ -597,6 +597,46 @@
help = "Instantiates build configurations with the specified properties")
public ConfigsMode configsMode;
+ /** Values for --experimental_output_paths. */
+ public enum OutputPathsMode {
+ /** Use the production output path model. */
+ OFF,
+ /**
+ * Use <a href="https://github.com/bazelbuild/bazel/issues/6526#issuecomment-488103473">
+ * content-based paths</a>.
+ *
+ * <p>Rule implementations also have to individually opt into this. So this setting doesn't mean
+ * all outputs follow this. Non-opted-in outputs continue to use the production model.
+ *
+ * <p>Follow the above link for latest details on exact scope.
+ */
+ CONTENT,
+ }
+
+ /** Converter for --experimental_output_paths. */
+ public static class OutputPathsConverter extends EnumConverter<OutputPathsMode> {
+ public OutputPathsConverter() {
+ super(OutputPathsMode.class, "output path mode");
+ }
+ }
+
+ @Option(
+ name = "experimental_output_paths",
+ converter = OutputPathsConverter.class,
+ defaultValue = "off",
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {
+ OptionEffectTag.LOSES_INCREMENTAL_STATE,
+ OptionEffectTag.BAZEL_INTERNAL_CONFIGURATION,
+ OptionEffectTag.AFFECTS_OUTPUTS,
+ OptionEffectTag.EXECUTION
+ },
+ help =
+ "Which model to use for where in the output tree rules write their outputs, particularly "
+ + "for multi-platform / multi-configuration builds. This is highly experimental. See "
+ + "https://github.com/bazelbuild/bazel/issues/6526 for details.")
+ public OutputPathsMode outputPathsMode;
+
@Option(
name = "enable_runfiles",
oldName = "experimental_enable_runfiles",
@@ -641,6 +681,7 @@
host.compilationMode = hostCompilationMode;
host.isHost = true;
host.configsMode = configsMode;
+ host.outputPathsMode = outputPathsMode;
host.enableRunfiles = enableRunfiles;
host.executionInfoModifier = executionInfoModifier;
host.commandLineBuildVariables = commandLineBuildVariables;