aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/build.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-10-13 14:01:50 -0400
committerXavier Claessens <xavier.claessens@collabora.com>2022-10-23 12:21:46 +0200
commit65590e6e4b59e08d0c1a16067524479ed822ad27 (patch)
tree24ef5a84dd057754db7b0b969e5e4aa78fbc3e77 /mesonbuild/build.py
parent5e0f22896f7e007d790c9b606e7b7a940470eff0 (diff)
downloadmeson-65590e6e4b59e08d0c1a16067524479ed822ad27.zip
meson-65590e6e4b59e08d0c1a16067524479ed822ad27.tar.gz
meson-65590e6e4b59e08d0c1a16067524479ed822ad27.tar.bz2
Add cc.preprocess() method for c-like compilers
This introduce a new type of BuildTarget: CompileTarget. From ninja backend POV it is the same thing as any other build target, except that it skips the final link step. It could be used in the future for transpilers too.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r--mesonbuild/build.py43
1 files changed, 40 insertions, 3 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index bf87071..14cc235 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -2581,6 +2581,44 @@ class CustomTarget(Target, CommandBase):
def __len__(self) -> int:
return len(self.outputs)
+class CompileTarget(BuildTarget):
+ '''
+ Target that only compile sources without linking them together.
+ It can be used as preprocessor, or transpiler.
+ '''
+
+ typename = 'compile'
+
+ def __init__(self,
+ name: str,
+ subdir: str,
+ subproject: str,
+ environment: environment.Environment,
+ sources: T.List[File],
+ output_templ: str,
+ compiler: Compiler,
+ kwargs):
+ compilers = {compiler.get_language(): compiler}
+ super().__init__(name, subdir, subproject, compiler.for_machine,
+ sources, None, [], environment, compilers, kwargs)
+ self.filename = name
+ self.compiler = compiler
+ self.output_templ = output_templ
+ self.outputs = []
+ for f in sources:
+ plainname = os.path.basename(f.fname)
+ basename = os.path.splitext(plainname)[0]
+ self.outputs.append(output_templ.replace('@BASENAME@', basename).replace('@PLAINNAME@', plainname))
+ self.sources_map = dict(zip(sources, self.outputs))
+
+ def type_suffix(self) -> str:
+ return "@compile"
+
+ @property
+ def is_unity(self) -> bool:
+ return False
+
+
class RunTarget(Target, CommandBase):
typename = 'run'
@@ -2705,7 +2743,7 @@ class CustomTargetIndex(HoldableObject):
typename: T.ClassVar[str] = 'custom'
- target: CustomTarget
+ target: T.Union[CustomTarget, CompileTarget]
output: str
def __post_init__(self) -> None:
@@ -2716,8 +2754,7 @@ class CustomTargetIndex(HoldableObject):
return f'{self.target.name}[{self.output}]'
def __repr__(self):
- return '<CustomTargetIndex: {!r}[{}]>'.format(
- self.target, self.target.get_outputs().index(self.output))
+ return '<CustomTargetIndex: {!r}[{}]>'.format(self.target, self.output)
def get_outputs(self) -> T.List[str]:
return [self.output]