Skip to content

Commit

Permalink
avoid empty paths in runenv (#11298)
Browse files Browse the repository at this point in the history
* avoid empty paths in runenv

* add check in test
  • Loading branch information
memsharded committed May 18, 2022
1 parent 44b1777 commit 0a27518
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 8 additions & 10 deletions conan/tools/env/virtualrunenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 5 additions & 0 deletions conans/test/integration/environment/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"""
Expand Down

0 comments on commit 0a27518

Please sign in to comment.