diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-02-20 11:18:00 -0500 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-05-31 11:59:39 -0400 |
commit | d17e3ce6ba0a22f449c9bcb82d67281048c776e9 (patch) | |
tree | 98bc49bb7236913901d6f6e911d2e2a3b98289e1 | |
parent | 95b03f793028968a4a6df7fe25358fd8c5d39a0c (diff) | |
download | meson-d17e3ce6ba0a22f449c9bcb82d67281048c776e9.zip meson-d17e3ce6ba0a22f449c9bcb82d67281048c776e9.tar.gz meson-d17e3ce6ba0a22f449c9bcb82d67281048c776e9.tar.bz2 |
preprocess: Allow preprocessing any file extensions
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 10 | ||||
-rw-r--r-- | test cases/common/259 preprocess/meson.build | 6 |
2 files changed, 11 insertions, 5 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 19da249..5aeaa48 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -856,6 +856,10 @@ class NinjaBackend(backends.Backend): self.generate_swift_target(target) return + # CompileTarget compiles all its sources and does not do a final link. + # This is, for example, a preprocessor. + is_compile_target = isinstance(target, build.CompileTarget) + # Preexisting target C/C++ sources to be built; dict of full path to # source relative to build root and the original File object. target_sources: T.MutableMapping[str, File] @@ -922,6 +926,8 @@ class NinjaBackend(backends.Backend): obj_list.append(rel_src) elif self.environment.is_library(rel_src) or modules.is_module_library(rel_src): pass + elif is_compile_target: + generated_source_files.append(raw_src) else: # Assume anything not specifically a source file is a header. This is because # people generate files with weird suffixes (.inc, .fh) that they then include @@ -992,7 +998,7 @@ class NinjaBackend(backends.Backend): # Generate compile targets for all the preexisting sources for this target for src in target_sources.values(): - if not self.environment.is_header(src): + if not self.environment.is_header(src) or is_compile_target: if self.environment.is_llvm_ir(src): o, s = self.generate_llvm_ir_compile(target, src) obj_list.append(o) @@ -1015,7 +1021,7 @@ class NinjaBackend(backends.Backend): obj_list.append(o) compiled_sources.append(s) source2object[s] = o - if isinstance(target, build.CompileTarget): + if is_compile_target: # Skip the link stage for this special type of target return linker, stdlib_args = self.determine_linker_and_stdlib_args(target) diff --git a/test cases/common/259 preprocess/meson.build b/test cases/common/259 preprocess/meson.build index 2650166..5107427 100644 --- a/test cases/common/259 preprocess/meson.build +++ b/test cases/common/259 preprocess/meson.build @@ -6,16 +6,16 @@ add_project_arguments(['-DFOO=0', '-DBAR=0'], language: 'c') fs = import('fs') bar_content = fs.read('bar.c') -bar_c = custom_target( +bar_x = custom_target( input: 'bar.c', - output: 'bar.c', + output: 'bar.x', command: ['python3', '-c', '''import sys;print(sys.argv[1].replace('@BAR@', 'bar'))''', bar_content], capture: true, ) dep = declare_dependency(compile_args: '-DPLOP=0') -pp_files = cc.preprocess('foo.c', bar_c, output: '@PLAINNAME@', dependencies: dep) +pp_files = cc.preprocess('foo.c', bar_x, output: '@PLAINNAME@.c', dependencies: dep) foreach f : pp_files message(f.full_path()) |