diff --git a/prelude/rust/tools/buildscript_run.py b/prelude/rust/tools/buildscript_run.py index ee10e9621619..69a96f3389d1 100755 --- a/prelude/rust/tools/buildscript_run.py +++ b/prelude/rust/tools/buildscript_run.py @@ -15,12 +15,16 @@ import subprocess import sys from pathlib import Path -from typing import Dict, IO, NamedTuple +from typing import Any, Dict, IO, NamedTuple IS_WINDOWS: bool = os.name == "nt" +def eprint(*args: Any, **kwargs: Any) -> None: + print(*args, end="\n", file=sys.stderr, flush=True, **kwargs) + + def cfg_env(rustc_cfg: Path) -> Dict[str, str]: with rustc_cfg.open(encoding="utf-8") as f: lines = f.readlines() @@ -142,13 +146,13 @@ def ensure_rustc_available( shell=IS_WINDOWS, ) except OSError as ex: - print(f"Failed to run {rustc} because {ex}", file=sys.stderr) + eprint(f"Failed to run {rustc} because {ex}") sys.exit(1) except subprocess.CalledProcessError as ex: - print(f"Command failed with exit code {ex.returncode}", file=sys.stderr) - print(f"Command: {ex.cmd}", file=sys.stderr) + eprint(f"Command failed with exit code {ex.returncode}") + eprint(f"Command: {ex.cmd}") if ex.stdout: - print(f"Stdout: {ex.stdout}", file=sys.stderr) + eprint(f"Stdout: {ex.stdout}") sys.exit(1) @@ -216,7 +220,7 @@ def main() -> None: # noqa: C901 if cargo_rustc_cfg_match: flags += "--cfg={}\n".format(cargo_rustc_cfg_match.group(1)) else: - print(line) + print(line, end="\n") args.outfile.write(flags) diff --git a/prelude/rust/tools/failure_filter_action.py b/prelude/rust/tools/failure_filter_action.py index 6fd2342ee7bd..155c93ad5b18 100755 --- a/prelude/rust/tools/failure_filter_action.py +++ b/prelude/rust/tools/failure_filter_action.py @@ -16,7 +16,11 @@ import os import shutil import sys -from typing import IO, List, NamedTuple, Optional, Tuple +from typing import Any, IO, List, NamedTuple, Optional, Tuple + + +def eprint(*args: Any, **kwargs: Any) -> None: + print(*args, end="\n", file=sys.stderr, flush=True, **kwargs) class Args(NamedTuple): @@ -69,10 +73,7 @@ def main() -> int: # Fall back to real copy if that doesn't work shutil.copy(inp, out) else: - print( - f"Missing required input file {short} ({inp})", - file=sys.stderr, - ) + eprint(f"Missing required input file {short} ({inp})") return build_status["status"] # If all the required files were present, then success regardless of