Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3: Update to 3.11.3, refresh/redo patches #21030

Merged
merged 8 commits into from
May 24, 2023

Conversation

jefferyto
Copy link
Member

@jefferyto jefferyto commented May 16, 2023

Maintainer: me
Compile tested: armvirt-32/armvirt-64/malta-be/x86-generic/x86-64, 2023-05-15 snapshot sdk
Run tested: armvirt-32/armvirt-64/malta-be/x86-generic/x86-64 (qemu), 2023-05-15 snapshot

Description:

  • python3: Remove --without-pymalloc

    --without-pymalloc was added in 7bf1ae6 because leaving it enabled added an "m" flag/suffix to file names.

    This flag/suffix was removed in Python 3.8, so disabling pymalloc is no longer necessary.

  • python3: Fix __pycache__ files included in python3-light

    003-do-not-run-distutils-tests.patch was removed in 4e05541. This patch stopped make install from, among other things, running compileall.

    When this patch was removed, make install ran compileall as normal and created bytecode files in __pycache__ directories. These files were then packaged in python3-light.

    This adds a patch to stop compileall from being run during make install.

    Fixes: 4e05541 ("python3: bump to version 3.10.0")

  • python3: Fix readelf program name not replaced in _sysconfigdata.py

    The Makefile lines to add READELF to TARGET_CONFIGURE_OPTS was removed in 4e05541.

    Without setting READELF, configure finds the symlink to $(TARGET_CROSS)readelf (e.g. arm-openwrt-linux-readelf) instead of $(TARGET_CROSS)readelf (e.g. arm-openwrt-linux-muslgnueabi-readelf).

    This leads to the symlink name being saved to _sysconfigdata.py, and so the readelf name is not replaced correctly (in Py3Package/python3-base/install).

    This restores the removed Makefile lines.

    Fixes: 4e05541 ("python3: bump to version 3.10.0")

  • python3: Fix race condition when doing parallel builds

    When doing parallel builds, host Python can install the python3 symlink before the Python standard library is installed completely.

    When this occurs, it is possible for other packages to detect the python3 symlink and try to use host Python before it is fully installed.

    This adds a patch to make commoninstall (where the standard library is installed) a prerequisite of bininstall (where the python3 symlink is installed), so that commoninstall is fully completed before bininstall begins.

    Patch has been submitted upstream: gh-104692: Include commoninstall as a prerequisite for bininstall python/cpython#104693

    Fixes: python3/host: build install race condition with uboot/scripts/dtc/pylibfdt #19241

  • python3: Fix multiarch/local paths added when building host Python

    By default, the Python build process will add /usr/local/{lib,include}, and multiarch paths (e.g. /usr/{lib,include}/x86_64-linux-gnu) if building on Debian/Ubuntu, to its library and includes paths.

    006-remove-multi-arch-and-local-paths.patch was added in 84202f1 to stop the Python build process from adding these paths.

    006-remove-multi-arch-and-local-paths.patch was removed in 48277ec.

    006-do-not-add-multiarch-paths-when-cross-compiling.patch was added in 0c8b0b0 to stop the Python build process from adding these paths for target Python.

    These paths are still added by the Python build process when building host Python.

    This replaces the cross-compiling-only patch with the original patch, renamed slightly and adapted for Python 3.10.

    Fixes: 48277ec ("python3: bump to version 3.8")

  • python3: Fix uuid module not compiled for host Python

    This adds $(STAGING_DIR_HOST)/include/e2fsprogs to HOST_CFLAGS and HOST_CPPFLAGS so that configure can find uuid/uuid.h.

  • python3: Fix hashlib module not compiled for host Python

    026-openssl-feature-flags.patch and 028-host-python-support-ssl-with-libressl.patch were removed in 4ecd9d6 to fix the ssl module after libressl was upgraded to 3.7.0.

    However, the cause of the ssl module build failure was only 028-host-python-support-ssl-with-libressl.patch.

    Removing 026-openssl-feature-flags.patch caused a build failure for the hashlib module.

    This restores 026-openssl-feature-flags.patch with an updated version of the patch from OpenBSD.

    Fixes: 4ecd9d6 ("python3: fix ssl support by removing libressl patches")

  • python3: Update to 3.11.3, refresh/redo patches

    • Removed patches:

      • 001-enable-zlib.patch: zlib module should be enabled automatically

      • 007-distutils-do-not-adjust-path.patch: Not necessary since we process shebang lines for all scripts (in python3-package.mk)

      • 030-bpo-43112-detect-musl-as-a-separate-SOABI-rust: select correct architecture for armv5 #24502.patch: Already merged

    • Move configure vars from config.site back into Makefile

      Centralizing all build information into one file makes it easier to maintain

    • No longer set ac_cv_header_uuid_h=yes as configure should detect libuuid

    • Order configure args by enable-/disable-/with-/without-, then alphabetically

    • Set ac_cv_working_openssl_hashlib=yes for host configure to bypass the OpenSSL API tests with LibreSSL

    • Use the default Host/Compile recipe instead of picking out specific targets to make

