From 27092e7c5007e0abac1dc64dc4c4166815c8ee95 Mon Sep 17 00:00:00 2001
From: Philipp Stephani
Date: Thu, 22 Feb 2024 15:48:52 +0100
Subject: [PATCH] Revert "Work around Bazel launcher issues on Windows."
This reverts commit ca3ba210ee6ac673246cdbc35d30b6ed5f80e39b.
With https://github.com/bazelbuild/bazel/issues/14500
and https://github.com/bazelbuild/bazel/pull/14515,
this should now be resolved in all supported Bazel versions.
---
elisp/process.cc | 19 +------------------
elisp/run_binary.py | 12 ++----------
elisp/run_emacs.py | 11 ++---------
elisp/run_test.py | 11 ++---------
4 files changed, 7 insertions(+), 46 deletions(-)
diff --git a/elisp/process.cc b/elisp/process.cc
index b08cafdc..8b62b42a 100644
--- a/elisp/process.cc
+++ b/elisp/process.cc
@@ -450,26 +450,9 @@ absl::StatusOr Run(const std::string_view binary,
absl::StatusOr resolved_binary = runfiles.Resolve(binary);
if (!resolved_binary.ok()) return resolved_binary.status();
std::vector final_args{*resolved_binary};
+ final_args.insert(final_args.end(), args.begin(), args.end());
absl::StatusOr map = runfiles.Environment();
if (!map.ok()) return map.status();
- std::vector runfiles_args;
- // Pass the runfiles environment variables as separate arguments. This is
- // necessary because the binary launcher unconditionally sets the runfiles
- // environment variables based on its own argv[0]; see
- // https://github.com/bazelbuild/bazel/blob/5.4.1/src/tools/launcher/launcher.cc
- // and https://github.com/bazelbuild/bazel/pull/16916. We also can’t set
- // argv[0] to this binary because the launcher uses it to find its own binary;
- // see
- // https://github.com/bazelbuild/bazel/blob/5.4.1/src/tools/launcher/launcher_main.cc.
- // Once we drop support for Bazel 6.0 and below, we should be able to modify
- // argv[0] to make this launcher more transparent.
- for (const auto& [key, value] : *map) {
- runfiles_args.push_back(RULES_ELISP_NATIVE_LITERAL("--runfiles-env=") +
- key + RULES_ELISP_NATIVE_LITERAL('=') + value);
- }
- final_args.insert(final_args.end(), runfiles_args.begin(),
- runfiles_args.end());
- final_args.insert(final_args.end(), args.begin(), args.end());
absl::StatusOr orig_env = CopyEnv();
if (!orig_env.ok()) return orig_env.status();
// We don’t want the Python launcher to change the current working directory,
diff --git a/elisp/run_binary.py b/elisp/run_binary.py
index 917bfb11..a7899f11 100644
--- a/elisp/run_binary.py
+++ b/elisp/run_binary.py
@@ -24,7 +24,7 @@
import pathlib
import subprocess
import sys
-from typing import Optional
+from typing import Iterable, Mapping, Optional, Sequence
from elisp import load
from elisp import manifest
@@ -33,9 +33,6 @@
def main() -> None:
"""Main function."""
parser = argparse.ArgumentParser(allow_abbrev=False)
- parser.add_argument('--env', action='append', type=_env_var, default=[])
- parser.add_argument('--runfiles-env', action='append', type=_env_var,
- default=[])
parser.add_argument('--wrapper', type=pathlib.PurePosixPath, required=True)
parser.add_argument('--mode', choices=('direct', 'wrap'), required=True)
parser.add_argument('--runfiles-elc', type=pathlib.PurePosixPath,
@@ -53,7 +50,7 @@ def main() -> None:
parser.add_argument('argv', nargs='+')
opts = parser.parse_args()
env: dict[str, str] = dict(os.environ)
- run_files = runfiles.Runfiles(dict(opts.runfiles_env))
+ run_files = runfiles.Runfiles()
emacs = run_files.resolve(opts.wrapper)
args: list[str] = [str(emacs)]
with manifest.add(opts.mode, args) as manifest_file:
@@ -114,10 +111,5 @@ def _arg_files(argv: Sequence[str], root: pathlib.Path,
return tuple(result)
-def _env_var(arg: str) -> tuple[str, str]:
- key, _, value = arg.partition('=')
- return key, value
-
-
if __name__ == '__main__':
main()
diff --git a/elisp/run_emacs.py b/elisp/run_emacs.py
index 27cf4cd3..1258f68f 100644
--- a/elisp/run_emacs.py
+++ b/elisp/run_emacs.py
@@ -28,19 +28,17 @@
import subprocess
import sys
import tempfile
+from typing import Iterable
from elisp import runfiles
def main() -> None:
"""Main function."""
parser = argparse.ArgumentParser(allow_abbrev=False)
- parser.add_argument('--env', action='append', type=_env_var, default=[])
- parser.add_argument('--runfiles-env', action='append', type=_env_var,
- default=[])
parser.add_argument('--install', type=pathlib.PurePosixPath, required=True)
parser.add_argument('argv', nargs='+')
opts = parser.parse_args()
- run_files = runfiles.Runfiles(dict(opts.runfiles_env))
+ run_files = runfiles.Runfiles()
install = run_files.resolve(opts.install)
exe_suffix = '.exe' if os.name == 'nt' else ''
emacs = install / 'bin' / ('emacs' + exe_suffix)
@@ -107,10 +105,5 @@ def _check_codepage(description: str, values: Iterable[str]) -> None:
f'can’t encode {description} “{value}” for Windows') from ex
-def _env_var(arg: str) -> tuple[str, str]:
- key, _, value = arg.partition('=')
- return key, value
-
-
if __name__ == '__main__':
main()
diff --git a/elisp/run_test.py b/elisp/run_test.py
index d17d767e..ab65fb24 100644
--- a/elisp/run_test.py
+++ b/elisp/run_test.py
@@ -26,6 +26,7 @@
import subprocess
import sys
import time
+from typing import List
import urllib.parse
from elisp import load
@@ -35,9 +36,6 @@
def main() -> None:
"""Main function."""
parser = argparse.ArgumentParser(allow_abbrev=False)
- parser.add_argument('--env', action='append', type=_env_var, default=[])
- parser.add_argument('--runfiles-env', action='append', type=_env_var,
- default=[])
parser.add_argument('--wrapper', type=pathlib.PurePosixPath, required=True)
parser.add_argument('--mode', choices=('direct', 'wrap'), required=True)
parser.add_argument('--runfiles-elc', type=pathlib.PurePosixPath,
@@ -62,7 +60,7 @@ def main() -> None:
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(name)s %(message)s')
env: dict[str, str] = dict(os.environ)
- run_files = runfiles.Runfiles(dict(opts.runfiles_env))
+ run_files = runfiles.Runfiles()
emacs = run_files.resolve(opts.wrapper)
args: list[str] = [str(emacs)]
with manifest.add(opts.mode, args) as manifest_file:
@@ -174,11 +172,6 @@ def _fix_coverage_manifest(manifest_file: pathlib.Path,
stream.write(file + '\n')
-def _env_var(arg: str) -> tuple[str, str]:
- key, _, value = arg.partition('=')
- return key, value
-
-
_WINDOWS = os.name == 'nt'
_logger = logging.getLogger('elisp.run_test')