Skip to content

Commit c28faca

Browse files
committed
Add patch to distlib to disable simple shebangs on cross compiles.
1 parent 5d567de commit c28faca

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/pip/_vendor/distlib/scripts.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ def _build_shebang(self, executable, post_interp):
164164
"""
165165
if os.name != 'posix':
166166
simple_shebang = True
167+
elif getattr(sys, "cross_compiling", False):
168+
# In a cross-compiling environment, the shebang will likely be a
169+
# script; this *must* be invoked with the "safe" version of the
170+
# shebang, or else using os.exec() to run the entry script will
171+
# fail, raising "OSError 8 [Errno 8] Exec format error".
172+
simple_shebang = False
167173
else:
168174
# Add 3 for '#!' prefix and newline suffix.
169175
shebang_length = len(executable) + len(post_interp) + 3

tools/vendoring/patches/distlib.patch

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ index cfa45d2af..e16292b83 100644
55
@@ -49,6 +49,24 @@ if __name__ == '__main__':
66
sys.exit(%(func)s())
77
'''
8-
8+
99
+# Pre-fetch the contents of all executable wrapper stubs.
1010
+# This is to address https://github.com/pypa/pip/issues/12666.
1111
+# When updating pip, we rename the old pip in place before installing the
@@ -24,9 +24,22 @@ index cfa45d2af..e16292b83 100644
2424
+ if r.name.endswith(".exe")
2525
+}
2626
+
27-
27+
2828
def enquote_executable(executable):
2929
if ' ' in executable:
30+
@@ -164,6 +164,12 @@ class ScriptMaker(object):
31+
"""
32+
if os.name != 'posix':
33+
simple_shebang = True
34+
+ elif getattr(sys, "cross_compiling", False):
35+
+ # In a cross-compiling environment, the shebang will likely be a
36+
+ # script; this *must* be invoked with the "safe" version of the
37+
+ # shebang, or else using os.exec() to run the entry script will
38+
+ # fail, raising "OSError 8 [Errno 8] Exec format error".
39+
+ simple_shebang = False
40+
else:
41+
# Add 3 for '#!' prefix and newline suffix.
42+
shebang_length = len(executable) + len(post_interp) + 3
3043
@@ -409,15 +427,11 @@ class ScriptMaker(object):
3144
bits = '32'
3245
platform_suffix = '-arm' if get_platform() == 'win-arm64' else ''
@@ -42,6 +55,6 @@ index cfa45d2af..e16292b83 100644
4255
raise ValueError(msg)
4356
- return resource.bytes
4457
+ return WRAPPERS[name]
45-
58+
4659
# Public API follows
47-
60+

0 commit comments

Comments
 (0)