Repository: mesonbuild/meson

Issue:
Regression when passing custom target as input file to gnome.compile_resources
**Describe the bug**
Sometime between Meson 0.59 and 0.61, passing a custom target as the XML file to gnome.compile_resources broke. It was probably sketchy to do that in the first place, so it wouldn't be so bad, except that there no longer seems to be an obvious way to achieve the same thing.
(This bug is kind of the reverse of #5017.)

**To Reproduce**
```meson
project('example', 'c')
gnome = import('gnome')
generated_gresource_xml = custom_target('generated-gresource-xml',
    output: 'my.gresource.xml', capture: true,
    command: ['echo', '<?xml version="1.0" encoding="UTF-8"?><gresources/>'])
resources_generated = gnome.compile_resources('resources-generated',
    generated_gresource_xml)
```
This logs the following error:
> ../meson.build:6:0: ERROR: gnome.compile_resources argument 2 was of type "CustomTarget" but should have been one of: "str", "File"

I've tried to work around it by using the custom target's `full_path()` and adding the custom target to the dependencies keyword arg. (i.e., `gnome.compile_resources('resources-generated', generated_gresource_xml.full_path(), dependencies: generated_gresource_xml)`) This logs the following error:
> ninja: error: '/var/home/ptomato/workspace/scratch/res/_build/my.gresource.xml', needed by 'resources-generated.c', missing and no known rule to make it

So despite it being included in `dependencies`, it's not made first. However, if you ask for it specifically with `ninja my.gresource.xml`, it does get built.

**Expected behavior**
On running the build, `my.gresource.xml` should first be generated, then subsequently used as input for the `compile_resources` call. This worked correctly under 0.59.

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)? native build
* what operating system? Fedora Silverblue 35, Meson installed via `pip3 install --user`
* what Python version are you using? 3.10.2
* what `meson --version`? 0.61.0
* what `ninja --version` if it's a Ninja build? 1.10.2



Discussion:
(Although I guess it can be worked around after all, using `configure_file()` with a bogus `input` argument instead of `custom_target()`)
I have exactly the same problem in fwupd, I'm doing something like this as a workaround:

	fwupd_gresource_xml = custom_target('fwupd-resources-xml',
	  input : [
	    'org.freedesktop.fwupd.xml',
	  ],
	  output : 'fwupd.gresource.xml',
	  command : [
	    join_paths(meson.project_source_root(), 'contrib', 'generate-gresource-xml.py'), '@OUTPUT@', '@INPUT@',
	  ],
	)
	resources_src = gnome.compile_resources(
	  'fwupd-resources',
	  join_paths(meson.current_build_dir(), 'fwupd.gresource.xml'),
	  dependencies: fwupd_gresource_xml,
	  source_dir: '.',
	  c_name: 'fu'
	)

when what I want to be doing is...

	fwupd_gresource_xml = custom_target('fwupd-resources-xml',
	  input : [
	    'org.freedesktop.fwupd.xml',
	  ],
	  output : 'fwupd.gresource.xml',
	  command : [
	    join_paths(meson.project_source_root(), 'contrib', 'generate-gresource-xml.py'), '@OUTPUT@', '@INPUT@',
	  ],
	)
	resources_src = gnome.compile_resources(
	  'fwupd-resources',
	  fwupd_gresource_xml,
	  source_dir: '.',
	  c_name: 'fu'
	)

Doing the latter I get:

    meson.build: ERROR: gnome.compile_resources argument 2 was of type "CustomTarget" but should have been one of: "str", "File"


Resolving patch:
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -371,7 +371,7 @@ def post_install(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: '
             rv.append(script)
         return ModuleReturnValue(None, rv)
 
-    @typed_pos_args('gnome.compile_resources', str, (str, mesonlib.File))
+    @typed_pos_args('gnome.compile_resources', str, (str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList))
     @typed_kwargs(
         'gnome.compile_resources',
         _BUILD_BY_DEFAULT,
@@ -426,6 +426,13 @@ def compile_resources(self, state: 'ModuleState', args: T.Tuple[str, 'FileOrStri
                     ifile = os.path.join(state.environment.get_build_dir(), input_file.subdir, input_file.fname)
                 else:
                     ifile = os.path.join(input_file.subdir, input_file.fname)
+
+            elif isinstance(input_file, (build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)):
+                raise MesonException('Resource xml files generated at build-time cannot be used with '
+                                     'gnome.compile_resources() in the current version of glib-compile-resources '
+                                     'because we need to scan the xml for dependencies due to '
+                                     '<https://bugzilla.gnome.org/show_bug.cgi?id=774368>\nUse '
+                                     'configure_file() instead to generate it at configure-time.')
             else:
                 ifile = os.path.join(state.subdir, input_file)
 


Test patch: