Skip to content

Commit

Permalink
Revert "Work around Bazel launcher issues on Windows."
Browse files Browse the repository at this point in the history
This reverts commit ca3ba21.

With bazelbuild/bazel#14500
and bazelbuild/bazel#14515,
this should now be resolved in all supported Bazel versions.
  • Loading branch information
phst committed Feb 23, 2024
1 parent 46ac5da commit 27092e7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 46 deletions.
19 changes: 1 addition & 18 deletions elisp/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,26 +450,9 @@ absl::StatusOr<int> Run(const std::string_view binary,
absl::StatusOr<NativeString> resolved_binary = runfiles.Resolve(binary);
if (!resolved_binary.ok()) return resolved_binary.status();
std::vector<NativeString> final_args{*resolved_binary};
final_args.insert(final_args.end(), args.begin(), args.end());
absl::StatusOr<Environment> map = runfiles.Environment();
if (!map.ok()) return map.status();
std::vector<NativeString> 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<Environment> orig_env = CopyEnv();
if (!orig_env.ok()) return orig_env.status();
// We don’t want the Python launcher to change the current working directory,
Expand Down
12 changes: 2 additions & 10 deletions elisp/run_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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()
11 changes: 2 additions & 9 deletions elisp/run_emacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
11 changes: 2 additions & 9 deletions elisp/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import subprocess
import sys
import time
from typing import List
import urllib.parse

from elisp import load
Expand All @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit 27092e7

Please sign in to comment.