Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid empty paths in runenv #11298

Merged
merged 2 commits into from May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions conan/tools/env/virtualrunenv.py
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
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

""")
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