Skip to content

Commit 734944c

Browse files
committed
cli: Add --conan-arg and --conan-setting options to exec and shell commands
1 parent 4cb2bef commit 734944c

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

cli/cloe_launch/__main__.py

+36
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,25 @@ def deny_profile_and_path(profile: str, profile_path: str) -> None:
114114
@click.option("-E", "--preserve-env", is_flag=True, help="Preserve user environment.")
115115
@click.option(
116116
"-o",
117+
"--conan-arg",
118+
type=click.STRING,
119+
multiple=True,
120+
help="Arguments to pass to Conan for virtualrunenv generation",
121+
)
122+
@click.option(
123+
"-o:o",
117124
"--conan-option",
118125
type=click.STRING,
119126
multiple=True,
120127
help="Options to pass to Conan for virtualrunenv generation",
121128
)
129+
@click.option(
130+
"-o:s",
131+
"--conan-setting",
132+
type=click.STRING,
133+
multiple=True,
134+
help="Settings to pass to Conan for virtualrunenv generation",
135+
)
122136
@click.option(
123137
"-e",
124138
"--override-env",
@@ -134,7 +148,9 @@ def cli_exec(
134148
profile_path: str,
135149
preserve_env: bool,
136150
override_env: List[str],
151+
conan_arg: List[str],
137152
conan_option: List[str],
153+
conan_setting: List[str],
138154
cache: bool,
139155
debug: bool,
140156
) -> None:
@@ -146,7 +162,9 @@ def cli_exec(
146162
conf = Configuration(profile)
147163
engine = Engine(conf, conanfile=profile_path)
148164
engine.preserve_env = preserve_env
165+
engine.conan_args = conan_arg
149166
engine.conan_options = conan_option
167+
engine.conan_settings = conan_setting
150168

151169
# Prepare environment overrides:
152170
overrides = {}
@@ -175,11 +193,25 @@ def cli_exec(
175193
@click.option("-E", "--preserve-env", is_flag=True, help="Preserve user environment.")
176194
@click.option(
177195
"-o",
196+
"--conan-arg",
197+
type=click.STRING,
198+
multiple=True,
199+
help="Arguments to pass to Conan for virtualrunenv generation",
200+
)
201+
@click.option(
202+
"-o:o",
178203
"--conan-option",
179204
type=click.STRING,
180205
multiple=True,
181206
help="Options to pass to Conan for virtualrunenv generation",
182207
)
208+
@click.option(
209+
"-o:s",
210+
"--conan-setting",
211+
type=click.STRING,
212+
multiple=True,
213+
help="Settings to pass to Conan for virtualrunenv generation",
214+
)
183215
@click.argument("shell_args", nargs=-1)
184216
@click.pass_obj
185217
def cli_shell(
@@ -188,15 +220,19 @@ def cli_shell(
188220
profile: str,
189221
profile_path: str,
190222
preserve_env: bool,
223+
conan_arg: List[str],
191224
conan_option: List[str],
225+
conan_setting: List[str],
192226
cache: bool,
193227
) -> None:
194228
"""Launch shell with the correct environment from a profile."""
195229
deny_profile_and_path(profile, profile_path)
196230
conf = Configuration(profile)
197231
engine = Engine(conf, conanfile=profile_path)
198232
engine.preserve_env = preserve_env
233+
engine.conan_args = conan_arg
199234
engine.conan_options = conan_option
235+
engine.conan_settings = conan_setting
200236

201237
# Replace process with shell.
202238
engine.shell(shell_args, use_cache=cache)

cli/cloe_launch/exec.py

+10
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ def __init__(self, conf, conanfile=None):
357357
self.engine_pre_args = conf._conf["engine"]["pre_arguments"]
358358
self.engine_post_args = conf._conf["engine"]["post_arguments"]
359359
self.preserve_env = False
360+
self.conan_args = []
360361
self.conan_options = []
362+
self.conan_settings = []
361363

362364
logging.info(f"Profile name: {self.profile}")
363365
logging.info("Configuration:")
@@ -402,13 +404,21 @@ def _prepare_virtualenv(self) -> None:
402404
"-g",
403405
generator,
404406
]
407+
for arg in self.conan_args:
408+
conan_cmd.append(arg)
405409
for option in self.conan_options:
406410
conan_cmd.append("-o")
407411
conan_cmd.append(option)
412+
for setting in self.conan_settings:
413+
conan_cmd.append("-s")
414+
conan_cmd.append(setting)
408415
conan_cmd.append(self.profile_path)
409416
self._run_cmd(conan_cmd, must_succeed=True)
410417

411418
def _read_conan_env(self) -> Environment:
419+
# The order of the items in env_paths is important because variables
420+
# will be overwritten.
421+
# TODO: Should be replaced by merging in the future.
412422
env_paths = [
413423
os.path.join(self.runtime_dir, "activate_run.sh"),
414424
os.path.join(self.runtime_dir, "activate.sh"),

tests/setup_bats.bash

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ cloe_engine() {
3838
cloe_launch_args+=(--override-env=${var})
3939
done
4040
if [[ "${WITH_VTD}" -eq "1" ]]; then
41-
cloe_launch_args+=(-o)
41+
cloe_launch_args+=(-o:o)
4242
cloe_launch_args+=("with_vtd=True")
4343
fi
4444
for var in ${CLOE_LAUNCH_ARGS[@]}; do
@@ -83,7 +83,7 @@ cloe_shell() {
8383
cloe_launch_args+=(--override-env=${var})
8484
done
8585
if [[ "${WITH_VTD}" -eq "1" ]]; then
86-
cloe_launch_args+=(-o)
86+
cloe_launch_args+=(-o:o)
8787
cloe_launch_args+=("with_vtd=True")
8888
fi
8989
for var in ${CLOE_LAUNCH_ARGS[@]}; do

0 commit comments

Comments
 (0)