From ff233db58f4c646f1b307f85b300f8eac46c2740 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 7 Dec 2022 02:25:32 -0800 Subject: [PATCH] Always use target attributes to set Python version Fixes: https://github.com/bazelbuild/bazel/issues/16935 RELNOTES[INC]: This changes the behavior of Python version in exec/host configuration. Mitigation is to set Python version on the targets. PiperOrigin-RevId: 493545843 Change-Id: I3a4d787e7075d2b76835faf04d4c4e04c9de85b4 --- .../lib/rules/python/PythonVersionTransition.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonVersionTransition.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonVersionTransition.java index f980879ff20f13..79401ca954708c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonVersionTransition.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonVersionTransition.java @@ -21,7 +21,6 @@ import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.BuildOptionsCache; 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.events.EventHandler; @@ -69,17 +68,12 @@ private PythonVersionTransition() {} @Override public ImmutableSet> requiresOptionFragments() { - return ImmutableSet.of(PythonOptions.class, CoreOptions.class); + return ImmutableSet.of(PythonOptions.class); } @Override public BuildOptions patch(BuildOptionsView options, EventHandler eventHandler) { - // If this happens after exec transition, keep the same version (to reproduce and keep behaviour - // of the host transition, that happens after this one) - PythonVersion newVersion = - options.get(CoreOptions.class).isExec - ? options.get(PythonOptions.class).getPythonVersion() - : determineNewVersion(options); + PythonVersion newVersion = determineNewVersion(options); checkArgument(newVersion.isTargetValue(), newVersion); // PythonOptions aren't present after NoConfigTransition. That implies rules that don't read