# Buggy code
def configure(self, extra_cmake_options: T.List[str]) -> None:
    for_machine = MachineChoice.HOST  # TODO make parameter
    # Find CMake
    cmake_exe = CMakeExecutor(self.env, ">=3.7", for_machine)
    if not cmake_exe.found():
        raise CMakeException("Unable to find CMake")
    self.trace = CMakeTraceParser(cmake_exe.version(), self.build_dir, permissive=True)

    preload_file = Path(__file__).resolve().parent / "data" / "preload.cmake"

    # Prefere CMAKE_PROJECT_INCLUDE over CMAKE_TOOLCHAIN_FILE if possible,
    # since CMAKE_PROJECT_INCLUDE was actually designed for code injection.
    preload_var = "CMAKE_PROJECT_INCLUDE"
    if version_compare(cmake_exe.version(), "<3.15"):
        preload_var = "CMAKE_TOOLCHAIN_FILE"

    generator = backend_generator_map[self.backend_name]
    cmake_args = []
    trace_args = self.trace.trace_args()
    cmcmp_args = [
        "-DCMAKE_POLICY_WARNING_{}=OFF".format(x) for x in disable_policy_warnings
    ]
    pload_args = ["-D{}={}".format(preload_var, str(preload_file))]

    if version_compare(cmake_exe.version(), ">=3.14"):
        self.cmake_api = CMakeAPI.FILE
        self.fileapi.setup_request()

    # Map meson compiler to CMake variables
    for lang, comp in self.env.coredata.compilers[for_machine].items():
        if lang not in language_map:
            continue
        self.linkers.add(comp.get_linker_id())
        cmake_lang = language_map[lang]
        exelist = comp.get_exelist()
        if len(exelist) == 1:
            cmake_args += ["-DCMAKE_{}_COMPILER={}".format(cmake_lang, exelist[0])]
        elif len(exelist) == 2:
            cmake_args += [
                "-DCMAKE_{}_COMPILER_LAUNCHER={}".format(cmake_lang, exelist[0]),
                "-DCMAKE_{}_COMPILER={}".format(cmake_lang, exelist[1]),
            ]
        if hasattr(comp, "get_linker_exelist") and comp.get_id() == "clang-cl":
            cmake_args += ["-DCMAKE_LINKER={}".format(comp.get_linker_exelist()[0])]
    cmake_args += ["-G", generator]
    cmake_args += ["-DCMAKE_INSTALL_PREFIX={}".format(self.install_prefix)]
    cmake_args += extra_cmake_options

    # Run CMake
    mlog.log()
    with mlog.nested():
        mlog.log(
            "Configuring the build directory with",
            mlog.bold("CMake"),
            "version",
            mlog.cyan(cmake_exe.version()),
        )
        mlog.log(mlog.bold("Running:"), " ".join(cmake_args))
        mlog.log(mlog.bold("  - build directory:         "), self.build_dir)
        mlog.log(mlog.bold("  - source directory:        "), self.src_dir)
        mlog.log(mlog.bold("  - trace args:              "), " ".join(trace_args))
        mlog.log(mlog.bold("  - preload file:            "), str(preload_file))
        mlog.log(
            mlog.bold("  - disabled policy warnings:"),
            "[{}]".format(", ".join(disable_policy_warnings)),
        )
        mlog.log()
        os.makedirs(self.build_dir, exist_ok=True)
        os_env = os.environ.copy()
        os_env["LC_ALL"] = "C"
        final_args = cmake_args + trace_args + cmcmp_args + pload_args + [self.src_dir]

        cmake_exe.set_exec_mode(
            print_cmout=True, always_capture_stderr=self.trace.requires_stderr()
        )
        rc, _, self.raw_trace = cmake_exe.call(
            final_args, self.build_dir, env=os_env, disable_cache=True
        )

    mlog.log()
    h = mlog.green("SUCCEEDED") if rc == 0 else mlog.red("FAILED")
    mlog.log("CMake configuration:", h)
    if rc != 0:
        raise CMakeException("Failed to configure the CMake subproject")


# Traceback (FileNotFoundError)
C:\Users\icherepa\Desktop\bgpscanner> meson --buildtype=release ..
The Meson build system
Version: 0.53.2
Source dir: C:\Users\icherepa\Desktop\bgpscanner
Build dir: C:\Users\icherepa\Desktop
Build type: native build
Project name: bgpscanner
Project version: 2.31
C compiler for the host machine: gcc (gcc 6.3.0 "gcc (MinGW.org GCC-6.3.0-1) 6.3.0")
C linker for the host machine: gcc ld.bfd 2.28
Host machine cpu family: x86
Host machine cpu: x86
Run-time dependency threads found: YES
Found pkg-config: C:\MinGW\bin\pkg-config.EXE (0.23)
Found CMake: C:\Program Files\CMake\bin\cmake.EXE (3.17.0-rc3)
Traceback (most recent call last):
File "mesonbuild\mesonmain.py", line 129, in run
File "mesonbuild\msetup.py", line 245, in run
File "mesonbuild\msetup.py", line 159, in generate
File "mesonbuild\msetup.py", line 192, in _generate
File "mesonbuild\interpreter.py", line 4167, in run
File "mesonbuild\interpreterbase.py", line 412, in run
File "mesonbuild\interpreterbase.py", line 436, in evaluate_codeblock
File "mesonbuild\interpreterbase.py", line 430, in evaluate_codeblock
File "mesonbuild\interpreterbase.py", line 443, in evaluate_statement
File "mesonbuild\interpreterbase.py", line 1064, in assignment
File "mesonbuild\interpreterbase.py", line 441, in evaluate_statement
File "mesonbuild\interpreterbase.py", line 788, in function_call
File "mesonbuild\interpreterbase.py", line 285, in wrapped
File "mesonbuild\interpreterbase.py", line 285, in wrapped
File "mesonbuild\interpreterbase.py", line 285, in wrapped
[Previous line repeated 2 more times]
File "mesonbuild\interpreterbase.py", line 155, in wrapped
File "mesonbuild\interpreterbase.py", line 174, in wrapped
File "mesonbuild\interpreter.py", line 3236, in func_dependency
File "mesonbuild\interpreter.py", line 3283, in dependency_impl
File "mesonbuild\dependencies\base.py", line 2234, in find_external_dependency
File "mesonbuild\dependencies\base.py", line 1104, in __init__
File "mesonbuild\dependencies\base.py", line 1158, in _get_cmake_info
File "mesonbuild\dependencies\base.py", line 1533, in _call_cmake
File "mesonbuild\dependencies\base.py", line 1507, in _setup_cmake_dir
File "pathlib.py", line 1229, in read_text
File "pathlib.py", line 1215, in open
File "pathlib.py", line 1071, in _opener
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Program Files\\Meson\\mesonbuild\\dependencies\\data\\CMakePathInfo.txt'

