Skip to content

Commit 8970371

Browse files
committed
cli: Use VirtualRunEnv generator
This is the only way to correctly pick up the environment variables such as PATH set for newer Conan packages. BREAKING CHANGE: This change may cause cloe-launch to no longer correctly pick up the environment variables for older Conan packages. This can be remedied by specifying the generators that should be run in the conanfile itself: generators = "virtualenv", "virtualrunenv" This is the case for conanfiles using `cloe-launch-profile` in a version < 0.21.
1 parent 56254fb commit 8970371

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

cli/cloe_launch/exec.py

+32-6
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ def _prepare_runtime_dir(self) -> None:
411411
self._prepare_virtualenv()
412412
self._write_cloe_env()
413413
self._write_activate_all(
414+
[
415+
# From Conan VirtualRunEnv (!= virtualrunenv) generator:
416+
self.runtime_dir / "conanrun.sh",
417+
],
414418
[
415419
# From Conan virtualenv generator:
416420
self.runtime_dir / "environment.sh.env",
@@ -492,7 +496,22 @@ def _write_zshrc(self) -> None:
492496

493497
def _write_cloe_env(self) -> None:
494498
"""Derive important CLOE_ variables and write environment_cloe.sh.env file."""
495-
env = Environment(self.runtime_dir / "activate_run.sh", source_file=True)
499+
conanrun = self.runtime_dir / "conanrun.sh" # From newer VirtualRunEnv generator
500+
activate_run = self.runtime_dir / "activate_run.sh" # From older virtualrunenv generator
501+
if conanrun.exists():
502+
if activate_run.exists():
503+
logging.warning("Warning: Found both conanrun.sh and activate_run.sh in runtime directory!")
504+
logging.warning("Note:")
505+
logging.warning(" It looks like /both/ VirtualRunEnv and virtualrunenv generators are being run.")
506+
logging.warning(" This may come from using an out-of-date cloe-launch-profile package.")
507+
logging.warning("")
508+
logging.warning(" Continuing with hybrid approach. Environment variables may be incorrectly set.")
509+
env = Environment(conanrun, source_file = True)
510+
elif activate_run.exists():
511+
env = Environment(activate_run, source_file = True)
512+
else:
513+
raise RuntimeError("cannot find conanrun.sh or activate_run.sh in runtime directory")
514+
496515
if env.has("CLOE_SHELL"):
497516
logging.error("Error: recursive cloe shells are not supported.")
498517
logging.error("Note:")
@@ -512,7 +531,7 @@ def _write_cloe_env(self) -> None:
512531
cloe_env.path_set("CLOE_PLUGIN_PATH", self._extract_plugin_paths(env))
513532
cloe_env.export(self.runtime_dir / "environment_cloe.sh.env")
514533

515-
def _write_activate_all(self, files: List[Path]) -> None:
534+
def _write_activate_all(self, source_files: List[Path], env_files: List[Path]) -> None:
516535
"""Write activate_all.sh file."""
517536
activate_file = self.runtime_dir / "activate_all.sh"
518537
activate_data = textwrap.dedent(
@@ -529,7 +548,16 @@ def _write_activate_all(self, files: List[Path]) -> None:
529548
530549
"""
531550
)
532-
for file in files:
551+
552+
for file in source_files:
553+
if not file.exists():
554+
logging.info(f"Skipping source: {file}")
555+
filename = shlex.quote(file.as_posix())
556+
activate_data += f". {filename}\n"
557+
558+
for file in env_files:
559+
if not file.exists():
560+
logging.info(f"Skipping export: {file}")
533561
filename = shlex.quote(file.as_posix())
534562
activate_data += f"export_vars_from_file {filename}\n"
535563
activate_data += "\nunset export_vars_from_file\n"
@@ -548,9 +576,7 @@ def _prepare_virtualenv(self) -> None:
548576
"--install-folder",
549577
str(self.runtime_dir),
550578
"-g",
551-
"virtualenv",
552-
"-g",
553-
"virtualrunenv",
579+
"VirtualRunEnv",
554580
]
555581
for arg in self.conan_args:
556582
conan_cmd.append(arg)

cli/conanfile.py

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class Base(object):
1212
settings = "os", "compiler", "build_type", "arch"
13-
generators = "virtualenv", "virtualrunenv"
1413

1514
def generate(self):
1615
if "cloe_launch_env" not in dir(self):

0 commit comments

Comments
 (0)