From bfdd11524dfe71414c179d8b1f55162517281d2f Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Mon, 29 Nov 2021 22:07:48 +0100 Subject: [PATCH] Use executable as argv[0]. This addresses https://github.com/bazelbuild/bazel/issues/14343. This is only possible because https://github.com/bazelbuild/bazel/issues/14500 has been fixed in all supported Bazel versions. --- elisp/run_binary.py | 8 ++------ elisp/run_emacs.py | 7 ++----- elisp/run_test.py | 8 ++------ 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/elisp/run_binary.py b/elisp/run_binary.py index 8e6380df..d608b969 100644 --- a/elisp/run_binary.py +++ b/elisp/run_binary.py @@ -55,10 +55,7 @@ def main() -> None: orig_env.pop('RUN_UNDER_RUNFILES', None) run_files = runfiles.Runfiles(dict(opts.runfiles_env)) emacs = run_files.resolve(opts.wrapper) - # We need to set argv[0] to the original argv[0] because the binary will use - # it to find its runfiles. See - # https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub. - args = [opts.argv[0]] + args = [str(emacs)] # List[str] with manifest.add(opts.mode, args) as manifest_file: args.append('--quick') if not opts.interactive: @@ -76,8 +73,7 @@ def main() -> None: env = dict(orig_env) env.update(run_files.environment()) try: - subprocess.run(executable=str(emacs), args=args, env=env, - check=True) + subprocess.run(args, env=env, check=True) except subprocess.CalledProcessError as ex: if 0 < ex.returncode < 0x100: # Don’t print a stacktrace if Emacs exited with a non-zero exit diff --git a/elisp/run_emacs.py b/elisp/run_emacs.py index c8a7dc0a..45aa11a7 100644 --- a/elisp/run_emacs.py +++ b/elisp/run_emacs.py @@ -45,10 +45,7 @@ def main() -> None: shared = _glob_unique(install / 'share' / 'emacs' / '[0-9]*') etc = shared / 'etc' libexec = install / 'libexec' - # We need to set argv[0] to the original argv[0] because the binary will use - # it to find its runfiles. See - # https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub.ñ - args = [opts.argv[0]] + args = [str(emacs)] # List[str] if opts.dump_mode == 'portable': dump = _glob_unique(libexec / 'emacs' / '*' / '*' / 'emacs.pdmp') args.append('--dump-file=' + str(dump)) @@ -70,7 +67,7 @@ def main() -> None: _check_codepage('environment variable name', env.keys()) _check_codepage('environment variable value', env.values()) try: - subprocess.run(executable=str(emacs), args=args, env=env, check=True) + subprocess.run(args, env=env, check=True) except subprocess.CalledProcessError as ex: if 0 < ex.returncode < 0x100: # Don’t print a stacktrace if Emacs exited with a non-zero exit diff --git a/elisp/run_test.py b/elisp/run_test.py index 79d8c197..28529e44 100644 --- a/elisp/run_test.py +++ b/elisp/run_test.py @@ -64,10 +64,7 @@ def main() -> None: orig_env.pop('RUN_UNDER_RUNFILES', None) run_files = runfiles.Runfiles(dict(opts.runfiles_env)) emacs = run_files.resolve(opts.wrapper) - # We need to set argv[0] to the original argv[0] because the binary will use - # it to find its runfiles. See - # https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub.ñ - args = [opts.argv[0]] + args = [str(emacs)] # List[str] with manifest.add(opts.mode, args) as manifest_file: args += ['--quick', '--batch'] if opts.module_assertions: @@ -122,8 +119,7 @@ def main() -> None: # We can’t use subprocess.run on Windows because it terminates the # subprocess using TerminateProcess on timeout, giving it no chance to # clean up after itself. - with subprocess.Popen(executable=str(emacs), args=args, env=env, - **kwargs) as process: + with subprocess.Popen(args, env=env, **kwargs) as process: try: process.communicate(timeout=timeout_secs) except subprocess.TimeoutExpired: