From b2efc6c904d4f7e49c4c24a6e064b5a949844663 Mon Sep 17 00:00:00 2001 From: Max Khon Date: Sat, 5 Feb 2022 05:24:53 +0700 Subject: [PATCH] [python3] Bootstrap pip with ${CURRENT_INSTALLED_DIR} --- ports/python3/0010-ensurepip.patch | 10 ++++++++++ ports/python3/portfile.cmake | 18 +++++++++++++++--- ports/python3/vcpkg.json | 2 +- versions/baseline.json | 2 +- versions/p-/python3.json | 5 +++++ 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 ports/python3/0010-ensurepip.patch diff --git a/ports/python3/0010-ensurepip.patch b/ports/python3/0010-ensurepip.patch new file mode 100644 index 00000000000000..45f137d4ca8f2e --- /dev/null +++ b/ports/python3/0010-ensurepip.patch @@ -0,0 +1,10 @@ +--- a/Lib/ensurepip/__init__.py 2021-10-05 00:40:46.000000000 +0700 ++++ b/Lib/ensurepip/__init__.py 2022-01-11 15:22:54.001498300 +0700 +@@ -86,6 +86,7 @@ + code = f""" + import runpy + import sys ++sys.executable = @sys_executable@ + sys.path = {additional_paths or []} + sys.path + sys.argv[1:] = {args} + runpy.run_module("pip", run_name="__main__", alter_sys=True) diff --git a/ports/python3/portfile.cmake b/ports/python3/portfile.cmake index d99a0fd673bf55..62b653590b7512 100644 --- a/ports/python3/portfile.cmake +++ b/ports/python3/portfile.cmake @@ -29,12 +29,23 @@ elseif(VCPKG_TARGET_IS_WINDOWS AND CMAKE_SYSTEM_VERSION EQUAL 6.1) message(FATAL_ERROR "python3 requires the feature deprecated-win7-support when building on Windows 7.") endif() -# The Windows 11 SDK has a problem that causes it to error on the resource files, so we patch that. if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP) + string(COMPARE EQUAL ${VCPKG_LIBRARY_LINKAGE} "dynamic" PYTHON_ALLOW_EXTENSIONS) + if(PYTHON_ALLOW_EXTENSIONS AND (NOT VCPKG_CROSSCOMPILING OR TARGET_TRIPLET MATCHES "^${HOST_TRIPLET}-")) + set(PYTHON_ENSUREPIP TRUE) + else() + set(PYTHON_ENSUREPIP FALSE) + endif() + + # The Windows 11 SDK has a problem that causes it to error on the resource files, so we patch that. vcpkg_get_windows_sdk(WINSDK_VERSION) if("${WINSDK_VERSION}" VERSION_GREATER_EQUAL "10.0.22000") list(APPEND PATCHES "0007-workaround-windows-11-sdk-rc-compiler-error.patch") endif() + + if(PYTHON_ENSUREPIP) + list(APPEND PATCHES "0010-ensurepip.patch") + endif() endif() vcpkg_from_github( @@ -70,7 +81,6 @@ endfunction() if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP) # Due to the way Python handles C extension modules on Windows, a static python core cannot # load extension modules. - string(COMPARE EQUAL ${VCPKG_LIBRARY_LINKAGE} "dynamic" PYTHON_ALLOW_EXTENSIONS) if(PYTHON_ALLOW_EXTENSIONS) find_library(BZ2_RELEASE NAMES bz2 PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH) find_library(BZ2_DEBUG NAMES bz2d PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH) @@ -172,8 +182,10 @@ if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP) file(REMOVE ${PYTHON_LIBS} ${PYTHON_INSTALLERS}) # The generated python executable must match the host arch - if(PYTHON_ALLOW_EXTENSIONS AND NOT VCPKG_CROSSCOMPILING) + if(PYTHON_ENSUREPIP) message(STATUS "Bootstrapping pip") + set(sys_executable "'${CURRENT_INSTALLED_DIR}/tools/${PORT}/python.exe'") + configure_file("${SOURCE_PATH}/Lib/ensurepip/__init__.py" "${CURRENT_PACKAGES_DIR}/tools/${PORT}/Lib/ensurepip/__init__.py" @ONLY) vcpkg_execute_required_process(COMMAND python -m ensurepip WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}" LOGNAME "ensurepip-${TARGET_TRIPLET}" diff --git a/ports/python3/vcpkg.json b/ports/python3/vcpkg.json index 1a2ec9110034a3..21ee84f93dc8bd 100644 --- a/ports/python3/vcpkg.json +++ b/ports/python3/vcpkg.json @@ -1,7 +1,7 @@ { "name": "python3", "version": "3.10.2", - "port-version": 1, + "port-version": 2, "description": "The Python programming language", "homepage": "https://github.com/python/cpython", "license": "Python-2.0", diff --git a/versions/baseline.json b/versions/baseline.json index 5b621212ce182d..9d1aaba63747e8 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5634,7 +5634,7 @@ }, "python3": { "baseline": "3.10.2", - "port-version": 1 + "port-version": 2 }, "qca": { "baseline": "2.3.4", diff --git a/versions/p-/python3.json b/versions/p-/python3.json index a89a02eb10de82..b9cf63eb25d4c2 100644 --- a/versions/p-/python3.json +++ b/versions/p-/python3.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "89ec84c1f5e3e62bcfac0642b77ac4bf610af1b9", + "version": "3.10.2", + "port-version": 2 + }, { "git-tree": "4e348bd50d8c4252bda83903ce22f1e60d34be88", "version": "3.10.2",