# Buggy code
def _generate(self, env):
    mlog.debug("Build started at", datetime.datetime.now().isoformat())
    mlog.debug("Main binary:", sys.executable)
    mlog.debug("Python system:", platform.system())
    mlog.log(mlog.bold("The Meson build system"))
    self.check_pkgconfig_envvar(env)
    mlog.log("Version:", coredata.version)
    mlog.log("Source dir:", mlog.bold(self.source_dir))
    mlog.log("Build dir:", mlog.bold(self.build_dir))
    if env.is_cross_build():
        mlog.log("Build type:", mlog.bold("cross build"))
    else:
        mlog.log("Build type:", mlog.bold("native build"))
    b = build.Build(env)
    if self.options.backend == "ninja":
        from .backend import ninjabackend

        g = ninjabackend.NinjaBackend(b)
    elif self.options.backend == "vs":
        from .backend import vs2010backend

        g = vs2010backend.autodetect_vs_version(b)
        mlog.log("Auto detected Visual Studio backend:", mlog.bold(g.name))
    elif self.options.backend == "vs2010":
        from .backend import vs2010backend

        g = vs2010backend.Vs2010Backend(b)
    elif self.options.backend == "vs2015":
        from .backend import vs2015backend

        g = vs2015backend.Vs2015Backend(b)
    elif self.options.backend == "vs2017":
        from .backend import vs2017backend

        g = vs2017backend.Vs2017Backend(b)
    elif self.options.backend == "xcode":
        from .backend import xcodebackend

        g = xcodebackend.XCodeBackend(b)
    else:
        raise RuntimeError('Unknown backend "%s".' % self.options.backend)

    intr = interpreter.Interpreter(b, g)
    if env.is_cross_build():
        mlog.log(
            "Host machine cpu family:",
            mlog.bold(intr.builtin["host_machine"].cpu_family_method([], {})),
        )
        mlog.log(
            "Host machine cpu:",
            mlog.bold(intr.builtin["host_machine"].cpu_method([], {})),
        )
        mlog.log(
            "Target machine cpu family:",
            mlog.bold(intr.builtin["target_machine"].cpu_family_method([], {})),
        )
        mlog.log(
            "Target machine cpu:",
            mlog.bold(intr.builtin["target_machine"].cpu_method([], {})),
        )
    mlog.log(
        "Build machine cpu family:",
        mlog.bold(intr.builtin["build_machine"].cpu_family_method([], {})),
    )
    mlog.log(
        "Build machine cpu:",
        mlog.bold(intr.builtin["build_machine"].cpu_method([], {})),
    )
    intr.run()
    try:
        # We would like to write coredata as late as possible since we use the existence of
        # this file to check if we generated the build file successfully. Since coredata
        # includes settings, the build files must depend on it and appear newer. However, due
        # to various kernel caches, we cannot guarantee that any time in Python is exactly in
        # sync with the time that gets applied to any files. Thus, we dump this file as late as
        # possible, but before build files, and if any error occurs, delete it.
        cdf = env.dump_coredata()
        g.generate(intr)
        dumpfile = os.path.join(env.get_scratch_dir(), "build.dat")
        with open(dumpfile, "wb") as f:
            pickle.dump(b, f)
        # Post-conf scripts must be run after writing coredata or else introspection fails.
        g.run_postconf_scripts()
    except:
        os.unlink(cdf)
        raise


# Traceback (TypeError)
1>------ Build started: Project: REGEN, Configuration: debug Win32 ------
1>Checking whether solution needs to be regenerated.
1>The Meson build system
1>Version: 0.45.0.dev1
1>Source dir: C:\msys64\home\Polarina\mysa
1>Build dir: C:\msys64\home\Polarina\mysa\build
1>Build type: native build
1>Traceback (most recent call last):
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 365, in run
1>    app.generate()
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 151, in generate
1>    self._generate(env)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 174, in _generate
1>    g = vs2010backend.autodetect_vs_version(b)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\backend\vs2010backend.py", line 38, in autodetect_vs_version
1>    if vs_version == '14.0' or 'Visual Studio 14' in vs_install_dir:
1>TypeError: argument of type 'NoneType' is not iterable
1>Traceback (most recent call last):
1>  File "C:\Users\Polarina\AppData\Local\Programs\Python\Python36-32\Scripts\meson.py", line 26, in <module>
1>    sys.exit(main())
1>  File "C:\Users\Polarina\AppData\Local\Programs\Python\Python36-32\Scripts\meson.py", line 23, in main
1>    return mesonmain.run(sys.argv[1:], launcher)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 322, in run
1>    sys.exit(run_script_command(args[1:]))
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 278, in run_script_command
1>    return cmdfunc(cmdargs)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\scripts\regen_checker.py", line 55, in run
1>    regen(regeninfo, mesonscript, backend)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\scripts\regen_checker.py", line 41, in regen
1>    subprocess.check_call(cmd)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\subprocess.py", line 291, in check_call
1>    raise CalledProcessError(retcode, cmd)
1>subprocess.CalledProcessError: Command '['c:\\users\\polarina\\appdata\\local\\programs\\python\\python36-32\\python.exe', 'C:\\Users\\Polarina\\AppData\\Local\\Programs\\Python\\Python36-32\\Scripts\\meson.py', '--internal', 'regenerate', 'C:\\msys64\\home\\Polarina\\mysa\\build', 'C:\\msys64\\home\\Polarina\\mysa', '--backend=vs']' returned non-zero exit status 1.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1.
1>Done building project "REGEN.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

