From edc4c505f9cad536b527a5f26852f6844df3c05e Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Fri, 9 Sep 2022 19:39:25 -0700 Subject: [PATCH] Make using python 2 an error Except if BUILD_BROKEN_USES_SOONG_PYTHON2_MODULES is set, and except for some core py2 modules that can't be removed until python2 is fully gone. Bug: 203436762 Test: m nothing Change-Id: I62ccb6f5687eab1e79c372ffc234a90ca5b566ac --- android/config.go | 4 ++++ android/variable.go | 1 + python/python.go | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/android/config.go b/android/config.go index b37d5c827..b84810f90 100644 --- a/android/config.go +++ b/android/config.go @@ -1759,6 +1759,10 @@ func (c *deviceConfig) BuildBrokenTrebleSyspropNeverallow() bool { return c.config.productVariables.BuildBrokenTrebleSyspropNeverallow } +func (c *deviceConfig) BuildBrokenUsesSoongPython2Modules() bool { + return c.config.productVariables.BuildBrokenUsesSoongPython2Modules +} + func (c *deviceConfig) BuildDebugfsRestrictionsEnabled() bool { return c.config.productVariables.BuildDebugfsRestrictionsEnabled } diff --git a/android/variable.go b/android/variable.go index 1b5d5586e..8c5c0bc03 100644 --- a/android/variable.go +++ b/android/variable.go @@ -442,6 +442,7 @@ type productVariables struct { BuildBrokenDepfile *bool `json:",omitempty"` BuildBrokenEnforceSyspropOwner bool `json:",omitempty"` BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"` + BuildBrokenUsesSoongPython2Modules bool `json:",omitempty"` BuildBrokenVendorPropertyNamespace bool `json:",omitempty"` BuildBrokenInputDirModules []string `json:",omitempty"` diff --git a/python/python.go b/python/python.go index 0ae7b3691..c7c523dfb 100644 --- a/python/python.go +++ b/python/python.go @@ -263,6 +263,12 @@ func versionSplitMutator() func(android.BottomUpMutatorContext) { versionProps = append(versionProps, props.Version.Py3) } if proptools.BoolDefault(props.Version.Py2.Enabled, false) { + if !mctx.DeviceConfig().BuildBrokenUsesSoongPython2Modules() && + mctx.ModuleName() != "par_test" && + mctx.ModuleName() != "py2-cmd" && + mctx.ModuleName() != "py2-stdlib" { + mctx.PropertyErrorf("version.py2.enabled", "Python 2 is no longer supported, please convert to python 3. This error can be temporarily overridden by setting BUILD_BROKEN_USES_SOONG_PYTHON2_MODULES := true in the product configuration") + } versionNames = append(versionNames, pyVersion2) versionProps = append(versionProps, props.Version.Py2) }