[RFC,23/26] python3: refactor python-config patch

Message ID 7967250b8b7c22b80fa8cbe84a776ff28ea26b1a.1637900380.git.timothy.t.orling@intel.com
State New
Headers show
Series [RFC,01/26] classes/distutils-*: add warning of deprecation | expand

Commit Message

Tim Orling Nov. 26, 2021, 4:36 a.m. UTC
Drop legacy python-config.patch

distutils is deprecated in Python 3.10 and will be removed in Python
3.12 (~October 2023).

Rather than wholesale import the distutils.sysconfig module, refactor
to replicate legacy distutils usage that we need.

This merges changes to get_python_inc from 12-distutils-prefix-is-inside-staging-area.patch

[YOCTO #14610]

Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
---
 ...n-implement-legacy-disutils-behavior.patch | 68 +++++++++++++++++++
 .../python/python3/python-config.patch        | 55 ---------------
 .../recipes-devtools/python/python3_3.10.0.bb |  2 +-
 3 files changed, 69 insertions(+), 56 deletions(-)
 create mode 100644 meta/recipes-devtools/python/python3/0001-python-config.in-implement-legacy-disutils-behavior.patch
 delete mode 100644 meta/recipes-devtools/python/python3/python-config.patch

Patch

diff --git a/meta/recipes-devtools/python/python3/0001-python-config.in-implement-legacy-disutils-behavior.patch b/meta/recipes-devtools/python/python3/0001-python-config.in-implement-legacy-disutils-behavior.patch
new file mode 100644
index 00000000000..71fad65def0
--- /dev/null
+++ b/meta/recipes-devtools/python/python3/0001-python-config.in-implement-legacy-disutils-behavior.patch
@@ -0,0 +1,68 @@ 
+From 9bc5f12a31f1c90913bfa90f71ec12cea95de040 Mon Sep 17 00:00:00 2001
+From: Tim Orling <timothy.t.orling@intel.com>
+Date: Thu, 25 Nov 2021 17:48:23 -0800
+Subject: [PATCH] python-config.in: implement legacy disutils behavior
+
+The sysconfig behavior does not provide the correct paths for our usage,
+but rather than continue to use the deprecated distutils.sysconfig
+behavior, refactor the code paths we need to use supported standard
+library functionality.
+
+[YOCTO #14610]
+
+Upstream-Status: Inappropriate [oe-specific]
+
+Signed-off-by: Tim Orling <timothy.t.orling@intel.com>
+---
+ Misc/python-config.in | 31 +++++++++++++++++++++++++++----
+ 1 file changed, 27 insertions(+), 4 deletions(-)
+
+diff --git a/Misc/python-config.in b/Misc/python-config.in
+index ebd99daa0c..5959d74453 100644
+--- a/Misc/python-config.in
++++ b/Misc/python-config.in
+@@ -35,14 +35,37 @@ if '--help' in opt_flags:
+ 
+ for opt in opt_flags:
+     if opt == '--prefix':
+-        print(getvar('prefix'))
++	# borrow the legacy behavior of distutils.sysconfig.PREFIX
++        print(os.path.normpath(sys.prefix))
+ 
+     elif opt == '--exec-prefix':
+-        print(getvar('exec_prefix'))
++        # borrow the legacy behavior of distutils.sysconfig.EXEC_PREFIX
++        print(os.path.normpath(sys.exec_prefix))
+ 
+     elif opt in ('--includes', '--cflags'):
+-        flags = ['-I' + sysconfig.get_path('include'),
+-                 '-I' + sysconfig.get_path('platinclude')]
++        # borrowing the logic from legacy/deprecated distutils.sysconfig.get_python_inc
++
++        # Calculate the build qualifier flags if they are defined.  Adding the flags
++        # to the include and lib directories only makes sense for an installation, not
++        # an in-source build.
++        build_flags = ''
++        try:
++            if not sysconfig._PYTHON_BUILD:
++                build_flags = sys.abiflags
++        except AttributeError:
++            # It's not a configure-based build, so the sys module doesn't have
++            # this attribute, which is fine.
++            pass
++
++        incdir = os.path.join(sysconfig.get_config_var('srcdir'), 'Include')
++        if prefix is None and os.environ.get('STAGING_LIBDIR', "");
++            prefix = os.environ['STAGING_LIBDIR'].rstrip(lib_basename)
++        elif prefix is None:
++            prefix = sysconfig._BASE_EXEC_PREFIX or sysconfig._BASE_PREFIX
++        python_dir = 'python' + sysconfig.get_python_version() + build_flags
++        #platincdir = sysconfig._sys_home or sysconfig._PROJECT_BASE
++        flags = ['-I' + os.path.normpath(incdir),
++                 '-I' + os.path.join(prefix, "include", python_dir)]
+         if opt == '--cflags':
+             flags.extend(getvar('CFLAGS').split())
+         print(' '.join(flags))
+-- 
+2.30.2
+
diff --git a/meta/recipes-devtools/python/python3/python-config.patch b/meta/recipes-devtools/python/python3/python-config.patch
deleted file mode 100644
index c53f646af35..00000000000
--- a/meta/recipes-devtools/python/python3/python-config.patch
+++ /dev/null
@@ -1,55 +0,0 @@ 
-From 57d073c12e7bede29919117b0141df14015eb27f Mon Sep 17 00:00:00 2001
-From: Tyler Hall <tylerwhall@gmail.com>
-Date: Sun, 4 May 2014 20:06:43 -0400
-Subject: [PATCH] python-config: Revert to using distutils.sysconfig
-
-The newer sysconfig module shares some code with distutils.sysconfig, but the same modifications as in
-
-12-distutils-prefix-is-inside-staging-area.patch makes distutils.sysconfig
-
-affect the native runtime as well as cross building. Use the old, patched
-implementation which returns paths in the staging directory and for the target,
-as appropriate.
-
-Upstream-Status: Inappropriate [Embedded Specific]
-
-Signed-off-by: Tyler Hall <tylerwhall@gmail.com>
-
----
- Misc/python-config.in | 10 +++++-----
- 1 file changed, 5 insertions(+), 5 deletions(-)
-
-diff --git a/Misc/python-config.in b/Misc/python-config.in
-index ebd99da..13e57ae 100644
---- a/Misc/python-config.in
-+++ b/Misc/python-config.in
-@@ -6,7 +6,9 @@
- import getopt
- import os
- import sys
--import sysconfig
-+import warnings
-+warnings.filterwarnings("ignore", category=DeprecationWarning)
-+from distutils import sysconfig
- 
- valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
-               'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir',
-@@ -35,14 +35,14 @@ if '--help' in opt_flags:
- 
- for opt in opt_flags:
-     if opt == '--prefix':
--        print(getvar('prefix'))
-+        print(sysconfig.PREFIX)
- 
-     elif opt == '--exec-prefix':
--        print(getvar('exec_prefix'))
-+        print(sysconfig.EXEC_PREFIX)
- 
-     elif opt in ('--includes', '--cflags'):
--        flags = ['-I' + sysconfig.get_path('include'),
--                 '-I' + sysconfig.get_path('platinclude')]
-+        flags = ['-I' + sysconfig.get_python_inc(),
-+                 '-I' + sysconfig.get_python_inc(plat_specific=True)]
-         if opt == '--cflags':
-             flags.extend(getvar('CFLAGS').split())
-         print(' '.join(flags))
diff --git a/meta/recipes-devtools/python/python3_3.10.0.bb b/meta/recipes-devtools/python/python3_3.10.0.bb
index e3300b6495b..6b965af0509 100644
--- a/meta/recipes-devtools/python/python3_3.10.0.bb
+++ b/meta/recipes-devtools/python/python3_3.10.0.bb
@@ -17,7 +17,6 @@  SRC_URI = "http://www.python.org/ftp/python/${PV}/Python-${PV}.tar.xz \
            file://0001-Do-not-add-usr-lib-termcap-to-linker-flags-to-avoid-.patch \
            ${@bb.utils.contains('PACKAGECONFIG', 'tk', '', 'file://avoid_warning_about_tkinter.patch', d)} \
            file://0001-Do-not-use-the-shell-version-of-python-config-that-w.patch \
-           file://python-config.patch \
            file://0001-Makefile.pre-use-qemu-wrapper-when-gathering-profile.patch \
            file://0001-python3-use-cc_basename-to-replace-CC-for-checking-c.patch \
            file://0001-bpo-36852-proper-detection-of-mips-architecture-for-.patch \
@@ -33,6 +32,7 @@  SRC_URI = "http://www.python.org/ftp/python/${PV}/Python-${PV}.tar.xz \
            file://makerace.patch \
            file://0001-sysconfig.py-use-platlibdir-also-for-purelib.patch \
            file://0001-Lib-pty.py-handle-stdin-I-O-errors-same-way-as-maste.patch \
+           file://0001-python-config.in-implement-legacy-disutils-behavior.patch \
            "
 
 SRC_URI:append:class-native = " \