@jefferyto
Copy link
Member Author

Changes:

  • Added commit to fix readelf program name not replaced in _sysconfigdata.py
  • Updated commit message with note about removing ac_cv_header_uuid_h=yes

@jefferyto
Copy link
Member Author

Changes:

  • Use default Host/Compile
  • Rebased on master

@jefferyto jefferyto force-pushed the python-3.11.3 branch 2 times, most recently from bdbb8f9 to e1ac7eb Compare May 20, 2023 11:27
@jefferyto
Copy link
Member Author

Changes:

Just to add: fixes are in separate commits so that they can be cherry-picked into 22.03 when I do the python3 package update after this PR.

@jefferyto
Copy link
Member Author

Changes:

  • Updated commit message for "python3: Fix race condition when doing parallel builds" to mention that the patch has been submitted upstream

@BKPepe BKPepe requested a review from commodo May 21, 2023 14:18
@jefferyto
Copy link
Member Author

Marking this PR as draft as I think I need to fit in one more fix...

I believe there is a Python/libressl issue that is causing the hashlib module to not build for host Python (when building from full buildroot, not sdk), which is causing poetry-core to fail to build, causing the issue mentioned in #20994

@jefferyto jefferyto marked this pull request as draft May 22, 2023 09:46
@jefferyto
Copy link
Member Author

Changes:

  • Renamed patch in "python3: Fix race condition when doing parallel builds"
  • Added commit "python3: Fix hashlib module not compiled for host Python"
  • Added setting ac_cv_working_openssl_hashlib=yes in HOST_CONFIGURE_VARS (python3: Update to 3.11.3, refresh/redo patches) and added note for this change in commit message
  • Rebased on master

@jefferyto jefferyto force-pushed the python-3.11.3 branch 2 times, most recently from 30b90b7 to 2ac9736 Compare May 23, 2023 18:26
jefferyto added 8 commits May 24, 2023 02:28
--without-pymalloc was added in 7bf1ae6
because leaving it enabled added an "m" flag/suffix to file names.

This flag/suffix was removed in Python 3.8[1], so disabling pymalloc is
no longer necessary.

[1]: https://docs.python.org/3.8/whatsnew/3.8.html#build-and-c-api-changes

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
003-do-not-run-distutils-tests.patch was removed in
4e05541. This patch stopped "make
install" from, among other things, running compileall.

When this patch was removed, "make install" ran compileall as normal and
created bytecode files in __pycache__ directories. These files were then
packaged in python3-light.

This adds a patch to stop compileall from being run during "make
install".

Fixes: 4e05541 ("python3: bump to version 3.10.0")
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
The Makefile lines to add READELF to TARGET_CONFIGURE_OPTS was removed
in 4e05541.

