def find_msvc()

in builder/core/toolchain.py [0:0]


    def find_msvc(version=None):
        """ Finds MSVC at a specific version, or the latest one available """
        def _find_msvc(version, install_vswhere=True):
            vswhere = util.where('vswhere')
            # if that fails, install vswhere and try again
            if not vswhere and install_vswhere:
                result = util.run_command(
                    'choco', 'install', '--no-progress', 'vswhere')
                if result.returncode == 0:
                    return _find_msvc(version, False)
                return None, None

            # A Visual Studio installation might have toolsets available for compiling
            # earlier versions. vswhere doesn't know about these toolsets, so
            # we'll just assume that any installation >= version can do the job.
            #
            # vswhere's -version flag expects a range, and if you just pass
            # a single int you'll get told about anything >= version.
            # Perfect, exactly what we want.
            result = util.run_command('vswhere', '-legacy', '-version', version,
                                      '-property', 'installationPath', '-sort', quiet=True)
            installations = result.output.splitlines()
            if installations:
                return installations[0], version
            return None, None

        versions = [version] if version else _msvc_versions()
        for version in versions:
            path, version = _find_msvc(version)
            if path:
                return path, version
        return None, None