From b4f6e1253356370c8d8855ea0b155e844db98b83 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 5 Oct 2026 10:34:55 +0500 Subject: tools/project-clang-format.py -> project/format.py --- project/utils.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'project/utils.py') diff --git a/project/utils.py b/project/utils.py index 8ef6639..3fb73c4 100644 --- a/project/utils.py +++ b/project/utils.py @@ -7,6 +7,7 @@ from contextlib import contextmanager import functools import logging import os.path +import shlex import shutil import subprocess import sys @@ -81,9 +82,32 @@ def cd(path): os.chdir(cwd) -def run(cmd_line, **kwargs): - logging.info("Running: %s", subprocess.list2cmdline(cmd_line)) - return subprocess.run(cmd_line, check=True, **kwargs) +def run(cmd, **kwargs): + logging.info("Running: %s", shlex.join(cmd)) + return subprocess.run(cmd, check=True, **kwargs) + + +def _run_log_output(level, output): + if not output: + logging.log(level, "... No output") + logging.log(level, "Output (%d) characters):", len(output)) + for line in output.splitlines(): + logging.log(level, " %s", line) + + +def run_capture(cmd, **kwargs): + stdout = subprocess.PIPE + stderr = subprocess.STDOUT + + try: + result = run(cmd, **kwargs, stdout=stdout, stderr=stderr, encoding="utf-8") + except subprocess.CalledProcessError as e: + logging.error("... Exited with code %d", e.returncode) + _run_log_output(logging.ERROR, e.output) + raise + + _run_log_output(logging.DEBUG, result.stdout) + return result.stdout @contextmanager -- cgit v1.3