Without setting READELF, configure finds the symlink to
$(TARGET_CROSS)readelf (e.g. arm-openwrt-linux-readelf) instead of
$(TARGET_CROSS)readelf (e.g. arm-openwrt-linux-muslgnueabi-readelf).

This leads to the symlink name being saved to _sysconfigdata.py, and so
the readelf name is not replaced correctly (in
Py3Package/python3-base/install).

This restores the removed Makefile lines.

Fixes: 4e05541 ("python3: bump to version 3.10.0")
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
When doing parallel builds, host Python can install the python3 symlink
before the Python standard library is installed completely.

When this occurs, it is possible for other packages to detect the
python3 symlink and try to use host Python before it is fully installed.

This adds a patch to make commoninstall (where the standard library is
installed) a prerequisite of bininstall (where the python3 symlink is
installed), so that commoninstall is fully completed before bininstall
begins.

Patch has been submitted upstream:
python/cpython#104693

Fixes: openwrt#19241

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
By default, the Python build process will add /usr/local/{lib,include},
and multiarch paths (e.g. /usr/{lib,include}/x86_64-linux-gnu) if
building on Debian/Ubuntu, to its library and includes paths.

006-remove-multi-arch-and-local-paths.patch was added in
84202f1 to stop the Python build
process from adding these paths.

006-remove-multi-arch-and-local-paths.patch was removed in
48277ec.

006-do-not-add-multiarch-paths-when-cross-compiling.patch was added in
0c8b0b0 to stop the Python build
process from adding these paths for target Python.

These paths are still added by the Python build process when building
host Python.

This replaces the cross-compiling-only patch with the original patch,
renamed slightly and adapted for Python 3.10.

Fixes: 48277ec ("python3: bump to version 3.8")
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
This adds $(STAGING_DIR_HOST)/include/e2fsprogs to HOST_CFLAGS and
HOST_CPPFLAGS so that configure can find uuid/uuid.h.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
026-openssl-feature-flags.patch and
028-host-python-support-ssl-with-libressl.patch were removed in
4ecd9d6 to fix the ssl module after
libressl was upgraded to 3.7.0[1].

However, the cause of the ssl module build failure was only
028-host-python-support-ssl-with-libressl.patch.

Removing 026-openssl-feature-flags.patch caused a build failure for the
hashlib module.

This restores 026-openssl-feature-flags.patch with an updated version of
the patch from OpenBSD[2].

[1]: openwrt#20107
[2]: https://github.com/openbsd/ports/blob/26a04435bf2a09dcbe22b718bfee08997617a906/lang/python/3.10/patches/patch-Modules__hashopenssl_c

Fixes: 4ecd9d6 ("python3: fix ssl support by removing libressl patches")
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
* Removed patches:

  * 001-enable-zlib.patch: zlib module should be enabled automatically

  * 007-distutils-do-not-adjust-path.patch: Not necessary since we
    process shebang lines for all scripts (in python3-package.mk)

  * 030-bpo-43112-detect-musl-as-a-separate-SOABI-openwrtGH-24502.patch:
    Already merged

* Move configure vars from config.site back into Makefile

  Centralizing all build information into one file makes it easier to
  maintain

* No longer set ac_cv_header_uuid_h=yes as configure should detect
  libuuid

* Order configure args by enable-/disable-/with-/without-, then
  alphabetically

* Set ac_cv_working_openssl_hashlib=yes for host configure to bypass the
  OpenSSL API tests with LibreSSL

* Use the default Host/Compile recipe instead of picking out specific
  targets to make

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
@jefferyto
Copy link
Member Author

Changes:

  • Added "python3: Fix multiarch/local paths added when building host Python"
  • Added "python3: Fix uuid module not compiled for host Python"
  • Rebased on master

@jefferyto jefferyto marked this pull request as ready for review May 23, 2023 18:35
@neheb neheb merged commit 2445fe9 into openwrt:master May 24, 2023
@1715173329
Copy link
Member

