From 5e0f22896f7e007d790c9b606e7b7a940470eff0 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 13 Oct 2022 13:54:10 -0400 Subject: 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. --- mesonbuild/compilers/mixins/clike.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'mesonbuild/compilers/mixins/clike.py') 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 -- cgit v1.1