# Fixed code
def configure(self, extra_cmake_options: T.List[str]) -> None:
    for_machine = MachineChoice.HOST  # TODO make parameter
    # Find CMake
    cmake_exe = CMakeExecutor(self.env, ">=3.7", for_machine)
    if not cmake_exe.found():
        raise CMakeException("Unable to find CMake")
    self.trace = CMakeTraceParser(cmake_exe.version(), self.build_dir, permissive=True)

    preload_file = pkg_resources.resource_filename(
        "mesonbuild", "cmake/data/preload.cmake"
    )

    # Prefere CMAKE_PROJECT_INCLUDE over CMAKE_TOOLCHAIN_FILE if possible,
    # since CMAKE_PROJECT_INCLUDE was actually designed for code injection.
    preload_var = "CMAKE_PROJECT_INCLUDE"
    if version_compare(cmake_exe.version(), "<3.15"):
        preload_var = "CMAKE_TOOLCHAIN_FILE"

    generator = backend_generator_map[self.backend_name]
    cmake_args = []
    trace_args = self.trace.trace_args()
    cmcmp_args = [
        "-DCMAKE_POLICY_WARNING_{}=OFF".format(x) for x in disable_policy_warnings
    ]
    pload_args = ["-D{}={}".format(preload_var, str(preload_file))]

    if version_compare(cmake_exe.version(), ">=3.14"):
        self.cmake_api = CMakeAPI.FILE
        self.fileapi.setup_request()

    # Map meson compiler to CMake variables
    for lang, comp in self.env.coredata.compilers[for_machine].items():
        if lang not in language_map:
            continue
        self.linkers.add(comp.get_linker_id())
        cmake_lang = language_map[lang]
        exelist = comp.get_exelist()
        if len(exelist) == 1:
            cmake_args += ["-DCMAKE_{}_COMPILER={}".format(cmake_lang, exelist[0])]
        elif len(exelist) == 2:
            cmake_args += [
                "-DCMAKE_{}_COMPILER_LAUNCHER={}".format(cmake_lang, exelist[0]),
                "-DCMAKE_{}_COMPILER={}".format(cmake_lang, exelist[1]),
            ]
        if hasattr(comp, "get_linker_exelist") and comp.get_id() == "clang-cl":
            cmake_args += ["-DCMAKE_LINKER={}".format(comp.get_linker_exelist()[0])]
    cmake_args += ["-G", generator]
    cmake_args += ["-DCMAKE_INSTALL_PREFIX={}".format(self.install_prefix)]
    cmake_args += extra_cmake_options

    # Run CMake
    mlog.log()
    with mlog.nested():
        mlog.log(
            "Configuring the build directory with",
            mlog.bold("CMake"),
            "version",
            mlog.cyan(cmake_exe.version()),
        )
        mlog.log(mlog.bold("Running:"), " ".join(cmake_args))
        mlog.log(mlog.bold("  - build directory:         "), self.build_dir)
        mlog.log(mlog.bold("  - source directory:        "), self.src_dir)
        mlog.log(mlog.bold("  - trace args:              "), " ".join(trace_args))
        mlog.log(mlog.bold("  - preload file:            "), str(preload_file))
        mlog.log(
            mlog.bold("  - disabled policy warnings:"),
            "[{}]".format(", ".join(disable_policy_warnings)),
        )
        mlog.log()
        os.makedirs(self.build_dir, exist_ok=True)
        os_env = os.environ.copy()
        os_env["LC_ALL"] = "C"
        final_args = cmake_args + trace_args + cmcmp_args + pload_args + [self.src_dir]

        cmake_exe.set_exec_mode(
            print_cmout=True, always_capture_stderr=self.trace.requires_stderr()
        )
        rc, _, self.raw_trace = cmake_exe.call(
            final_args, self.build_dir, env=os_env, disable_cache=True
        )

    mlog.log()
    h = mlog.green("SUCCEEDED") if rc == 0 else mlog.red("FAILED")
    mlog.log("CMake configuration:", h)
    if rc != 0:
        raise CMakeException("Failed to configure the CMake subproject")