Skip to content

Commit

Permalink
rust: Add eprint help to write to stderr
Browse files Browse the repository at this point in the history
Summary:
Adding `file=sys.stderr` is a mouthful. Even more if we try to align on
always using LF (and not CRLF).

Reviewed By: shayne-fletcher

Differential Revision: D50080143

fbshipit-source-id: 360b90d25febd7281b0a308adf16171eb59a1e65
  • Loading branch information
zertosh authored and facebook-github-bot committed Oct 9, 2023
1 parent 72ecbb4 commit 8a1aff2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
16 changes: 10 additions & 6 deletions prelude/rust/tools/buildscript_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down
11 changes: 6 additions & 5 deletions prelude/rust/tools/failure_filter_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8a1aff2

Please sign in to comment.