debugruntest: fix requires binary invocation for debugruntest .t tests

Summary:
When running `.t` integration tests using `debugruntest`, and those tests depend on some external binary, they have to be declared with teh `requires` keyword at the beginning of the test. Those external binaries can be invoked either by the "shell" in the `.t` tests or by hg/sl.

Before this diff a mechanism existed for calling external commands under `debugruntest`, but this only worked for those invoked via the `ui.system` method. This was possible since one of the methods ultimately called by `ui.system` was monkey-patched by `hg.py`. This diff does something similar for the `subprocess.run` method.

Reviewed By: quark-zju

Differential Revision: D41793101

fbshipit-source-id: dffb042791e3c4b9be9ae05a8b8586a4fe3f382d
This commit is contained in:
Saul Gutierrez 2022-12-07 19:54:24 -08:00 committed by Facebook GitHub Bot
parent 8434fc0d40
commit 2e30eb56d2

View File

@ -13,6 +13,7 @@
import io
import os
import subprocess
import sys
from functools import partial
from typing import BinaryIO
@ -206,7 +207,11 @@ def hg(stdin: BinaryIO, stdout: BinaryIO, stderr: BinaryIO, env: Env) -> int:
try:
with shellenv(
env, stdin=stdin, stdout=stdout, stderr=stderr
), extensions.wrappedfunction(util, "rawsystem", rawsystem):
), extensions.wrappedfunction(
util, "rawsystem", rawsystem
), extensions.wrappedfunction(
subprocess, "run", _patchedsubprun
):
bindings.identity.resetdefault()
encoding.setfromenviron()
@ -255,6 +260,16 @@ def _rawsystem(
return res.exitcode
def _patchedsubprun(orig, args, **kwargs):
if os.name == "nt" and args:
# append ".bat" to args[0]
arg0bat = f"{args[0]}.bat"
paths = os.getenv("PATH", "").split(os.pathsep)
if any(os.path.exists(os.path.join(p, arg0bat)) for p in paths):
args[0] = arg0bat
return orig(args, **kwargs)
def _execpython(path):
"""execute python code at path, return its globals"""
with open(path, "r") as f: