diff options
author | Andres Freund <andres@anarazel.de> | 2023-02-19 12:22:37 -0800 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-02-27 20:09:32 -0500 |
commit | 808d5934dd6c6a6c16f66e9dc51dae6e83e02cef (patch) | |
tree | e70ac01d9ccac49bad5a7d20b8a79730e388a548 /mesonbuild/compilers | |
parent | 9a41ce58d682faa59fcef5b067adc393a5412d30 (diff) | |
download | meson-808d5934dd6c6a6c16f66e9dc51dae6e83e02cef.zip meson-808d5934dd6c6a6c16f66e9dc51dae6e83e02cef.tar.gz meson-808d5934dd6c6a6c16f66e9dc51dae6e83e02cef.tar.bz2 |
Use caching in Compiler.sizeof() and Compiler.alignment()
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/compilers.py | 4 | ||||
-rw-r--r-- | mesonbuild/compilers/d.py | 14 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/clike.py | 30 |
3 files changed, 25 insertions, 23 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 3300a75..f17ae22 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -719,12 +719,12 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): def sizeof(self, typename: str, prefix: str, env: 'Environment', *, extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None, - dependencies: T.Optional[T.List['Dependency']] = None) -> int: + dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[int, bool]: raise EnvironmentException('Language %s does not support sizeof checks.' % self.get_display_language()) def alignment(self, typename: str, prefix: str, env: 'Environment', *, extra_args: T.Optional[T.List[str]] = None, - dependencies: T.Optional[T.List['Dependency']] = None) -> int: + dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[int, bool]: raise EnvironmentException('Language %s does not support alignment checks.' % self.get_display_language()) def has_function(self, funcname: str, prefix: str, env: 'Environment', *, diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 90c0498..15b22d6 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -735,7 +735,7 @@ class DCompiler(Compiler): def sizeof(self, typename: str, prefix: str, env: 'Environment', *, extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None, - dependencies: T.Optional[T.List['Dependency']] = None) -> int: + dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[int, bool]: if extra_args is None: extra_args = [] t = f''' @@ -745,17 +745,17 @@ class DCompiler(Compiler): writeln(({typename}).sizeof); }} ''' - res = self.run(t, env, extra_args=extra_args, - dependencies=dependencies) + res = self.cached_run(t, env, extra_args=extra_args, + dependencies=dependencies) if not res.compiled: - return -1 + return -1, False if res.returncode != 0: raise mesonlib.EnvironmentException('Could not run sizeof test binary.') - return int(res.stdout) + return int(res.stdout), res.cached def alignment(self, typename: str, prefix: str, env: 'Environment', *, extra_args: T.Optional[T.List[str]] = None, - dependencies: T.Optional[T.List['Dependency']] = None) -> int: + dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[int, bool]: if extra_args is None: extra_args = [] t = f''' @@ -774,7 +774,7 @@ class DCompiler(Compiler): align = int(res.stdout) if align == 0: raise mesonlib.EnvironmentException(f'Could not determine alignment of {typename}. Sorry. You might want to file a bug.') - return align + return align, res.cached def has_header(self, hname: str, prefix: str, env: 'Environment', *, extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None, diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index d44dd4d..200f4a2 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -591,25 +591,26 @@ class CLikeCompiler(Compiler): def sizeof(self, typename: str, prefix: str, env: 'Environment', *, extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None, - dependencies: T.Optional[T.List['Dependency']] = None) -> int: + dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[int, bool]: if extra_args is None: extra_args = [] if self.is_cross: - return self.cross_sizeof(typename, prefix, env, extra_args=extra_args, - dependencies=dependencies) + r = self.cross_sizeof(typename, prefix, env, extra_args=extra_args, + dependencies=dependencies) + return r, False t = f'''#include<stdio.h> {prefix} int main(void) {{ printf("%ld\\n", (long)(sizeof({typename}))); return 0; }}''' - res = self.run(t, env, extra_args=extra_args, - dependencies=dependencies) + res = self.cached_run(t, env, extra_args=extra_args, + dependencies=dependencies) if not res.compiled: - return -1 + return -1, False if res.returncode != 0: raise mesonlib.EnvironmentException('Could not run sizeof test binary.') - return int(res.stdout) + return int(res.stdout), res.cached def cross_alignment(self, typename: str, prefix: str, env: 'Environment', *, extra_args: T.Optional[T.List[str]] = None, @@ -635,12 +636,13 @@ class CLikeCompiler(Compiler): def alignment(self, typename: str, prefix: str, env: 'Environment', *, extra_args: T.Optional[T.List[str]] = None, - dependencies: T.Optional[T.List['Dependency']] = None) -> int: + dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[int, bool]: if extra_args is None: extra_args = [] if self.is_cross: - return self.cross_alignment(typename, prefix, env, extra_args=extra_args, - dependencies=dependencies) + r = self.cross_alignment(typename, prefix, env, extra_args=extra_args, + dependencies=dependencies) + return r, False t = f'''#include <stdio.h> #include <stddef.h> {prefix} @@ -652,8 +654,8 @@ class CLikeCompiler(Compiler): printf("%d", (int)offsetof(struct tmp, target)); return 0; }}''' - res = self.run(t, env, extra_args=extra_args, - dependencies=dependencies) + res = self.cached_run(t, env, extra_args=extra_args, + dependencies=dependencies) if not res.compiled: raise mesonlib.EnvironmentException('Could not compile alignment test.') if res.returncode != 0: @@ -661,7 +663,7 @@ class CLikeCompiler(Compiler): align = int(res.stdout) if align == 0: raise mesonlib.EnvironmentException(f'Could not determine alignment of {typename}. Sorry. You might want to file a bug.') - return align + return align, res.cached def get_define(self, dname: str, prefix: str, env: 'Environment', extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]]], @@ -1117,7 +1119,7 @@ class CLikeCompiler(Compiler): ''' returns true if the output produced is 64-bit, false if 32-bit ''' - return self.sizeof('void *', '', env) == 8 + return self.sizeof('void *', '', env)[0] == 8 def _find_library_real(self, libname: str, env: 'Environment', extra_dirs: T.List[str], code: str, libtype: LibType) -> T.Optional[T.List[str]]: # First try if we can just add the library as -l. |