Repository: mesonbuild/meson

Issue:
qt5.compile_translations regression
**Describe the bug**
Since a recent meson version, the attached meson.build doesn't build anymore but fails with the following error
```
ERROR: Target 'qt5-compile-de.ts' has 1 outputs: ['de.qm'], but only 12 "install_dir"s were found.
Pass 'false' for outputs that should not be installed and 'true' for
using the default installation directory for an output.
```
git bisect leads to the following commit:
```
11f96380351a88059ec55f1070fdebc1b1033117 is the first bad commit
commit 11f96380351a88059ec55f1070fdebc1b1033117
Author: Dylan Baker <dylan@pnwbakers.com>
Date:   Wed Jan 19 12:42:25 2022 -0800

    build: replace kwargs in CustomTarget initializer
    
    Because we don't want to pass the Interpreter kwargs into the build
    layer. This turned out to be a mega commit, as there's really on elegant
    way to make this change in an incremental way. On the nice side, mypy
    made this change super easy, as nearly all of the calls to
    `CustomTarget` are fully type checked!
    
    It also turns out that we're not handling install_tags in custom_target
    correctly, since we're not converting the boolean values into Optional
    values!
```

**To Reproduce**
```
project('foobar', 'c',
        version : '0.0.1',
        meson_version : '>=0.44.0')

qt5 = import('qt5')
qt5.compile_translations(ts_files : ['de.ts'],
                         install : true,
                         install_dir : join_paths(get_option('datadir'), 'foobar'),
                         build_by_default: true)
```

**Expected behavior**
meson should understand this, as before.

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)?
  * plain native build
* what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
  * arch linux
* what Python version are you using e.g. 3.8.0
  * Python 3.10.4
* what `meson --version`
  * Tried both 0.62.0 and git master
* what `ninja --version` if it's a Ninja build
  * 1.10.2


Discussion:
I get the same problem. (meson version 0.62.1) The error message made me think, that removing the install_dir argument might fix the issue. However, after removal I get a traceback:

```
Traceback (most recent call last):                                                                  
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/mesonmain.py", line 153, in run
    return options.run_func(options)
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/msetup.py", line 301, in run
    app.generate()
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/msetup.py", line 185, in generate
    self._generate(env)
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/msetup.py", line 247, in _generate
    intr.backend.generate()
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/backend/ninjabackend.py", line 558, in generate
    self.generate_install()
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/backend/ninjabackend.py", line 1124, in generate_install
    self.create_install_data_files()
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/backend/backends.py", line 1525, in create_install_data_files
    pickle.dump(self.create_install_data(), ofile)
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/backend/backends.py", line 1512, in create_install_data
    self.generate_target_install(d)
  File "/home/hmoebius/.local/lib/python3.9/site-packages/mesonbuild/backend/backends.py", line 1663, in generate_target_install
    dir_name = os.path.join('{prefix}', outdir)
  File "/usr/lib/python3.9/posixpath.py", line 90, in join
    genericpath._check_arg_types('join', a, *p)
  File "/usr/lib/python3.9/genericpath.py", line 152, in _check_arg_types
    raise TypeError(f'{funcname}() argument must be str, bytes, or '
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'NoneType'

ERROR: Unhandled python exception

    This is a Meson bug and should be reported!
```

Resolving patch:
diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py
--- a/mesonbuild/modules/qt.py
+++ b/mesonbuild/modules/qt.py
@@ -546,7 +546,8 @@ def compile_translations(self, state: 'ModuleState', args: T.Tuple, kwargs: 'Com
         if any(isinstance(s, (build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)) for s in ts_files):
             FeatureNew.single_use('qt.compile_translations: custom_target or generator for "ts_files" keyword argument',
                                   '0.60.0', state.subproject, location=state.current_node)
-        install_dir = kwargs['install_dir']
+        if kwargs['install'] and not kwargs['install_dir']:
+            raise MesonException('qt.compile_translations: "install_dir" keyword argument must be set when "install" is true.')
         qresource = kwargs['qresource']
         if qresource:
             if ts_files:
@@ -593,7 +594,7 @@ def compile_translations(self, state: 'ModuleState', args: T.Tuple, kwargs: 'Com
                 [ts],
                 ['@BASENAME@.qm'],
                 install=kwargs['install'],
-                install_dir=install_dir,
+                install_dir=[kwargs['install_dir']],
                 install_tag=['i18n'],
                 build_by_default=kwargs['build_by_default'],
             )


Test patch: