diff --git a/src/pip/_vendor/distlib/scripts.py b/src/pip/_vendor/distlib/scripts.py index e16292b8330..0982e6b726e 100644 --- a/src/pip/_vendor/distlib/scripts.py +++ b/src/pip/_vendor/distlib/scripts.py @@ -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 diff --git a/tools/vendoring/patches/distlib.patch b/tools/vendoring/patches/distlib.patch index de2834710a3..f8a066bf699 100644 --- a/tools/vendoring/patches/distlib.patch +++ b/tools/vendoring/patches/distlib.patch @@ -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 @@ -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 '' @@ -42,6 +55,6 @@ index cfa45d2af..e16292b83 100644 raise ValueError(msg) - return resource.bytes + return WRAPPERS[name] - + # Public API follows - +