mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
Meta: Use new run_command
utility to invoke subprocesses
As opposed to just running subprocess.check_call, our `run_command` utility handles e.g. ctrl+c to avoid spamming the terminal with KeyboardInterrupt stack traces.
This commit is contained in:
parent
a5bfb686f4
commit
f2eaf1e57b
Notes:
github-actions[bot]
2025-05-29 23:35:09 +00:00
Author: https://github.com/trflynn89
Commit: f2eaf1e57b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4904
Reviewed-by: https://github.com/ADKaster
1 changed files with 24 additions and 60 deletions
|
@ -11,7 +11,6 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -24,6 +23,7 @@ from Meta.find_compiler import pick_host_compiler
|
||||||
from Meta.host_platform import HostArchitecture
|
from Meta.host_platform import HostArchitecture
|
||||||
from Meta.host_platform import HostSystem
|
from Meta.host_platform import HostSystem
|
||||||
from Meta.host_platform import Platform
|
from Meta.host_platform import Platform
|
||||||
|
from Meta.utils import run_command
|
||||||
from Toolchain.BuildVcpkg import build_vcpkg
|
from Toolchain.BuildVcpkg import build_vcpkg
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,11 +209,7 @@ def configure_main(platform: Platform, preset: str, cc: str, cxx: str) -> Path:
|
||||||
|
|
||||||
# FIXME: Improve error reporting for vcpkg install failures
|
# FIXME: Improve error reporting for vcpkg install failures
|
||||||
# https://github.com/LadybirdBrowser/ladybird/blob/master/Documentation/BuildInstructionsLadybird.md#unable-to-find-a-build-program-corresponding-to-ninja
|
# https://github.com/LadybirdBrowser/ladybird/blob/master/Documentation/BuildInstructionsLadybird.md#unable-to-find-a-build-program-corresponding-to-ninja
|
||||||
try:
|
run_command(config_args, exit_on_failure=True)
|
||||||
subprocess.check_call(config_args)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print_process_stderr(e, "Unable to configure ladybird project")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return build_preset_dir
|
return build_preset_dir
|
||||||
|
|
||||||
|
@ -289,23 +285,21 @@ def validate_cmake_version():
|
||||||
# FIXME: This 3.25+ CMake version check may not be needed anymore due to vcpkg downloading a newer version
|
# FIXME: This 3.25+ CMake version check may not be needed anymore due to vcpkg downloading a newer version
|
||||||
cmake_install_message = "Please install CMake version 3.25 or newer."
|
cmake_install_message = "Please install CMake version 3.25 or newer."
|
||||||
|
|
||||||
try:
|
cmake_version_output = run_command(["cmake", "--version"], return_output=True, exit_on_failure=True)
|
||||||
cmake_version_output = subprocess.check_output(["cmake", "--version"], text=True).strip()
|
assert cmake_version_output
|
||||||
|
|
||||||
version_match = re.search(r"version\s+(\d+)\.(\d+)\.(\d+)?", cmake_version_output)
|
version_match = re.search(r"version\s+(\d+)\.(\d+)\.(\d+)?", cmake_version_output)
|
||||||
if version_match:
|
if not version_match:
|
||||||
|
print(f"Unable to determine CMake version. {cmake_install_message}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
major = int(version_match.group(1))
|
major = int(version_match.group(1))
|
||||||
minor = int(version_match.group(2))
|
minor = int(version_match.group(2))
|
||||||
patch = int(version_match.group(3))
|
patch = int(version_match.group(3))
|
||||||
|
|
||||||
if major < 3 or (major == 3 and minor < 25):
|
if major < 3 or (major == 3 and minor < 25):
|
||||||
print(f"CMake version {major}.{minor}.{patch} is too old. {cmake_install_message}", file=sys.stderr)
|
print(f"CMake version {major}.{minor}.{patch} is too old. {cmake_install_message}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
|
||||||
print(f"Unable to determine CMake version. {cmake_install_message}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print_process_stderr(e, f"CMake not found. {cmake_install_message}\n")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_ladybird_source_dir() -> Path:
|
def ensure_ladybird_source_dir() -> Path:
|
||||||
|
@ -313,14 +307,11 @@ def ensure_ladybird_source_dir() -> Path:
|
||||||
ladybird_source_dir = Path(ladybird_source_dir) if ladybird_source_dir else None
|
ladybird_source_dir = Path(ladybird_source_dir) if ladybird_source_dir else None
|
||||||
|
|
||||||
if not ladybird_source_dir or not ladybird_source_dir.is_dir():
|
if not ladybird_source_dir or not ladybird_source_dir.is_dir():
|
||||||
try:
|
root_dir = run_command(["git", "rev-parse", "--show-toplevel"], return_output=True, exit_on_failure=True)
|
||||||
top_dir = subprocess.check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip()
|
assert root_dir
|
||||||
ladybird_source_dir = Path(top_dir)
|
|
||||||
|
|
||||||
os.environ["LADYBIRD_SOURCE_DIR"] = str(ladybird_source_dir)
|
os.environ["LADYBIRD_SOURCE_DIR"] = root_dir
|
||||||
except subprocess.CalledProcessError as e:
|
ladybird_source_dir = Path(root_dir)
|
||||||
print_process_stderr(e, "Unable to determine LADYBIRD_SOURCE_DIR:")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return ladybird_source_dir
|
return ladybird_source_dir
|
||||||
|
|
||||||
|
@ -340,11 +331,7 @@ def build_main(build_dir: Path, target: Optional[str] = None, args: list[str] =
|
||||||
build_args.append("--")
|
build_args.append("--")
|
||||||
build_args.extend(args)
|
build_args.extend(args)
|
||||||
|
|
||||||
try:
|
run_command(build_args, exit_on_failure=True)
|
||||||
subprocess.check_call(build_args)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print_process_stderr(e, f"Unable to build Ladybird {f'target {target}' if target else 'project'}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def test_main(build_dir: Path, preset: str, pattern: Optional[str]):
|
def test_main(build_dir: Path, preset: str, pattern: Optional[str]):
|
||||||
|
@ -360,11 +347,7 @@ def test_main(build_dir: Path, preset: str, pattern: Optional[str]):
|
||||||
if pattern:
|
if pattern:
|
||||||
test_args.extend(["-R", pattern])
|
test_args.extend(["-R", pattern])
|
||||||
|
|
||||||
try:
|
run_command(test_args, exit_on_failure=True)
|
||||||
subprocess.check_call(test_args)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print_process_stderr(e, f"Unable to test Ladybird {f'pattern {pattern}' if pattern else 'project'}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def run_main(host_system: HostSystem, build_dir: Path, target: str, args: list[str]):
|
def run_main(host_system: HostSystem, build_dir: Path, target: str, args: list[str]):
|
||||||
|
@ -385,12 +368,7 @@ def run_main(host_system: HostSystem, build_dir: Path, target: str, args: list[s
|
||||||
|
|
||||||
run_args.extend(args)
|
run_args.extend(args)
|
||||||
|
|
||||||
try:
|
run_command(run_args, exit_on_failure=True)
|
||||||
# FIXME: For Windows, set the working directory so DLLs are found
|
|
||||||
subprocess.check_call(run_args)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print_process_stderr(e, f'Unable to run ladybird target "{target}"')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def debug_main(host_system: HostSystem, build_dir: Path, target: str, debugger: str, debugger_commands: list[str]):
|
def debug_main(host_system: HostSystem, build_dir: Path, target: str, debugger: str, debugger_commands: list[str]):
|
||||||
|
@ -408,12 +386,7 @@ def debug_main(host_system: HostSystem, build_dir: Path, target: str, debugger:
|
||||||
else:
|
else:
|
||||||
gdb_args.append(str(build_dir.joinpath("bin", target)))
|
gdb_args.append(str(build_dir.joinpath("bin", target)))
|
||||||
|
|
||||||
try:
|
run_command(gdb_args, exit_on_failure=True)
|
||||||
# FIXME: For Windows, set the working directory so DLLs are found
|
|
||||||
subprocess.check_call(gdb_args)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print_process_stderr(e, f'Unable to run ladybird target "{target}" with "{debugger}" debugger')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def clean_main(preset: str, cc: str, cxx: str):
|
def clean_main(preset: str, cc: str, cxx: str):
|
||||||
|
@ -447,16 +420,7 @@ def addr2line_main(build_dir, target: str, program: str, addresses: list[str]):
|
||||||
]
|
]
|
||||||
addr2line_args.extend(addresses)
|
addr2line_args.extend(addresses)
|
||||||
|
|
||||||
try:
|
run_command(addr2line_args, exit_on_failure=True)
|
||||||
subprocess.check_call(addr2line_args)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print_process_stderr(e, f'Unable to find lines with "{program}" for binary target "{target}"')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def print_process_stderr(exception: subprocess.CalledProcessError, message: str):
|
|
||||||
details = f": {exception.stderr}" if exception.stderr else ""
|
|
||||||
print(f"{message}{details}", file=sys.stderr)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue