# Buggy code
def generate_target_install(self, d):
    for t in self.build.get_targets().values():
        if not t.should_install():
            continue
        outdirs, custom_install_dir = self.get_target_install_dirs(t)
        # Sanity-check the outputs and install_dirs
        num_outdirs, num_out = len(outdirs), len(t.get_outputs())
        if num_outdirs != 1 and num_outdirs != num_out:
            m = (
                'Target {!r} has {} outputs: {!r}, but only {} "install_dir"s were found.\n'
                "Pass 'false' for outputs that should not be installed and 'true' for\n"
                "using the default installation directory for an output."
            )
            raise MesonException(
                m.format(t.name, num_out, t.get_outputs(), num_outdirs)
            )
        install_mode = t.get_custom_install_mode()
        # Install the target output(s)
        if isinstance(t, build.BuildTarget):
            should_strip = self.get_option_for_target("strip", t)
            # Install primary build output (library/executable/jar, etc)
            # Done separately because of strip/aliases/rpath
            if outdirs[0] is not False:
                mappings = self.get_target_link_deps_mappings(t, d.prefix)
                i = TargetInstallData(
                    self.get_target_filename(t),
                    outdirs[0],
                    t.get_aliases(),
                    should_strip,
                    mappings,
                    t.install_rpath,
                    install_mode,
                )
                d.targets.append(i)
                # On toolchains/platforms that use an import library for
                # linking (separate from the shared library with all the
                # code), we need to install that too (dll.a/.lib).
                if (
                    isinstance(
                        t, (build.SharedLibrary, build.SharedModule, build.Executable)
                    )
                    and t.get_import_filename()
                ):
                    if custom_install_dir:
                        # If the DLL is installed into a custom directory,
                        # install the import library into the same place so
                        # it doesn't go into a surprising place
                        implib_install_dir = outdirs[0]
                    else:
                        implib_install_dir = self.environment.get_import_lib_dir()
                    # Install the import library.
                    i = TargetInstallData(
                        self.get_target_filename_for_linking(t),
                        implib_install_dir,
                        {},
                        False,
                        {},
                        "",
                        install_mode,
                    )
                    d.targets.append(i)
            # Install secondary outputs. Only used for Vala right now.
            if num_outdirs > 1:
                for output, outdir in zip(t.get_outputs()[1:], outdirs[1:]):
                    # User requested that we not install this output
                    if outdir is False:
                        continue
                    f = os.path.join(self.get_target_dir(t), output)
                    i = TargetInstallData(f, outdir, {}, False, {}, None, install_mode)
                    d.targets.append(i)
        elif isinstance(t, build.CustomTarget):
            # If only one install_dir is specified, assume that all
            # outputs will be installed into it. This is for
            # backwards-compatibility and because it makes sense to
            # avoid repetition since this is a common use-case.
            #
            # To selectively install only some outputs, pass `false` as
            # the install_dir for the corresponding output by index
            if num_outdirs == 1 and num_out > 1:
                for output in t.get_outputs():
                    f = os.path.join(self.get_target_dir(t), output)
                    i = TargetInstallData(
                        f, outdirs[0], {}, False, {}, None, install_mode
                    )
                    d.targets.append(i)
            else:
                for output, outdir in zip(t.get_outputs(), outdirs):
                    # User requested that we not install this output
                    if outdir is False:
                        continue
                    f = os.path.join(self.get_target_dir(t), output)
                    i = TargetInstallData(f, outdir, {}, False, {}, None, install_mode)
                    d.targets.append(i)


# Traceback (FileNotFoundError)
Traceback (most recent call last):
File "d:\\projects\\cerbero\\meson\\master\\build\\build-tools\\Scripts\\meson.py", line 4, in <module>
__import__('pkg_resources').run_script('meson==0.47.0', 'meson.py')
File "c:\Python36-32\lib\site-packages\pkg_resources\__init__.py", line 658, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "c:\Python36-32\lib\site-packages\pkg_resources\__init__.py", line 1438, in run_script
exec(code, namespace, namespace)
File "d:\projects\cerbero\meson\master\build\build-tools\lib\site-packages\meson-0.47.0-py3.6.egg\EGG-INFO\scripts\meson.py", line 29, in <module>
sys.exit(mesonmain.main())
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\mesonmain.py", line 367, in main
return run(sys.argv[1:], launcher)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\mesonmain.py", line 281, in run
return minstall.run(remaining_args)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 466, in run
installer.do_install(datafilename)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 298, in do_install
self.install_targets(d)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 387, in install_targets
fname = check_for_stampfile(t.fname)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 170, in check_for_stampfile
if os.stat(fname).st_size == 0:
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'tls/gnutls\\giognutls.lib'
FAILED: meson-install
"c:\\Python36-32\\python.exe" "d:\\projects\\cerbero\\meson\\master\\build\\build-tools\\Scripts\\meson.py" "install" "--no-rebuild"
ninja: build stopped: subcommand failed.

