Skip to content

Commit

Permalink
simplify some log formatting by splitting out a commonly used format …
Browse files Browse the repository at this point in the history
…string

There are a bunch of cases in a single function where we would want to
log the detected path of pkg-config. Formatting this is awkward. Define
it once, then use f-strings everywhere. :D
  • Loading branch information
eli-schwartz committed Oct 10, 2021
1 parent 437745b commit 9b80874
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mesonbuild/dependencies/pkgconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,21 +420,20 @@ def get_pkgconfig_variable(self, variable_name: str, kwargs: T.Dict[str, T.Union
return variable

def check_pkgconfig(self, pkgbin: ExternalProgram) -> T.Optional[str]:
command_as_string = ' '.join(pkgbin.get_command())
if not pkgbin.found():
mlog.log(f'Did not find pkg-config by name {pkgbin.name!r}')
return None
try:
p, out = Popen_safe(pkgbin.get_command() + ['--version'])[0:2]
if p.returncode != 0:
mlog.warning('Found pkg-config {!r} but it failed when run'
''.format(' '.join(pkgbin.get_command())))
mlog.warning(f'Found pkg-config {command_as_string!r} but it failed when run')
return None
except FileNotFoundError:
mlog.warning('We thought we found pkg-config {!r} but now it\'s not there. How odd!'
''.format(' '.join(pkgbin.get_command())))
mlog.warning(f'We thought we found pkg-config {command_as_string!r} but now it\'s not there. How odd!')
return None
except PermissionError:
msg = 'Found pkg-config {!r} but didn\'t have permissions to run it.'.format(' '.join(pkgbin.get_command()))
msg = f'Found pkg-config {command_as_string!r} but didn\'t have permissions to run it.')
if not self.env.machines.build.is_windows():
msg += '\n\nOn Unix-like systems this is often caused by scripts that are not executable.'
mlog.warning(msg)
Expand Down

0 comments on commit 9b80874

Please sign in to comment.