From 563664e0e0a9083be554b4931654743d84b9cba4 Mon Sep 17 00:00:00 2001 From: twigg Date: Tue, 15 Feb 2022 13:56:25 -0800 Subject: [PATCH] Add `--incompatible_android_platforms_transition_updates_affected` This is essentially a quick followup to the `diffToAffected` mode of `--experimental_exec_configuration_distinguisher` and intended for use with that mode. This setting causes the AndroidPlatformsTransition to also update `affected by Starlark transition` with the changed options. PiperOrigin-RevId: 428868170 --- .../starlark/FunctionTransitionUtil.java | 2 +- .../rules/android/AndroidConfiguration.java | 12 ++++++++++ .../android/AndroidPlatformsTransition.java | 23 ++++++++++++++++++- .../devtools/build/lib/rules/android/BUILD | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/FunctionTransitionUtil.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/FunctionTransitionUtil.java index 5ddcf24e4bd1bc..2e1fa8071d4991 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/FunctionTransitionUtil.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/FunctionTransitionUtil.java @@ -467,7 +467,7 @@ public static String computeOutputDirectoryNameFragment(BuildOptions toOptions) * Extend the global build config affectedByStarlarkTransition, by adding any new option names * from changedOptions */ - private static void updateAffectedByStarlarkTransition( + public static void updateAffectedByStarlarkTransition( CoreOptions buildConfigOptions, Set changedOptions) { if (changedOptions.isEmpty()) { return; diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java index 0b0188bcf937f0..0da5a9d84ad6a4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java @@ -966,6 +966,17 @@ public static class Options extends FragmentOptions { + " This will make the build nondeterministic.") public boolean includeProguardLocationReferences; + @Option( + name = "incompatible_android_platforms_transition_updated_affected", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = OptionEffectTag.LOADING_AND_ANALYSIS, + metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE}, + help = + "If set to true, the AndroidPlatformsTransition will also update `affected by Starlark" + + " transition` with changed options to avoid potential action conflicts.") + public boolean androidPlatformsTransitionsUpdateAffected; + @Override public FragmentOptions getHost() { Options host = (Options) super.getHost(); @@ -974,6 +985,7 @@ public FragmentOptions getHost() { host.sdk = sdk; host.fatApkCpus = ImmutableList.of(); // Fat APK archs don't apply to the host. host.incompatibleUseToolchainResolution = incompatibleUseToolchainResolution; + host.androidPlatformsTransitionsUpdateAffected = androidPlatformsTransitionsUpdateAffected; host.desugarJava8 = desugarJava8; host.desugarJava8Libs = desugarJava8Libs; diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidPlatformsTransition.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidPlatformsTransition.java index c8f0225d230a10..298c6d62ea810e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidPlatformsTransition.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidPlatformsTransition.java @@ -18,10 +18,12 @@ 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.BuildOptionsView; +import com.google.devtools.build.lib.analysis.config.CoreOptions; import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.analysis.config.transitions.PatchTransition; import com.google.devtools.build.lib.analysis.config.transitions.StarlarkExposedRuleTransitionFactory; import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory; +import com.google.devtools.build.lib.analysis.starlark.FunctionTransitionUtil; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.packages.RuleTransitionData; import com.google.devtools.build.lib.rules.cpp.CppOptions; @@ -51,7 +53,10 @@ public static TransitionFactory create() { @Override public ImmutableSet> requiresOptionFragments() { return ImmutableSet.of( - AndroidConfiguration.Options.class, PlatformOptions.class, CppOptions.class); + AndroidConfiguration.Options.class, + PlatformOptions.class, + CoreOptions.class, + CppOptions.class); } @Override @@ -74,6 +79,22 @@ public BuildOptions patch(BuildOptionsView options, EventHandler eventHandler) { newOptions.get(CppOptions.class).enableCcToolchainResolution = true; } + if (androidOptions.androidPlatformsTransitionsUpdateAffected) { + ImmutableSet.Builder affected = ImmutableSet.builder(); + if (!options + .get(PlatformOptions.class) + .platforms + .equals(newOptions.get(PlatformOptions.class).platforms)) { + affected.add("//command_line_option:platforms"); + } + if (options.get(CppOptions.class).enableCcToolchainResolution + != newOptions.get(CppOptions.class).enableCcToolchainResolution) { + affected.add("//command_line_option:incompatible_enable_cc_toolchain_resolution"); + } + FunctionTransitionUtil.updateAffectedByStarlarkTransition( + newOptions.get(CoreOptions.class), affected.build()); + } + return newOptions.underlying(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/BUILD b/src/main/java/com/google/devtools/build/lib/rules/android/BUILD index f0c6e142377034..626a113ca3b2c9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/android/BUILD @@ -65,6 +65,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis:required_config_fragments_provider", "//src/main/java/com/google/devtools/build/lib/analysis:resolved_toolchain_context", "//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment", + "//src/main/java/com/google/devtools/build/lib/analysis:starlark/function_transition_util", "//src/main/java/com/google/devtools/build/lib/analysis:starlark/starlark_api_provider", "//src/main/java/com/google/devtools/build/lib/analysis:starlark/starlark_error_reporter", "//src/main/java/com/google/devtools/build/lib/analysis:test/execution_info",