Skip to content

Commit

Permalink
Feature/fix vcvars filter known (#3941)
Browse files Browse the repository at this point in the history
* before win

* added test

* Avoid empty path
  • Loading branch information
lasote committed Nov 19, 2018
1 parent a4bbe1c commit aae64bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 4 additions & 3 deletions conans/client/tools/win.py
Expand Up @@ -457,9 +457,10 @@ def relevant_path(path):
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)
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

Expand Down
18 changes: 18 additions & 0 deletions conans/test/util/tools_test.py
Expand Up @@ -801,6 +801,24 @@ def vcvars_env_not_duplicated_path_test(self):
# If the entry was already repeated before calling "tools.vcvars" we keep it
self.fail("The key '%s' has been repeated" % value)

@unittest.skipUnless(platform.system() == "Windows", "Requires Windows")
def vcvars_filter_known_paths_test(self):
settings = Settings.loads(default_settings_yml)
settings.os = "Windows"
settings.compiler = "Visual Studio"
settings.compiler.version = "15"
settings.arch = "x86"
settings.arch_build = "x86_64"
with tools.environment_append({"PATH": ["custom_path", "WindowsFake"]}):
tmp = tools.vcvars_dict(settings, only_diff=False, filter_known_paths=True)
with tools.environment_append(tmp):
self.assertNotIn("custom_path", os.environ["PATH"])
self.assertIn("WindowsFake", os.environ["PATH"])
tmp = tools.vcvars_dict(settings, only_diff=False, filter_known_paths=False)
with tools.environment_append(tmp):
self.assertIn("custom_path", os.environ["PATH"])
self.assertIn("WindowsFake", os.environ["PATH"])

@unittest.skipUnless(platform.system() == "Windows", "Requires Windows")
def vcvars_amd64_32_cross_building_support_test(self):
# amd64_x86 crossbuilder
Expand Down

0 comments on commit aae64bf

Please sign in to comment.