From 37d39a2554063e50ee124d80c9a24b6866c743e0 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 at their literal default values are removed from the post-transition BuildOptions without going through 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 | 179 +++++++++++------- .../StarlarkAttrTransitionProviderTest.java | 132 +++++++++++++ 2 files changed, 239 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..9f1518591f2896 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