Skip to content

Commit

Permalink
compilers: remove Environment parameter from has_header
Browse files Browse the repository at this point in the history
and replace with self.env
  • Loading branch information
dcbaker committed Jul 7, 2023
1 parent aaf6b78 commit 350f1ac
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def check_header(self, hname: str, prefix: str, *,
"""
raise EnvironmentException('Language %s does not support header checks.' % self.get_display_language())

def has_header(self, hname: str, prefix: str, env: 'Environment', *,
def has_header(self, hname: str, prefix: str, *,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
disable_cache: bool = False) -> T.Tuple[bool, bool]:
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def alignment(self, typename: str, prefix: str, env: 'Environment', *,
raise mesonlib.EnvironmentException(f'Could not determine alignment of {typename}. Sorry. You might want to file a bug.')
return align, res.cached

def has_header(self, hname: str, prefix: str, env: 'Environment', *,
def has_header(self, hname: str, prefix: str, *,
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
disable_cache: bool = False) -> T.Tuple[bool, bool]:
Expand All @@ -785,7 +785,7 @@ def has_header(self, hname: str, prefix: str, env: 'Environment', *,
code = f'''{prefix}
import {hname};
'''
return self.compiles(code, env, extra_args=extra_args,
return self.compiles(code, self.env, extra_args=extra_args,
dependencies=dependencies, mode='compile', disable_cache=disable_cache)

class GnuDCompiler(GnuCompiler, DCompiler):
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def language_stdlib_only_link_flags(self, env: 'Environment') -> T.List[str]:
search_dirs.append(f'-L{d}')
return search_dirs + ['-lgfortran', '-lm']

def has_header(self, hname: str, prefix: str, env: 'Environment', *,
def has_header(self, hname: str, prefix: str, *,
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
disable_cache: bool = False) -> T.Tuple[bool, bool]:
Expand All @@ -205,7 +205,7 @@ def has_header(self, hname: str, prefix: str, env: 'Environment', *,
https://github.com/mesonbuild/meson/issues/7017
'''
code = f'{prefix}\n#include <{hname}>'
return self.compiles(code, env, extra_args=extra_args,
return self.compiles(code, self.env, extra_args=extra_args,
dependencies=dependencies, mode='preprocess', disable_cache=disable_cache)


Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def check_header(self, hname: str, prefix: str, *,
return self.compiles(code, self.env, extra_args=extra_args,
dependencies=dependencies)

def has_header(self, hname: str, prefix: str, env: 'Environment', *,
def has_header(self, hname: str, prefix: str, *,
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
disable_cache: bool = False) -> T.Tuple[bool, bool]:
Expand All @@ -369,7 +369,7 @@ def has_header(self, hname: str, prefix: str, env: 'Environment', *,
#else
#include <{hname}>
#endif'''
return self.compiles(code, env, extra_args=extra_args,
return self.compiles(code, self.env, extra_args=extra_args,
dependencies=dependencies, mode='preprocess', disable_cache=disable_cache)

def has_header_symbol(self, hname: str, symbol: str, prefix: str, *,
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/dependencies/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
libs = ['z']
for lib in libs:
l = self.clib_compiler.find_library(lib, environment, [])
h = self.clib_compiler.has_header('zlib.h', '', environment, dependencies=[self])
h = self.clib_compiler.has_header('zlib.h', '', dependencies=[self])
if l and h[0]:
self.is_found = True
self.link_args = l
Expand Down
14 changes: 7 additions & 7 deletions mesonbuild/dependencies/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__(name, env, kwargs)
self.feature_since = ('0.62.0', "consider checking for `dlopen` with and without `find_library('dl')`")

h = self.clib_compiler.has_header('dlfcn.h', '', env)
h = self.clib_compiler.has_header('dlfcn.h', '')
self.link_args = self.clib_compiler.find_library('dl', env, [], self.libtype)

if h[0] and self.link_args:
Expand Down Expand Up @@ -131,7 +131,7 @@ def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> No
# Flang has omp_lib.h
header_names = ('omp.h', 'omp_lib.h')
for name in header_names:
if self.clib_compiler.has_header(name, '', self.env, dependencies=[self], disable_cache=True)[0]:
if self.clib_compiler.has_header(name, '', dependencies=[self], disable_cache=True)[0]:
self.is_found = True
self.compile_args = self.clib_compiler.openmp_flags()
self.link_args = self.clib_compiler.openmp_link_flags()
Expand Down Expand Up @@ -169,7 +169,7 @@ def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> No
self.compile_args = ['-fblocks']
self.link_args = ['-lBlocksRuntime']

if not self.clib_compiler.has_header('Block.h', '', environment, disable_cache=True) or \
if not self.clib_compiler.has_header('Block.h', '', disable_cache=True) or \
not self.clib_compiler.find_library('BlocksRuntime', environment, []):
mlog.log(mlog.red('ERROR:'), 'BlocksRuntime not found.')
return
Expand Down Expand Up @@ -344,7 +344,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
l = self.clib_compiler.find_library(lib, env, [])
if l:
for header in headers:
h = self.clib_compiler.has_header(header, '', env)
h = self.clib_compiler.has_header(header, '')
if h[0]:
self.is_found = True
self.link_args = l
Expand Down Expand Up @@ -390,7 +390,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__(name, env, kwargs)
self.feature_since = ('0.60.0', "consider checking for `iconv_open` with and without find_library('iconv')")

h = self.clib_compiler.has_header('iconv.h', '', env)
h = self.clib_compiler.has_header('iconv.h', '')
self.link_args = self.clib_compiler.find_library('iconv', env, [], self.libtype)

if h[0] and self.link_args:
Expand All @@ -412,7 +412,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__(name, env, kwargs)
self.feature_since = ('0.59.0', "consider checking for `ngettext` with and without `find_library('intl')`")

h = self.clib_compiler.has_header('libintl.h', '', env)
h = self.clib_compiler.has_header('libintl.h', '')
self.link_args = self.clib_compiler.find_library('intl', env, [], self.libtype)

if h[0] and self.link_args:
Expand All @@ -432,7 +432,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
'method': 'system',
'static': self.static,
}
if not self.clib_compiler.has_header('openssl/ssl.h', '', env)[0]:
if not self.clib_compiler.has_header('openssl/ssl.h', '')[0]:
return

# openssl >= 3 only
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/dependencies/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def __init__(self, name: str, environment: 'Environment',
if mesonlib.is_windows() and self.get_windows_python_arch().endswith('64') and mesonlib.version_compare(self.version, '<3.12'):
self.compile_args += ['-DMS_WIN64=']

if not self.clib_compiler.has_header('Python.h', '', environment, extra_args=self.compile_args):
if not self.clib_compiler.has_header('Python.h', '', extra_args=self.compile_args):
self.is_found = False

def find_libpy(self, environment: 'Environment') -> None:
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/dependencies/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
return
else:
links = self.clib_compiler.find_library('GL', environment, [])
has_header = self.clib_compiler.has_header('GL/gl.h', '', environment)[0]
has_header = self.clib_compiler.has_header('GL/gl.h', '')[0]
if links and has_header:
self.is_found = True
self.link_args = links
Expand Down Expand Up @@ -242,7 +242,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
else:
# simply try to guess it, usually works on linux
libs = self.clib_compiler.find_library('vulkan', environment, [])
if libs is not None and self.clib_compiler.has_header('vulkan/vulkan.h', '', environment, disable_cache=True)[0]:
if libs is not None and self.clib_compiler.has_header('vulkan/vulkan.h', '', disable_cache=True)[0]:
self.is_found = True
for lib in libs:
self.link_args.append(lib)
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/interpreter/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def _has_header_impl(self, hname: str, kwargs: 'HeaderKW') -> bool:
return False
extra_args = functools.partial(self._determine_args, kwargs['no_builtin_args'], kwargs['include_directories'], kwargs['args'])
deps, msg = self._determine_dependencies(kwargs['dependencies'])
haz, cached = self.compiler.has_header(hname, kwargs['prefix'], self.environment,
haz, cached = self.compiler.has_header(hname, kwargs['prefix'],
extra_args=extra_args, dependencies=deps)
cached_msg = mlog.blue('(cached)') if cached else ''
if required and not haz:
Expand Down

0 comments on commit 350f1ac

Please sign in to comment.