hmmm the poetry module still seems broken when compiling from source.

build log:

cd "/home/builder/oprk-master/build_dir/target-aarch64_generic_musl/pypi/dnspython-2.3.0" && CC="aarch64-openwrt-linux-musl-gcc" CCSHARED="aarch64-openwrt-linux-musl-gcc -DPIC -fPIC" CXX="aarch64-openwrt-linux-musl-g++" LD="aarch64-openwrt-linux-musl-gcc" LDSHARED="aarch64-openwrt-linux-musl-gcc -shared" CFLAGS="-Os -pipe -mcpu=generic -fno-caller-saves -fno-plt -fhonour-copts -fmacro-prefix-map=/home/builder/oprk-master/build_dir/target-aarch64_generic_musl/pypi/dnspython-2.3.0=dnspython-2.3.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" CPPFLAGS="-I/home/builder/oprk-master/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/usr/include -I/home/builder/oprk-master/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/include/fortify -I/home/builder/oprk-master/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/include -I/home/builder/oprk-master/staging_dir/target-aarch64_generic_musl/usr/include/python3.11" LDFLAGS="-L/home/builder/oprk-master/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/usr/lib -L/home/builder/oprk-master/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/lib -znow -zrelro -lpython3.11" _PYTHON_HOST_PLATFORM="linux-aarch64" PYTHONPATH="/home/builder/oprk-master/staging_dir/target-aarch64_generic_musl/usr/lib/python3.11:/home/builder/oprk-master/staging_dir/target-aarch64_generic_musl//usr/lib/python3.11/site-packages:/home/builder/oprk-master/build_dir/target-aarch64_generic_musl/pypi/dnspython-2.3.0/ipkg-install//usr/lib/python3.11/site-packages" PYTHONDONTWRITEBYTECODE=1 _python_sysroot="/home/builder/oprk-master/staging_dir/target-aarch64_generic_musl" _python_prefix="/usr" _python_exec_prefix="/usr"    /home/builder/oprk-master/staging_dir/hostpkg/bin/python3.11  -m build --no-isolation --outdir "/home/builder/oprk-master/build_dir/target-aarch64_generic_musl/pypi/dnspython-2.3.0/"/openwrt-build --wheel   "/home/builder/oprk-master/build_dir/target-aarch64_generic_musl/pypi/dnspython-2.3.0/" 
* Getting build dependencies for wheel...

Traceback (most recent call last):
  File "/home/builder/oprk-master/staging_dir/hostpkg/lib/python3.11/site-packages/pyproject_hooks/_impl.py", line 321, in _call_hook
    raise BackendUnavailable(data.get('traceback', ''))