# Fixed code
def _generate(self, env):
    mlog.debug("Build started at", datetime.datetime.now().isoformat())
    mlog.debug("Main binary:", sys.executable)
    mlog.debug("Python system:", platform.system())
    mlog.log(mlog.bold("The Meson build system"))
    self.check_pkgconfig_envvar(env)
    mlog.log("Version:", coredata.version)
    mlog.log("Source dir:", mlog.bold(self.source_dir))
    mlog.log("Build dir:", mlog.bold(self.build_dir))
    if env.is_cross_build():
        mlog.log("Build type:", mlog.bold("cross build"))
    else:
        mlog.log("Build type:", mlog.bold("native build"))
    b = build.Build(env)
    if self.options.backend == "ninja":
        from .backend import ninjabackend

        g = ninjabackend.NinjaBackend(b)
    elif self.options.backend == "vs":
        from .backend import vs2010backend

        g = vs2010backend.autodetect_vs_version(b)
        env.coredata.set_builtin_option("backend", g.name)
        mlog.log("Auto detected Visual Studio backend:", mlog.bold(g.name))
    elif self.options.backend == "vs2010":
        from .backend import vs2010backend

        g = vs2010backend.Vs2010Backend(b)
    elif self.options.backend == "vs2015":
        from .backend import vs2015backend

        g = vs2015backend.Vs2015Backend(b)
    elif self.options.backend == "vs2017":
        from .backend import vs2017backend

        g = vs2017backend.Vs2017Backend(b)
    elif self.options.backend == "xcode":
        from .backend import xcodebackend

        g = xcodebackend.XCodeBackend(b)
    else:
        raise RuntimeError('Unknown backend "%s".' % self.options.backend)

    intr = interpreter.Interpreter(b, g)
    if env.is_cross_build():
        mlog.log(
            "Host machine cpu family:",
            mlog.bold(intr.builtin["host_machine"].cpu_family_method([], {})),
        )
        mlog.log(
            "Host machine cpu:",
            mlog.bold(intr.builtin["host_machine"].cpu_method([], {})),
        )
        mlog.log(
            "Target machine cpu family:",
            mlog.bold(intr.builtin["target_machine"].cpu_family_method([], {})),
        )
        mlog.log(
            "Target machine cpu:",
            mlog.bold(intr.builtin["target_machine"].cpu_method([], {})),
        )
    mlog.log(
        "Build machine cpu family:",
        mlog.bold(intr.builtin["build_machine"].cpu_family_method([], {})),
    )
    mlog.log(
        "Build machine cpu:",
        mlog.bold(intr.builtin["build_machine"].cpu_method([], {})),
    )
    intr.run()
    try:
        # We would like to write coredata as late as possible since we use the existence of
        # this file to check if we generated the build file successfully. Since coredata
        # includes settings, the build files must depend on it and appear newer. However, due
        # to various kernel caches, we cannot guarantee that any time in Python is exactly in
        # sync with the time that gets applied to any files. Thus, we dump this file as late as
        # possible, but before build files, and if any error occurs, delete it.
        cdf = env.dump_coredata()
        g.generate(intr)
        dumpfile = os.path.join(env.get_scratch_dir(), "build.dat")
        with open(dumpfile, "wb") as f:
            pickle.dump(b, f)
        # Post-conf scripts must be run after writing coredata or else introspection fails.
        g.run_postconf_scripts()
    except:
        os.unlink(cdf)
        raise