@@ -20,8 +20,74 @@ export LLVM_PROFDATA=${TOOLS_PATH}/${TOOLCHAIN}/bin/llvm-profdata
20
20
find ${TOOLS_PATH} /deps -name ' *.so*' -exec rm {} \;
21
21
22
22
tar -xf Python-${PYTHON_VERSION} .tar.xz
23
- tar -xf setuptools-${SETUPTOOLS_VERSION} .tar.gz
24
- tar -xf pip-${PIP_VERSION} .tar.gz
23
+
24
+ PIP_WHEEL=" ${ROOT} /pip-${PIP_VERSION} -py3-none-any.whl"
25
+ SETUPTOOLS_WHEEL=" ${ROOT} /setuptools-${SETUPTOOLS_VERSION} -py3-none-any.whl"
26
+
27
+ chmod 644 " ${PIP_WHEEL} "
28
+ chmod 644 " ${SETUPTOOLS_WHEEL} "
29
+
30
+ # pip and setuptools don't properly handle the case where the current executable
31
+ # isn't dynamic. This is tracked by https://github.com/pypa/pip/issues/6543.
32
+ # We need to patch both.
33
+ #
34
+ # Ideally we'd do this later in the build. However, since we use the pip
35
+ # wheel to bootstrap itself, we need to patch the wheel before it is used.
36
+ #
37
+ # Wheels are zip files. So we simply unzip, patch, and rezip.
38
+ mkdir pip-tmp
39
+ pushd pip-tmp
40
+ unzip " ${PIP_WHEEL} "
41
+
42
+ patch -p1 << EOF
43
+ diff --git a/pip/_internal/utils/glibc.py b/pip/_internal/utils/glibc.py
44
+ index 819979d80..4ae91e364 100644
45
+ --- a/pip/_internal/utils/glibc.py
46
+ +++ b/pip/_internal/utils/glibc.py
47
+ @@ -47,7 +47,10 @@ def glibc_version_string_ctypes():
48
+ # manpage says, "If filename is NULL, then the returned handle is for the
49
+ # main program". This way we can let the linker do the work to figure out
50
+ # which libc our process is actually using.
51
+ - process_namespace = ctypes.CDLL(None)
52
+ + try:
53
+ + process_namespace = ctypes.CDLL(None)
54
+ + except OSError:
55
+ + return None
56
+ try:
57
+ gnu_get_libc_version = process_namespace.gnu_get_libc_version
58
+ except AttributeError:
59
+ EOF
60
+
61
+ zip -r " ${PIP_WHEEL} " *
62
+ popd
63
+ rm -rf pip-tmp
64
+
65
+ mkdir setuptools-tmp
66
+ pushd setuptools-tmp
67
+ unzip " ${SETUPTOOLS_WHEEL} "
68
+
69
+ patch -p1 << EOF
70
+ diff --git a/setuptools/_vendor/packaging/tags.py b/setuptools/_vendor/packaging/tags.py
71
+ index 9064910b..c541e648 100644
72
+ --- a/setuptools/_vendor/packaging/tags.py
73
+ +++ b/setuptools/_vendor/packaging/tags.py
74
+ @@ -475,7 +475,10 @@ def _glibc_version_string_ctypes():
75
+ # which libc our process is actually using.
76
+ #
77
+ # Note: typeshed is wrong here so we are ignoring this line.
78
+ - process_namespace = ctypes.CDLL(None) # type: ignore
79
+ + try:
80
+ + process_namespace = ctypes.CDLL(None) # type: ignore
81
+ + except OSError:
82
+ + return None
83
+ try:
84
+ gnu_get_libc_version = process_namespace.gnu_get_libc_version
85
+ except AttributeError:
86
+ EOF
87
+
88
+ zip -r " ${SETUPTOOLS_WHEEL} " *
89
+ popd
90
+ rm -rf setuptools-tmp
25
91
26
92
# If we are cross-compiling, we need to build a host Python to use during
27
93
# the build.
@@ -50,7 +116,9 @@ if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
50
116
;;
51
117
esac
52
118
53
- CC=" ${HOST_CC} " CFLAGS=" ${EXTRA_HOST_CFLAGS} " CPPFLAGS=" ${EXTRA_HOST_CFLAGS} " LDFLAGS=" ${EXTRA_HOST_LDFLAGS} " ./configure --prefix " ${TOOLS_PATH} /pyhost"
119
+ CC=" ${HOST_CC} " CFLAGS=" ${EXTRA_HOST_CFLAGS} " CPPFLAGS=" ${EXTRA_HOST_CFLAGS} " LDFLAGS=" ${EXTRA_HOST_LDFLAGS} " ./configure \
120
+ --prefix " ${TOOLS_PATH} /pyhost" \
121
+ --without-ensurepip
54
122
55
123
make -j " ${NUM_CPUS} " install
56
124
@@ -770,63 +838,17 @@ if [ "${PYBUILD_SHARED}" = "1" ]; then
770
838
fi
771
839
fi
772
840
773
- # Install pip so we can patch it to work with non-dynamic executables
774
- # and work around https://github.com/pypa/pip/issues/6543. But pip's bundled
775
- # setuptools has the same bug! So we need to install a patched version.
776
- pushd ${ROOT} /setuptools-${SETUPTOOLS_VERSION}
777
- patch -p1 << EOF
778
- diff --git a/setuptools/_vendor/packaging/tags.py b/setuptools/_vendor/packaging/tags.py
779
- index 9064910b..c541e648 100644
780
- --- a/setuptools/_vendor/packaging/tags.py
781
- +++ b/setuptools/_vendor/packaging/tags.py
782
- @@ -475,7 +475,10 @@ def _glibc_version_string_ctypes():
783
- # which libc our process is actually using.
784
- #
785
- # Note: typeshed is wrong here so we are ignoring this line.
786
- - process_namespace = ctypes.CDLL(None) # type: ignore
787
- + try:
788
- + process_namespace = ctypes.CDLL(None) # type: ignore
789
- + except OSError:
790
- + return None
791
- try:
792
- gnu_get_libc_version = process_namespace.gnu_get_libc_version
793
- except AttributeError:
794
- EOF
795
-
796
- ${BUILD_PYTHON} setup.py install
797
- popd
798
-
799
- pushd ${ROOT} /pip-${PIP_VERSION}
800
-
801
- # pip 21 shipped DOS line endings. https://github.com/pypa/pip/issues/9638.
802
- # Let's fix that.
803
- if [ " ${PYBUILD_PLATFORM} " = " macos" ]; then
804
- find . -name ' *.py' -exec perl -i -pe ' s/\r\n$/\n/g' {} \;
805
- else
806
- find . -name ' *.py' -exec sed -i ' s/\r$//g' {} \;
807
- fi
808
-
809
- patch -p1 << EOF
810
- diff --git a/src/pip/_internal/utils/glibc.py b/src/pip/_internal/utils/glibc.py
811
- index 819979d80..4ae91e364 100644
812
- --- a/src/pip/_internal/utils/glibc.py
813
- +++ b/src/pip/_internal/utils/glibc.py
814
- @@ -47,7 +47,10 @@ def glibc_version_string_ctypes():
815
- # manpage says, "If filename is NULL, then the returned handle is for the
816
- # main program". This way we can let the linker do the work to figure out
817
- # which libc our process is actually using.
818
- - process_namespace = ctypes.CDLL(None)
819
- + try:
820
- + process_namespace = ctypes.CDLL(None)
821
- + except OSError:
822
- + return None
823
- try:
824
- gnu_get_libc_version = process_namespace.gnu_get_libc_version
825
- except AttributeError:
826
- EOF
841
+ # Install setuptools and pip as they are common tools that should be in any
842
+ # Python distribution.
843
+ #
844
+ # We disabled ensurepip because we insist on providing our own pip and don't
845
+ # want the final product to possibly be contaminated by another version.
846
+ #
847
+ # It is possible for the Python interpreter to run wheels directly. So we
848
+ # simply use our pip to install self. Kinda crazy, but it works!
827
849
828
- ${BUILD_PYTHON} setup.py install
829
- popd
850
+ ${BUILD_PYTHON} " ${PIP_WHEEL} /pip " install --prefix= " ${ROOT} /out/python/install " --no-cache-dir --no-index " ${PIP_WHEEL} "
851
+ ${BUILD_PYTHON} " ${PIP_WHEEL} /pip " install --prefix= " ${ROOT} /out/python/install " --no-cache-dir --no-index " ${SETUPTOOLS_WHEEL} "
830
852
831
853
# Emit metadata to be used in PYTHON.json.
832
854
cat > ${ROOT} /generate_metadata.py << EOF
0 commit comments