From 95de355e4524a6339c0e807b60d333c36c40bdc7 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 15 Mar 2022 13:38:17 +0100 Subject: [PATCH] Do not validate input-only settings in transitions (#15048) Starlark transition logic temporarily explicitly sets all input build settings of a transition to their defaults. Since #13971, these values are cleared after the transition. However, since then they have also been subject to type validation, which is not only unnecessary, but also breaks in the special case of a string build setting with allow_multiple. With this commit, input-only build settings are unconditionally stripped from the post-transition BuildOptions and do not undergo validation. This is made possible by a refactoring of `StarlarkTransition#validate` that extracts the validation logic into a separate function and also improves some variable names. Fixes #14894 Closes #14972. PiperOrigin-RevId: 434589143 --- .../analysis/starlark/StarlarkTransition.java | 186 +++++++++++------- .../StarlarkAttrTransitionProviderTest.java | 136 +++++++++++++ 2 files changed, 250 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkTransition.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkTransition.java index 0cf754541bcfd0..7fffe2e7d215cf 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkTransition.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkTransition.java @@ -267,31 +267,39 @@ public static Map validate( Map buildSettingPackages, Map toOptions) throws TransitionException { - // Collect settings changed during this transition and their types. This includes settings that - // were only used as inputs as to the transition and thus had their default values added to the - // fromOptions, which in case of a no-op transition directly end up in toOptions. - Map changedSettingToRule = Maps.newHashMap(); + // Collect settings that are inputs or outputs of the transition together with their types. + // Output setting values will be validated and removed if set to their default. + Map inputAndOutputSettingsToRule = Maps.newHashMap(); + // Collect settings that were only used as inputs to the transition and thus possibly had their + // default values added to the fromOptions. They will be removed if set to ther default, but + // should not be validated. + Set