Skip to content

Remove str from build.CustomTarget sources#15595

Open
bonzini wants to merge 14 commits intomesonbuild:masterfrom
bonzini:redo14885
Open

Remove str from build.CustomTarget sources#15595
bonzini wants to merge 14 commits intomesonbuild:masterfrom
bonzini:redo14885

Conversation

@bonzini
Copy link
Contributor

@bonzini bonzini commented Mar 4, 2026

This is inspired by #14885, which reported that a source of type str to a custom target would be exported to the introspection data as os.path.join(meson_root, relative_path).

However, considering that the testcase for it had to use i18n.merge_file, I checked instead whether str sources could be removed altogether. It seems like they can, and the hardest part is actually getting mypy to comply.

I'm still not 100% sure about the handling of the get_outputs() case in the qt module, so I'm marking this as draft until I write a testcase for that.

Fixes: #2748

@bonzini
Copy link
Contributor Author

bonzini commented Mar 4, 2026

#9012 never worked for compile_resources because the call to _parse_qrc_deps fails to find the generated file.

This can be seen with this test:

diff --git a/test cases/frameworks/4 qt/subfolder/copyfile.py b/test cases/frameworks/4 qt/subfolder/copyfile.py
new file mode 100644
index 000000000..ff42ac359
--- /dev/null
+++ b/test cases/frameworks/4 qt/subfolder/copyfile.py	
@@ -0,0 +1,6 @@
+#!/usr/bin/env python3
+
+import sys
+import shutil
+
+shutil.copyfile(sys.argv[1], sys.argv[2])
diff --git a/test cases/frameworks/4 qt/subfolder/meson.build b/test cases/frameworks/4 qt/subfolder/meson.build
index f1b84e6ae..2295b1993 100644
--- a/test cases/frameworks/4 qt/subfolder/meson.build	
+++ b/test cases/frameworks/4 qt/subfolder/meson.build	
@@ -30,3 +30,8 @@ endif
 
 app = executable('subfolder', 'main.cpp', qresources, dependencies : qtdep, cpp_args: extra_cpp_args)
 test(qt + 'subfolder', app)
+
+# Test compile_resources with a custom_target source, to ensure that
+# custom target outputs are correctly converted to File objects.
+ct_qrc = custom_target('stuff3_ct.qrc', output: 'stuff3_ct.qrc', input: 'resources/stuff3.qrc', command: ['python3', files('copyfile.py'), '@INPUT@', '@OUTPUT@'])
+qtmodule.compile_resources(sources : ct_qrc, method : get_option('method'))

@bonzini bonzini force-pushed the redo14885 branch 2 times, most recently from f6be0ae to 9f0dad1 Compare March 10, 2026 17:13
@bonzini bonzini added this to the 1.12 milestone Mar 10, 2026
@bonzini bonzini marked this pull request as ready for review March 10, 2026 17:13
@bonzini bonzini requested a review from jpakkane as a code owner March 10, 2026 17:13
@bonzini bonzini added refactoring No behavior changes and removed bug labels Mar 11, 2026
@bonzini bonzini force-pushed the redo14885 branch 2 times, most recently from 8bbb447 to 669faa7 Compare March 11, 2026 12:10
bonzini added 7 commits March 16, 2026 13:50
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The changes introduced by PR 9012 never worked for compile_resources
because the call to _parse_qrc_deps fails to find the generated file.
Raise an error similar to the one in gnome.compile_resources().

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
…om_target input

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@bonzini bonzini force-pushed the redo14885 branch 2 times, most recently from a7a4a6e to 8f6ec77 Compare March 16, 2026 13:01
bonzini added 7 commits March 16, 2026 16:33
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
"j" is used in an earlier loop iterating target.sources.  Before changing the
type of the sources, rename the variable.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The function is using source_strings_to_files, and that makes
it trivial to pass generated sources to the CustomTarget
constructor.

Fixes: mesonbuild#2748
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring No behavior changes typing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to use output of custom_target as a source for gnome.genmarshal

1 participant