From 0a27518b5f3617a6730df97965a1e0f4e8409e07 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 18 May 2022 19:43:54 +0200 Subject: [PATCH] avoid empty paths in runenv (#11298) * avoid empty paths in runenv * add check in test --- conan/tools/env/virtualrunenv.py | 18 ++++++++---------- .../test/integration/environment/test_env.py | 5 +++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/conan/tools/env/virtualrunenv.py b/conan/tools/env/virtualrunenv.py index 345df2b50c8..a25f480eb8b 100644 --- a/conan/tools/env/virtualrunenv.py +++ b/conan/tools/env/virtualrunenv.py @@ -11,19 +11,17 @@ def runenv_from_cpp_info(conanfile, dep, os_name): cpp_info = dep.cpp_info.aggregated_components() - def _handle_paths(paths): - return [p for p in paths if os.path.exists(p)] + def _prepend_path(envvar, paths): + existing = [p for p in paths if os.path.exists(p)] if paths else None + if existing: + dyn_runenv.prepend_path(envvar, existing) - if cpp_info.bindirs: # cpp_info.exes is not defined yet - dyn_runenv.prepend_path("PATH", _handle_paths(cpp_info.bindirs)) + _prepend_path("PATH", cpp_info.bindirs) # If it is a build_require this will be the build-os, otherwise it will be the host-os if os_name and not os_name.startswith("Windows"): - if cpp_info.libdirs: - libdirs = _handle_paths(cpp_info.libdirs) - dyn_runenv.prepend_path("LD_LIBRARY_PATH", libdirs) - dyn_runenv.prepend_path("DYLD_LIBRARY_PATH", libdirs) - if cpp_info.frameworkdirs: - dyn_runenv.prepend_path("DYLD_FRAMEWORK_PATH", _handle_paths(cpp_info.frameworkdirs)) + _prepend_path("LD_LIBRARY_PATH", cpp_info.libdirs) + _prepend_path("DYLD_LIBRARY_PATH", cpp_info.libdirs) + _prepend_path("DYLD_FRAMEWORK_PATH", cpp_info.frameworkdirs) return dyn_runenv diff --git a/conans/test/integration/environment/test_env.py b/conans/test/integration/environment/test_env.py index ba458ae56e8..f6d39692adc 100644 --- a/conans/test/integration/environment/test_env.py +++ b/conans/test/integration/environment/test_env.py @@ -367,6 +367,7 @@ def generate(self): self.output.info("MYVAR2: {}!!!".format(runenv.get("MYVAR2"))) self.output.info("MYVAR3: {}!!!".format(runenv.get("MYVAR3"))) self.output.info("MYVAR4: {}!!!".format(runenv.get("MYVAR4"))) + env.generate() """) client = TestClient() client.save({"pkga/conanfile.py": pkga, @@ -386,6 +387,10 @@ def generate(self): assert "MYVAR3: PkgDValue3 PkgBValue3 PkgCValue3 PkgAValue3!!!" in client.out assert "MYVAR4: PkgDValue4!!!" in client.out + # No settings always sh + conanrun = client.load("conanrunenv.sh") + assert "PATH" not in conanrun + def test_environment_scripts_generated_envvars(): consumer_pkg = textwrap.dedent(r"""