From 238710cfab18da9d7c4091133b57e0bf638a6020 Mon Sep 17 00:00:00 2001
From: Jussi Pakkanen <jpakkane@gmail.com>
Date: Mon, 1 Oct 2018 20:31:48 +0300
Subject: [PATCH] Fix handling generated .desktop files. Closes #4304.

---
 mesonbuild/modules/i18n.py                    | 22 ++++++++++---------
 .../6 gettext/generated/desktopgenerator.py   |  9 ++++++++
 .../6 gettext/generated/meson.build           | 14 ++++++++++++
 .../generated/something.desktop.in.in         | 15 +++++++++++++
 test cases/frameworks/6 gettext/meson.build   |  1 +
 5 files changed, 51 insertions(+), 10 deletions(-)
 create mode 100644 test cases/frameworks/6 gettext/generated/desktopgenerator.py
 create mode 100644 test cases/frameworks/6 gettext/generated/meson.build
 create mode 100644 test cases/frameworks/6 gettext/generated/something.desktop.in.in

diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
index 0fc052b778..8b5e18162f 100644
--- mesonbuild/modules/i18n.py
+++ mesonbuild/modules/i18n.py
@@ -82,17 +82,19 @@ def merge_file(self, state, args, kwargs):
         kwargs['command'] = command
 
         inputfile = kwargs['input']
-        if isinstance(inputfile, str):
-            inputfile = mesonlib.File.from_source_file(state.environment.source_dir,
+        if hasattr(inputfile, 'held_object'):
+            ct = build.CustomTarget(kwargs['output'] + '_merge', state.subdir, state.subproject, kwargs)
+        else:
+            if isinstance(inputfile, str):
+                inputfile = mesonlib.File.from_source_file(state.environment.source_dir,
                                                        state.subdir, inputfile)
-        output = kwargs['output']
-        ifile_abs = inputfile.absolute_path(state.environment.source_dir,
-                                            state.environment.build_dir)
-        values = mesonlib.get_filenames_templates_dict([ifile_abs], None)
-        outputs = mesonlib.substitute_values([output], values)
-        output = outputs[0]
-
-        ct = build.CustomTarget(output + '_' + state.subdir + '_merge', state.subdir, state.subproject, kwargs)
+            output = kwargs['output']
+            ifile_abs = inputfile.absolute_path(state.environment.source_dir,
+                                                state.environment.build_dir)
+            values = mesonlib.get_filenames_templates_dict([ifile_abs], None)
+            outputs = mesonlib.substitute_values([output], values)
+            output = outputs[0]
+            ct = build.CustomTarget(output + '_' + state.subdir + '_merge', state.subdir, state.subproject, kwargs)
         return ModuleReturnValue(ct, [ct])
 
     @FeatureNewKwargs('i18n.gettext', '0.37.0', ['preset'])
