From d1090edb914be0efaddabd5a254bb2051d74bb59 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 21 Jul 2025 10:31:08 +0200 Subject: Print external project logfile on CI systems --- mesonbuild/modules/external_project.py | 9 ++++++--- mesonbuild/scripts/externalproject.py | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mesonbuild/modules/external_project.py b/mesonbuild/modules/external_project.py index 339d0003f..ba7b30075 100644 --- a/mesonbuild/modules/external_project.py +++ b/mesonbuild/modules/external_project.py @@ -201,10 +201,10 @@ class ExternalProject(NewExtensionModule): def _run(self, step: str, command: T.List[str], workdir: Path) -> None: mlog.log(f'External project {self.name}:', mlog.bold(step)) m = 'Running command ' + str(command) + ' in directory ' + str(workdir) + '\n' - log_filename = Path(mlog.get_log_dir(), f'{self.name}-{step}.log') + logfile = Path(mlog.get_log_dir(), f'{self.name}-{step}.log') output = None if not self.verbose: - output = open(log_filename, 'w', encoding='utf-8') + output = open(logfile, 'w', encoding='utf-8') output.write(m + '\n') output.flush() else: @@ -215,7 +215,10 @@ class ExternalProject(NewExtensionModule): if p.returncode != 0: m = f'{step} step returned error code {p.returncode}.' if not self.verbose: - m += '\nSee logs: ' + str(log_filename) + m += '\nSee logs: ' + str(logfile) + contents = mlog.ci_fold_file(logfile, f'CI platform detected, click here for {os.path.basename(logfile)} contents.') + if contents: + print(contents) raise MesonException(m) def _create_targets(self, extra_depends: T.List[T.Union['BuildTarget', 'CustomTarget']]) -> T.List['TYPE_var']: diff --git a/mesonbuild/scripts/externalproject.py b/mesonbuild/scripts/externalproject.py index 4013b0acf..b782a8551 100644 --- a/mesonbuild/scripts/externalproject.py +++ b/mesonbuild/scripts/externalproject.py @@ -10,6 +10,7 @@ from pathlib import Path import typing as T from ..mesonlib import Popen_safe, split_args, determine_worker_count +from .. import mlog class ExternalProject: def __init__(self, options: argparse.Namespace): @@ -67,10 +68,10 @@ class ExternalProject: def _run(self, step: str, command: T.List[str], env: T.Optional[T.Dict[str, str]] = None) -> int: m = 'Running command ' + str(command) + ' in directory ' + str(self.build_dir) + '\n' - log_filename = Path(self.log_dir, f'{self.name}-{step}.log') + logfile = Path(self.log_dir, f'{self.name}-{step}.log') output = None if not self.verbose: - output = open(log_filename, 'w', encoding='utf-8') + output = open(logfile, 'w', encoding='utf-8') output.write(m + '\n') output.flush() else: @@ -84,8 +85,11 @@ class ExternalProject: if p.returncode != 0: m = f'{step} step returned error code {p.returncode}.' if not self.verbose: - m += '\nSee logs: ' + str(log_filename) + m += '\nSee logs: ' + str(logfile) print(m) + contents = mlog.ci_fold_file(logfile, f'CI platform detected, click here for {os.path.basename(logfile)} contents.') + if contents: + print(contents) return p.returncode def run(args: T.List[str]) -> int: -- cgit v1.2.3