aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-06-13 00:45:15 -0400
committerEli Schwartz <eschwartz@archlinux.org>2023-06-14 01:04:55 -0400
commitaa13c46822611f615429f3f05556fc29c7e1d505 (patch)
treed59b9645972ea0f46d00b0eb532b38140b4806cb /mesonbuild
parentc503c757f1afa4677d98901ce3fc1e509c01aeeb (diff)
downloadmeson-aa13c46822611f615429f3f05556fc29c7e1d505.zip
meson-aa13c46822611f615429f3f05556fc29c7e1d505.tar.gz
meson-aa13c46822611f615429f3f05556fc29c7e1d505.tar.bz2
WIP: refactor loggable popen calls for consistency
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/compilers/compilers.py7
-rw-r--r--mesonbuild/compilers/detect.py9
-rw-r--r--mesonbuild/dependencies/configtool.py9
-rw-r--r--mesonbuild/dependencies/pkgconfig.py13
-rw-r--r--mesonbuild/linkers/detect.py20
-rw-r--r--mesonbuild/utils/universal.py16
6 files changed, 29 insertions, 45 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 5f6fa08..76f9e0e 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -26,7 +26,7 @@ from .. import mesonlib
from ..mesonlib import (
HoldableObject,
EnvironmentException, MesonException,
- Popen_safe, LibType, TemporaryDirectoryWinProof, OptionKey,
+ Popen_safe_logged, LibType, TemporaryDirectoryWinProof, OptionKey,
)
from ..arglist import CompilerArgs
@@ -855,15 +855,12 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
command_list = self.get_exelist(ccache=not no_ccache) + commands.to_native()
mlog.debug('Running compile:')
mlog.debug('Working directory: ', tmpdirname)
- mlog.debug('Command line: ', ' '.join(command_list), '\n')
mlog.debug('Code:\n', contents)
os_env = os.environ.copy()
os_env['LC_ALL'] = 'C'
if no_ccache:
os_env['CCACHE_DISABLE'] = '1'
- p, stdo, stde = Popen_safe(command_list, cwd=tmpdirname, env=os_env)
- mlog.debug('Compiler stdout:\n', stdo)
- mlog.debug('Compiler stderr:\n', stde)
+ p, stdo, stde = Popen_safe_logged(command_list, msg='Command line', cwd=tmpdirname, env=os_env)
result = CompileResult(stdo, stde, command_list, p.returncode, input_name=srcname)
if want_output:
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index c6d6ae3..f950331 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -15,7 +15,7 @@ from __future__ import annotations
from ..mesonlib import (
MesonException, EnvironmentException, MachineChoice, join_args,
- search_version, is_windows, Popen_safe, windows_proof_rm,
+ search_version, is_windows, Popen_safe, Popen_safe_logged, windows_proof_rm,
)
from ..envconfig import BinaryTable
from .. import mlog
@@ -327,12 +327,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
cmd = compiler + [arg]
try:
- mlog.debug('-----')
- mlog.debug(f'Detecting compiler via: {join_args(cmd)}')
- p, out, err = Popen_safe(cmd)
- mlog.debug(f'compiler returned {p}')
- mlog.debug(f'compiler stdout:\n{out}')
- mlog.debug(f'compiler stderr:\n{err}')
+ p, out, err = Popen_safe_logged(cmd, msg='Detecting compiler via')
except OSError as e:
popen_exceptions[join_args(cmd)] = e
continue
diff --git a/mesonbuild/dependencies/configtool.py b/mesonbuild/dependencies/configtool.py
index 99c0417..5a4294e 100644
--- a/mesonbuild/dependencies/configtool.py
+++ b/mesonbuild/dependencies/configtool.py
@@ -14,7 +14,7 @@
from __future__ import annotations
from .base import ExternalDependency, DependencyException, DependencyTypeName
-from ..mesonlib import listify, Popen_safe, split_args, version_compare, version_compare_many
+from ..mesonlib import listify, Popen_safe, Popen_safe_logged, split_args, version_compare, version_compare_many
from ..programs import find_external_program
from .. import mlog
import re
@@ -143,12 +143,7 @@ class ConfigToolDependency(ExternalDependency):
return self.config is not None
def get_config_value(self, args: T.List[str], stage: str) -> T.List[str]:
- p, out, err = Popen_safe(self.config + args)
- mlog.debug(f'Called `{mesonlib.join_args(self.config+args)}` -> {p.returncode}')
- if out:
- mlog.debug(f'stdout:\n{out}\n-----------')
- if err:
- mlog.debug(f'stderr:\n{err}\n-----------')
+ p, out, err = Popen_safe_logged(self.config + args)
if p.returncode != 0:
if self.required:
raise DependencyException(f'Could not generate {stage} for {self.name}.\n{err}')
diff --git a/mesonbuild/dependencies/pkgconfig.py b/mesonbuild/dependencies/pkgconfig.py
index 8dfb128..0c40847 100644
--- a/mesonbuild/dependencies/pkgconfig.py
+++ b/mesonbuild/dependencies/pkgconfig.py
@@ -16,7 +16,7 @@ from __future__ import annotations
from pathlib import Path
from .base import ExternalDependency, DependencyException, sort_libpaths, DependencyTypeName
-from ..mesonlib import OptionKey, OrderedSet, PerMachine, Popen_safe
+from ..mesonlib import OptionKey, OrderedSet, PerMachine, Popen_safe, Popen_safe_logged
from ..programs import find_external_program, ExternalProgram
from .. import mlog
from pathlib import PurePath
@@ -122,15 +122,8 @@ class PkgConfigDependency(ExternalDependency):
def _call_pkgbin_real(self, args: T.List[str], env: T.Dict[str, str]) -> T.Tuple[int, str, str]:
assert isinstance(self.pkgbin, ExternalProgram)
cmd = self.pkgbin.get_command() + args
- p, out, err = Popen_safe(cmd, env=env)
- rc, out, err = p.returncode, out.strip(), err.strip()
- call = ' '.join(cmd)
- mlog.debug(f"Called `{call}` -> {rc}")
- if out:
- mlog.debug(f'stdout:\n{out}\n-----------')
- if err:
- mlog.debug(f'stderr:\n{err}\n-----------')
- return rc, out, err
+ p, out, err = Popen_safe_logged(cmd, env=env)
+ return p.returncode, out.strip(), err.strip()
@staticmethod
def get_env(environment: 'Environment', for_machine: MachineChoice,
diff --git a/mesonbuild/linkers/detect.py b/mesonbuild/linkers/detect.py
index 59f1d78..3f8de05 100644
--- a/mesonbuild/linkers/detect.py
+++ b/mesonbuild/linkers/detect.py
@@ -17,7 +17,7 @@ from __future__ import annotations
from .. import mlog
from ..mesonlib import (
EnvironmentException,
- Popen_safe, join_args, search_version
+ Popen_safe, Popen_safe_logged, join_args, search_version
)
from .linkers import (
AppleDynamicLinker,
@@ -157,11 +157,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
check_args += override
mlog.debug('-----')
- mlog.debug(f'Detecting linker via: {join_args(compiler + check_args)}')
- p, o, e = Popen_safe(compiler + check_args)
- mlog.debug(f'linker returned {p}')
- mlog.debug(f'linker stdout:\n{o}')
- mlog.debug(f'linker stderr:\n{e}')
+ p, o, e = Popen_safe_logged(compiler + check_args, msg='Detecting linker via')
v = search_version(o + e)
linker: DynamicLinker
@@ -170,11 +166,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
cmd = compiler + override + [comp_class.LINKER_PREFIX + '-v'] + extra_args
else:
cmd = compiler + override + comp_class.LINKER_PREFIX + ['-v'] + extra_args
- mlog.debug('-----')
- mlog.debug(f'Detecting LLD linker via: {join_args(cmd)}')
- _, newo, newerr = Popen_safe(cmd)
- mlog.debug(f'linker stdout:\n{newo}')
- mlog.debug(f'linker stderr:\n{newerr}')
+ _, newo, newerr = Popen_safe_logged(cmd, msg='Detecting LLD linker via')
lld_cls: T.Type[DynamicLinker]
if 'ld64.lld' in newerr:
@@ -211,11 +203,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
cmd = compiler + [comp_class.LINKER_PREFIX + '-v'] + extra_args
else:
cmd = compiler + comp_class.LINKER_PREFIX + ['-v'] + extra_args
- mlog.debug('-----')
- mlog.debug(f'Detecting Apple linker via: {join_args(cmd)}')
- _, newo, newerr = Popen_safe(cmd)
- mlog.debug(f'linker stdout:\n{newo}')
- mlog.debug(f'linker stderr:\n{newerr}')
+ _, newo, newerr = Popen_safe_logged(cmd, msg='Detecting Apple linker via')
for line in newerr.split('\n'):
if 'PROJECT:ld' in line:
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index 79c60c4..08e9881 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -144,6 +144,7 @@ __all__ = [
'path_is_in_root',
'pickle_load',
'Popen_safe',
+ 'Popen_safe_logged',
'quiet_git',
'quote_arg',
'relative_to_if_possible',
@@ -1512,6 +1513,21 @@ def Popen_safe_legacy(args: T.List[str], write: T.Optional[str] = None,
return p, o, e
+def Popen_safe_logged(args: T.List[str], msg: str = 'Called', **kwargs: T.Any) -> T.Tuple['subprocess.Popen[str]', str, str]:
+ '''
+ Wrapper around Popen_safe that assumes standard piped o/e and logs this to the meson log.
+ '''
+ p, o, e = Popen_safe(args, **kwargs)
+ rc, out, err = p.returncode, o.strip(), e.strip()
+ mlog.debug('-----------')
+ mlog.debug(f'{msg}: `{join_args(args)}` -> {rc}')
+ if out:
+ mlog.debug(f'stdout:\n{out}\n-----------')
+ if err:
+ mlog.debug(f'stderr:\n{err}\n-----------')
+ return p, o, e
+
+
def iter_regexin_iter(regexiter: T.Iterable[str], initer: T.Iterable[str]) -> T.Optional[str]:
'''
Takes each regular expression in @regexiter and tries to search for it in