From 1d15c6f5022565e0ac029daa18be8b9c3a7e2ad0 Mon Sep 17 00:00:00 2001 From: Remi Thebault Date: Sun, 5 Jun 2022 01:35:02 +0200 Subject: [PATCH 1/2] add D generated files to order-only deps --- mesonbuild/backend/ninjabackend.py | 11 +++++++++-- test cases/d/16 code generation/exe.d | 9 +++++++++ test cases/d/16 code generation/generator.d | 13 +++++++++++++ test cases/d/16 code generation/input.txt | 1 + test cases/d/16 code generation/meson.build | 18 ++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 test cases/d/16 code generation/exe.d create mode 100644 test cases/d/16 code generation/generator.d create mode 100644 test cases/d/16 code generation/input.txt create mode 100644 test cases/d/16 code generation/meson.build diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 1b5937207..e9a435fb7 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -833,6 +833,11 @@ class NinjaBackend(backends.Backend): # people generate files with weird suffixes (.inc, .fh) that they then include # in their source files. header_deps.append(raw_src) + + # For D language, the object of generated source files are added + # as order only deps because other files may depend on them + d_generated_deps = [] + # These are the generated source files that need to be built for use by # this target. We create the Ninja build file elements for this here # because we need `header_deps` to be fully generated in the above loop. @@ -845,6 +850,8 @@ class NinjaBackend(backends.Backend): compiled_sources.append(s) source2object[s] = o obj_list.append(o) + if s.endswith('.d'): + d_generated_deps.append(o) use_pch = self.environment.coredata.options.get(OptionKey('b_pch')) if use_pch and target.has_pch(): @@ -891,7 +898,7 @@ class NinjaBackend(backends.Backend): src.rel_to_builddir(self.build_to_src)) unity_src.append(abs_src) else: - o, s = self.generate_single_compile(target, src, False, [], header_deps) + o, s = self.generate_single_compile(target, src, False, [], header_deps + d_generated_deps) obj_list.append(o) compiled_sources.append(s) source2object[s] = o @@ -899,7 +906,7 @@ class NinjaBackend(backends.Backend): obj_list += self.flatten_object_list(target) if is_unity: for src in self.generate_unity_files(target, unity_src): - o, s = self.generate_single_compile(target, src, True, unity_deps + header_deps) + o, s = self.generate_single_compile(target, src, True, unity_deps + header_deps + d_generated_deps) obj_list.append(o) compiled_sources.append(s) source2object[s] = o diff --git a/test cases/d/16 code generation/exe.d b/test cases/d/16 code generation/exe.d new file mode 100644 index 000000000..0e24d6d5a --- /dev/null +++ b/test cases/d/16 code generation/exe.d @@ -0,0 +1,9 @@ +module exe; + +import generated; +import std.stdio; + +int main() +{ + return generatedString() == "Some text to be returned by generated code" ? 0 : 1; +} diff --git a/test cases/d/16 code generation/generator.d b/test cases/d/16 code generation/generator.d new file mode 100644 index 000000000..f944dd39f --- /dev/null +++ b/test cases/d/16 code generation/generator.d @@ -0,0 +1,13 @@ +module generator; + +import std.file; +import std.stdio; +import std.string; + +void main(string[] args) +{ + const text = cast(string)read(args[1]); + + writeln("module generated;"); + writefln!`string generatedString() { return "%s"; }`(text.strip()); +} diff --git a/test cases/d/16 code generation/input.txt b/test cases/d/16 code generation/input.txt new file mode 100644 index 000000000..aebcda848 --- /dev/null +++ b/test cases/d/16 code generation/input.txt @@ -0,0 +1 @@ +Some text to be returned by generated code diff --git a/test cases/d/16 code generation/meson.build b/test cases/d/16 code generation/meson.build new file mode 100644 index 000000000..2418acab5 --- /dev/null +++ b/test cases/d/16 code generation/meson.build @@ -0,0 +1,18 @@ +project('meson-dep-test', 'd') + +generator = executable('generator', 'generator.d') + +generated = custom_target('generated', + capture: true, + output: 'generated.d', + input: 'input.txt', + command: [ + generator, '@INPUT@' + ] +) + +exe = executable('exe', generated, 'exe.d', + include_directories: include_directories('.'), +) + +test('test exe', exe) From e9576a43611d751a8405525cf32ee0109787d161 Mon Sep 17 00:00:00 2001 From: Remi Thebault Date: Thu, 9 Jun 2022 21:19:56 +0200 Subject: [PATCH 2/2] use compilers.lang_suffixes to determine lang --- mesonbuild/backend/ninjabackend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e9a435fb7..591865c34 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -850,7 +850,7 @@ class NinjaBackend(backends.Backend): compiled_sources.append(s) source2object[s] = o obj_list.append(o) - if s.endswith('.d'): + if s.split('.')[-1] in compilers.lang_suffixes['d']: d_generated_deps.append(o) use_pch = self.environment.coredata.options.get(OptionKey('b_pch'))