Skip to content

Commit

Permalink
Add patch to distlib to disable simple shebangs on cross compiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Sep 25, 2024
1 parent 5d567de commit c28faca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/pip/_vendor/distlib/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ def _build_shebang(self, executable, post_interp):
"""
if os.name != 'posix':
simple_shebang = True
elif getattr(sys, "cross_compiling", False):
# In a cross-compiling environment, the shebang will likely be a
# script; this *must* be invoked with the "safe" version of the
# shebang, or else using os.exec() to run the entry script will
# fail, raising "OSError 8 [Errno 8] Exec format error".
simple_shebang = False
else:
# Add 3 for '#!' prefix and newline suffix.
shebang_length = len(executable) + len(post_interp) + 3
Expand Down
21 changes: 17 additions & 4 deletions tools/vendoring/patches/distlib.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ index cfa45d2af..e16292b83 100644
@@ -49,6 +49,24 @@ if __name__ == '__main__':
sys.exit(%(func)s())
'''

+# Pre-fetch the contents of all executable wrapper stubs.
+# This is to address https://github.com/pypa/pip/issues/12666.
+# When updating pip, we rename the old pip in place before installing the
Expand All @@ -24,9 +24,22 @@ index cfa45d2af..e16292b83 100644
+ if r.name.endswith(".exe")
+}
+

def enquote_executable(executable):
if ' ' in executable:
@@ -164,6 +164,12 @@ class ScriptMaker(object):
"""
if os.name != 'posix':
simple_shebang = True
+ elif getattr(sys, "cross_compiling", False):
+ # In a cross-compiling environment, the shebang will likely be a
+ # script; this *must* be invoked with the "safe" version of the
+ # shebang, or else using os.exec() to run the entry script will
+ # fail, raising "OSError 8 [Errno 8] Exec format error".
+ simple_shebang = False
else:
# Add 3 for '#!' prefix and newline suffix.
shebang_length = len(executable) + len(post_interp) + 3
@@ -409,15 +427,11 @@ class ScriptMaker(object):
bits = '32'
platform_suffix = '-arm' if get_platform() == 'win-arm64' else ''
Expand All @@ -42,6 +55,6 @@ index cfa45d2af..e16292b83 100644
raise ValueError(msg)
- return resource.bytes
+ return WRAPPERS[name]

# Public API follows

0 comments on commit c28faca

Please sign in to comment.