# Buggy code
def vcvars_dict(
    settings,
    arch=None,
    compiler_version=None,
    force=False,
    filter_known_paths=False,
    vcvars_ver=None,
    winsdk_version=None,
    only_diff=True,
):
    known_path_lists = ("include", "lib", "libpath", "path")
    cmd = vcvars_command(
        settings,
        arch=arch,
        compiler_version=compiler_version,
        force=force,
        vcvars_ver=vcvars_ver,
        winsdk_version=winsdk_version,
    )
    cmd += " && echo __BEGINS__ && set"
    ret = decode_text(subprocess.check_output(cmd, shell=True))
    new_env = {}
    start_reached = False
    for line in ret.splitlines():
        line = line.strip()
        if not start_reached:
            if "__BEGINS__" in line:
                start_reached = True
            continue

        if line == "\n" or not line:
            continue
        try:
            name_var, value = line.split("=", 1)
            new_value = (
                value.split(os.pathsep)
                if name_var.lower() in known_path_lists
                else value
            )
            # Return only new vars & changed ones, but only with the changed elements if the var is
            # a list
            if only_diff:
                old_value = os.environ.get(name_var)
                if name_var.lower() == "path":
                    old_values_lower = [v.lower() for v in old_value.split(os.pathsep)]
                    # Clean all repeated entries, not append if the element was already there
                    new_env[name_var] = [
                        v for v in new_value if v.lower() not in old_values_lower
                    ]
                elif old_value and value.endswith(os.pathsep + old_value):
                    # The new value ends with separator and the old value, is a list,
                    # get only the new elements
                    new_env[name_var] = value[: -(len(old_value) + 1)].split(os.pathsep)
                elif value != old_value:
                    # Only if the vcvars changed something, we return the variable,
                    # otherwise is not vcvars related
                    new_env[name_var] = new_value
            else:
                new_env[name_var] = new_value

        except ValueError:
            pass

    if filter_known_paths:

        def relevant_path(path):
            path = path.replace("\\", "/").lower()
            keywords = (
                "msbuild",
                "visual",
                "microsoft",
                "/msvc/",
                "/vc/",
                "system32",
                "windows",
            )
            return any(word in path for word in keywords)

        path = new_env.get("PATH", "").split(";")
        path = [entry for entry in path if relevant_path(entry)]
        new_env["PATH"] = ";".join(path)

    return new_env


# Traceback (AttributeError)
boost/1.68.0@odant/tt: Calling build()
boost/1.68.0@odant/tt: -------------- Bootstrap ------------------------
Traceback (most recent call last):
File "D:\.conan\data\boost\1.68.0\odant\tt\export\conanfile.py", line 171, in get_build_environment
env = tools.vcvars_dict(self.settings, filter_known_paths=True, force=True)
File "D:\Python27\lib\site-packages\conans\client\tools\win.py", line 460, in vcvars_dict
path = new_env.get("PATH", "").split(";")
AttributeError: 'list' object has no attribute 'split'
boost/1.68.0@odant/tt:
boost/1.68.0@odant/tt: ERROR: Package '74d6e6f7d63123455b1033138a5a462ab0736c21' build failed
boost/1.68.0@odant/tt: WARN: Build folder D:/.conan/s\4w_jf4\1
ERROR: boost/1.68.0@odant/tt: Error in build() method, line 80
b2 = self.bootstrap(source_folder)
while calling 'bootstrap', line 101
env = self.get_build_environment()
while calling 'get_build_environment', line 171
env = tools.vcvars_dict(self.settings, filter_known_paths=True, force=True)
AttributeError: 'list' object has no attribute 'split'

# Fixed code
def vcvars_dict(
    settings,
    arch=None,
    compiler_version=None,
    force=False,
    filter_known_paths=False,
    vcvars_ver=None,
    winsdk_version=None,
    only_diff=True,
):
    known_path_lists = ("include", "lib", "libpath", "path")
    cmd = vcvars_command(
        settings,
        arch=arch,
        compiler_version=compiler_version,
        force=force,
        vcvars_ver=vcvars_ver,
        winsdk_version=winsdk_version,
    )
    cmd += " && echo __BEGINS__ && set"
    ret = decode_text(subprocess.check_output(cmd, shell=True))
    new_env = {}
    start_reached = False
    for line in ret.splitlines():
        line = line.strip()
        if not start_reached:
            if "__BEGINS__" in line:
                start_reached = True
            continue

        if line == "\n" or not line:
            continue
        try:
            name_var, value = line.split("=", 1)
            new_value = (
                value.split(os.pathsep)
                if name_var.lower() in known_path_lists
                else value
            )
            # Return only new vars & changed ones, but only with the changed elements if the var is
            # a list
            if only_diff:
                old_value = os.environ.get(name_var)
                if name_var.lower() == "path":
                    old_values_lower = [v.lower() for v in old_value.split(os.pathsep)]
                    # Clean all repeated entries, not append if the element was already there
                    new_env[name_var] = [
                        v for v in new_value if v.lower() not in old_values_lower
                    ]
                elif old_value and value.endswith(os.pathsep + old_value):
                    # The new value ends with separator and the old value, is a list,
                    # get only the new elements
                    new_env[name_var] = value[: -(len(old_value) + 1)].split(os.pathsep)
                elif value != old_value:
                    # Only if the vcvars changed something, we return the variable,
                    # otherwise is not vcvars related
                    new_env[name_var] = new_value
            else:
                new_env[name_var] = new_value

        except ValueError:
            pass

    if filter_known_paths:

        def relevant_path(path):
            path = path.replace("\\", "/").lower()
            keywords = (
                "msbuild",
                "visual",
                "microsoft",
                "/msvc/",
                "/vc/",
                "system32",
                "windows",
            )
            return any(word in path for word in keywords)

        path_key = next(
            (name for name in new_env.keys() if "path" == name.lower()), None
        )
        if path_key:
            path = [
                entry for entry in new_env.get(path_key, "") if relevant_path(entry)
            ]
            new_env[path_key] = ";".join(path)

    return new_env