pyproject_hooks._impl.BackendUnavailable: Traceback (most recent call last):
  File "/home/builder/oprk-master/staging_dir/hostpkg/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
    obj = import_module(mod_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/builder/oprk-master/staging_dir/target-aarch64_generic_musl/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'poetry'

ERROR Backend 'poetry.core.masonry.api' is not available.
make[2]: *** [Makefile:45: /home/builder/oprk-master/build_dir/target-aarch64_generic_musl/pypi/dnspython-2.3.0/.built] Error 1
make[2]: Leaving directory '/home/builder/oprk-master/feeds/packages/lang/python/python-dns'
time: package/feeds/packages/python-dns/compile#0.38#0.05#1.31
    ERROR: package/feeds/packages/python-dns failed to build.
make[1]: *** [package/Makefile:120: package/feeds/packages/python-dns/compile] Error 1
make[1]: Leaving directory '/home/builder/oprk-master'
make: *** [/home/builder/oprk-master/include/toplevel.mk:231: package/python-dns/compile] Error 2

base rev: 1c074ac
packages rev: 574d43f
config:

CONFIG_TARGET_rockchip=y
CONFIG_TARGET_rockchip_armv8=y
CONFIG_TARGET_rockchip_armv8_DEVICE_friendlyarm_nanopi-r2s=y
CONFIG_LINUX_6_1=y
CONFIG_OPENSSL_ENGINE=y
CONFIG_OPENSSL_WITH_ASM=y
CONFIG_OPENSSL_WITH_CHACHA_POLY1305=y
CONFIG_OPENSSL_WITH_CMS=y
CONFIG_OPENSSL_WITH_DEPRECATED=y
CONFIG_OPENSSL_WITH_ERROR_MESSAGES=y
CONFIG_OPENSSL_WITH_IDEA=y
CONFIG_OPENSSL_WITH_MDC2=y
CONFIG_OPENSSL_WITH_PSK=y
CONFIG_OPENSSL_WITH_SEED=y
CONFIG_OPENSSL_WITH_SRP=y
CONFIG_OPENSSL_WITH_TLS13=y
CONFIG_OPENSSL_WITH_WHIRLPOOL=y
CONFIG_PACKAGE_libbz2=y
CONFIG_PACKAGE_libffi=y
CONFIG_PACKAGE_libgdbm=y
CONFIG_PACKAGE_liblzma=y
CONFIG_PACKAGE_libncurses=y
CONFIG_PACKAGE_libopenssl=y
CONFIG_PACKAGE_libpython3=y
CONFIG_PACKAGE_libreadline=y
CONFIG_PACKAGE_libsqlite3=y
CONFIG_PACKAGE_python3=y
CONFIG_PACKAGE_python3-asyncio=y
CONFIG_PACKAGE_python3-base=y
CONFIG_PACKAGE_python3-cgi=y
CONFIG_PACKAGE_python3-cgitb=y
CONFIG_PACKAGE_python3-codecs=y
CONFIG_PACKAGE_python3-ctypes=y
CONFIG_PACKAGE_python3-dbm=y
CONFIG_PACKAGE_python3-decimal=y
CONFIG_PACKAGE_python3-distutils=y
CONFIG_PACKAGE_python3-dns=y
CONFIG_PACKAGE_python3-email=y
CONFIG_PACKAGE_python3-light=y
CONFIG_PACKAGE_python3-logging=y
CONFIG_PACKAGE_python3-lzma=y
CONFIG_PACKAGE_python3-multiprocessing=y
CONFIG_PACKAGE_python3-ncurses=y
CONFIG_PACKAGE_python3-openssl=y
CONFIG_PACKAGE_python3-pydoc=y
CONFIG_PACKAGE_python3-readline=y
CONFIG_PACKAGE_python3-sqlite3=y
CONFIG_PACKAGE_python3-unittest=y
CONFIG_PACKAGE_python3-urllib=y
CONFIG_PACKAGE_python3-uuid=y
CONFIG_PACKAGE_python3-xml=y
CONFIG_PACKAGE_terminfo=y
CONFIG_PACKAGE_zlib=y
CONFIG_SQLITE3_COLUMN_METADATA=y
CONFIG_SQLITE3_DYNAMIC_EXTENSIONS=y
CONFIG_SQLITE3_FTS3=y
CONFIG_SQLITE3_FTS4=y
CONFIG_SQLITE3_FTS5=y
CONFIG_SQLITE3_RTREE=y
CONFIG_TESTING_KERNEL=y

@jefferyto
Copy link
Member Author

hmmm the poetry module still seems broken when compiling from source.

Yes the fix is openwrt/openwrt#12710. I have also sent it to the mailing list now: https://patchwork.ozlabs.org/project/openwrt/patch/20230531135834.2150795-1-jeffery.to@gmail.com/

If it's still not merged in a week or so I'll do a special case fix for Python packages, but this is really a general issue.

@1715173329
Copy link
Member

Thank you for the fix! And sorry I asked a stupid question (didn't check the existing issues first...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

python3/host: build install race condition with uboot/scripts/dtc/pylibfdt
4 participants