From 3ebca6e9d27d043003cc8e627f35ca59018d335e Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sat, 5 Mar 2022 18:56:45 +0100 Subject: [PATCH] Do not validate input-only settings in transitions 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. --- .../analysis/starlark/StarlarkTransition.java | 169 ++++++++++-------- .../StarlarkAttrTransitionProviderTest.java | 57 ++++++ 2 files changed, 154 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 64a0de883867a6..cc82a0adbb71d1 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,38 @@ 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 input or outputs of the transition together with their types. + // Output setting values will be validated and cleaned if set to the default. + Map inputAndOutputSettingsToRule = Maps.newHashMap(); + // Collect settings that were only used as inputs to the transition and thus had their default + // values added to the fromOptions. They always have to be cleaned. + Set