aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/mixins/clike.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-10-13 13:54:10 -0400
committerXavier Claessens <xavier.claessens@collabora.com>2022-10-23 12:21:46 +0200
commit5e0f22896f7e007d790c9b606e7b7a940470eff0 (patch)
tree40e4915ba4760c404fef89af934534aa5ba0df59 /mesonbuild/compilers/mixins/clike.py
parentaf6d70a1768e8611cbd937be5b8c8fd18e3f49f1 (diff)
downloadmeson-5e0f22896f7e007d790c9b606e7b7a940470eff0.zip
meson-5e0f22896f7e007d790c9b606e7b7a940470eff0.tar.gz
meson-5e0f22896f7e007d790c9b606e7b7a940470eff0.tar.bz2
Compilers: Add a preprocessor mode for clike compilers
A compiler object can now return a list of "modes", they are new compiler object specialized for a specific task.
Diffstat (limited to 'mesonbuild/compilers/mixins/clike.py')
-rw-r--r--mesonbuild/compilers/mixins/clike.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index cc78639..e1baa84 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -27,6 +27,7 @@ import itertools
import os
import re
import subprocess
+import copy
import typing as T
from pathlib import Path
@@ -145,6 +146,8 @@ class CLikeCompiler(Compiler):
self.exe_wrapper = None
else:
self.exe_wrapper = exe_wrapper
+ # Lazy initialized in get_preprocessor()
+ self.preprocessor: T.Optional[Compiler] = None
def compiler_args(self, args: T.Optional[T.Iterable[str]] = None) -> CLikeCompilerArgs:
# This is correct, mypy just doesn't understand co-operative inheritance
@@ -1328,3 +1331,18 @@ class CLikeCompiler(Compiler):
def get_disable_assert_args(self) -> T.List[str]:
return ['-DNDEBUG']
+
+ @functools.lru_cache(maxsize=None)
+ def can_compile(self, src: 'mesonlib.FileOrString') -> bool:
+ # Files we preprocess can be anything, e.g. .in
+ if self.mode == 'PREPROCESSOR':
+ return True
+ return super().can_compile(src)
+
+ def get_preprocessor(self) -> Compiler:
+ if not self.preprocessor:
+ self.preprocessor = copy.copy(self)
+ self.preprocessor.exelist = self.exelist + self.get_preprocess_to_file_args()
+ self.preprocessor.mode = 'PREPROCESSOR'
+ self.modes.append(self.preprocessor)
+ return self.preprocessor