# Fixed code
def generate_target_install(self, d):
    for t in self.build.get_targets().values():
        if not t.should_install():
            continue
        outdirs, custom_install_dir = self.get_target_install_dirs(t)
        # Sanity-check the outputs and install_dirs
        num_outdirs, num_out = len(outdirs), len(t.get_outputs())
        if num_outdirs != 1 and num_outdirs != num_out:
            m = (
                'Target {!r} has {} outputs: {!r}, but only {} "install_dir"s were found.\n'
                "Pass 'false' for outputs that should not be installed and 'true' for\n"
                "using the default installation directory for an output."
            )
            raise MesonException(
                m.format(t.name, num_out, t.get_outputs(), num_outdirs)
            )
        install_mode = t.get_custom_install_mode()
        # Install the target output(s)
        if isinstance(t, build.BuildTarget):
            should_strip = self.get_option_for_target("strip", t)
            # Install primary build output (library/executable/jar, etc)
            # Done separately because of strip/aliases/rpath
            if outdirs[0] is not False:
                mappings = self.get_target_link_deps_mappings(t, d.prefix)
                i = TargetInstallData(
                    self.get_target_filename(t),
                    outdirs[0],
                    t.get_aliases(),
                    should_strip,
                    mappings,
                    t.install_rpath,
                    install_mode,
                )
                d.targets.append(i)
                # On toolchains/platforms that use an import library for
                # linking (separate from the shared library with all the
                # code), we need to install that too (dll.a/.lib).
                if (
                    isinstance(
                        t, (build.SharedLibrary, build.SharedModule, build.Executable)
                    )
                    and t.get_import_filename()
                ):
                    if custom_install_dir:
                        # If the DLL is installed into a custom directory,
                        # install the import library into the same place so
                        # it doesn't go into a surprising place
                        implib_install_dir = outdirs[0]
                    else:
                        implib_install_dir = self.environment.get_import_lib_dir()
                    # Install the import library; may not exist for shared modules
                    i = TargetInstallData(
                        self.get_target_filename_for_linking(t),
                        implib_install_dir,
                        {},
                        False,
                        {},
                        "",
                        install_mode,
                        optional=isinstance(t, build.SharedModule),
                    )
                    d.targets.append(i)
            # Install secondary outputs. Only used for Vala right now.
            if num_outdirs > 1:
                for output, outdir in zip(t.get_outputs()[1:], outdirs[1:]):
                    # User requested that we not install this output
                    if outdir is False:
                        continue
                    f = os.path.join(self.get_target_dir(t), output)
                    i = TargetInstallData(f, outdir, {}, False, {}, None, install_mode)
                    d.targets.append(i)
        elif isinstance(t, build.CustomTarget):
            # If only one install_dir is specified, assume that all
            # outputs will be installed into it. This is for
            # backwards-compatibility and because it makes sense to
            # avoid repetition since this is a common use-case.
            #
            # To selectively install only some outputs, pass `false` as
            # the install_dir for the corresponding output by index
            if num_outdirs == 1 and num_out > 1:
                for output in t.get_outputs():
                    f = os.path.join(self.get_target_dir(t), output)
                    i = TargetInstallData(
                        f, outdirs[0], {}, False, {}, None, install_mode
                    )
                    d.targets.append(i)
            else:
                for output, outdir in zip(t.get_outputs(), outdirs):
                    # User requested that we not install this output
                    if outdir is False:
                        continue
                    f = os.path.join(self.get_target_dir(t), output)
                    i = TargetInstallData(f, outdir, {}, False, {}, None, install_mode)
                    d.targets.append(i)