xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-devtools/python/python3-installer/interpreter.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunLet us override the hashbang directly (possibly upstreamable), and don't
2*4882a593Smuzhiyunplay games with hashbangs: for now assume that even hashbangs with spaces
3*4882a593Smuzhiyunare simple (assume the spaces are only used to separate arguments) and
4*4882a593Smuzhiyunwe don't have long hashbangs.
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunUpstream-Status: Inappropriate
7*4882a593SmuzhiyunSigned-off-by: Ross Burton <ross.burton@arm.com>
8*4882a593Smuzhiyun
9*4882a593Smuzhiyundiff --git a/src/installer/__main__.py b/src/installer/__main__.py
10*4882a593Smuzhiyunindex 3357ec5..d2fd8d2 100644
11*4882a593Smuzhiyun--- a/src/installer/__main__.py
12*4882a593Smuzhiyun+++ b/src/installer/__main__.py
13*4882a593Smuzhiyun@@ -23,6 +23,13 @@ def _get_main_parser() -> argparse.ArgumentParser:
14*4882a593Smuzhiyun         type=str,
15*4882a593Smuzhiyun         help="destination directory (prefix to prepend to each file)",
16*4882a593Smuzhiyun     )
17*4882a593Smuzhiyun+    parser.add_argument(
18*4882a593Smuzhiyun+        "--interpreter",
19*4882a593Smuzhiyun+        "-i",
20*4882a593Smuzhiyun+        type=str,
21*4882a593Smuzhiyun+        default=sys.executable,
22*4882a593Smuzhiyun+        help=f"interpreter (defaults to {sys.executable})",
23*4882a593Smuzhiyun+    )
24*4882a593Smuzhiyun     parser.add_argument(
25*4882a593Smuzhiyun         "--compile-bytecode",
26*4882a593Smuzhiyun         action="append",
27*4882a593Smuzhiyun@@ -73,7 +80,7 @@ def _main(cli_args: Sequence[str], program: Optional[str] = None) -> None:
28*4882a593Smuzhiyun     with WheelFile.open(args.wheel) as source:
29*4882a593Smuzhiyun         destination = SchemeDictionaryDestination(
30*4882a593Smuzhiyun             scheme_dict=_get_scheme_dict(source.distribution),
31*4882a593Smuzhiyun-            interpreter=sys.executable,
32*4882a593Smuzhiyun+            interpreter=args.interpreter,
33*4882a593Smuzhiyun             script_kind=get_launcher_kind(),
34*4882a593Smuzhiyun             bytecode_optimization_levels=bytecode_levels,
35*4882a593Smuzhiyun             destdir=args.destdir,
36*4882a593Smuzhiyundiff --git a/src/installer/scripts.py b/src/installer/scripts.py
37*4882a593Smuzhiyunindex 7e3c8fc..ba6ed5a 100644
38*4882a593Smuzhiyun--- a/src/installer/scripts.py
39*4882a593Smuzhiyun+++ b/src/installer/scripts.py
40*4882a593Smuzhiyun@@ -59,20 +59,7 @@ def _build_shebang(executable: str, forlauncher: bool) -> bytes:
41*4882a593Smuzhiyun     https://bitbucket.org/pypa/distlib/src/58cd5c6/distlib/scripts.py#lines-124
42*4882a593Smuzhiyun     """
43*4882a593Smuzhiyun     executable_bytes = executable.encode("utf-8")
44*4882a593Smuzhiyun-    if forlauncher:  # The launcher can just use the command as-is.
45*4882a593Smuzhiyun-        return b"#!" + executable_bytes
46*4882a593Smuzhiyun-    if _is_executable_simple(executable_bytes):
47*4882a593Smuzhiyun-        return b"#!" + executable_bytes
48*4882a593Smuzhiyun-
49*4882a593Smuzhiyun-    # Shebang support for an executable with a space in it is under-specified
50*4882a593Smuzhiyun-    # and platform-dependent, so we use a clever hack to generate a script to
51*4882a593Smuzhiyun-    # run in ``/bin/sh`` that should work on all reasonably modern platforms.
52*4882a593Smuzhiyun-    # Read the following message to understand how the hack works:
53*4882a593Smuzhiyun-    # https://github.com/pradyunsg/installer/pull/4#issuecomment-623668717
54*4882a593Smuzhiyun-
55*4882a593Smuzhiyun-    quoted = shlex.quote(executable).encode("utf-8")
56*4882a593Smuzhiyun-    # I don't understand a lick what this is trying to do.
57*4882a593Smuzhiyun-    return b"#!/bin/sh\n'''exec' " + quoted + b' "$0" "$@"\n' + b"' '''"
58*4882a593Smuzhiyun+    return b"#!" + executable_bytes
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun class InvalidScript(ValueError):
62