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

Quote build_args in conan graph build-order #16594

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions conans/client/graph/install_graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import shlex
import textwrap

from conan.api.output import ConanOutput
Expand Down Expand Up @@ -72,7 +73,8 @@ def _build_args(self):
compatible = "compatible:" if self.info and self.info.get("compatibility_delta") else ""
cmd += f" --build={compatible}{self.ref}"
if self.options:
cmd += " " + " ".join(f"-o {o}" for o in self.options)
scope = "" if self.context == "host" else ":b"
cmd += " " + " ".join(f'-o{scope}="{o}"' for o in self.options)
if self.overrides:
cmd += f' --lockfile-overrides="{self.overrides}"'
return cmd
Expand Down Expand Up @@ -283,7 +285,8 @@ def _build_args(self):
compatible = "compatible:" if self.info and self.info.get("compatibility_delta") else ""
cmd += f" --build={compatible}{self.ref}"
if self.options:
cmd += " " + " ".join(f"-o {o}" for o in self.options)
scope = "" if self.context == "host" else ":b"
cmd += " " + " ".join(f'-o{scope}="{o}"' for o in self.options)
if self.overrides:
cmd += f' --lockfile-overrides="{self.overrides}"'
return cmd
Expand Down
23 changes: 21 additions & 2 deletions test/integration/command_v2/test_info_build_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ def test_info_build_order_options():
'context': 'build', 'depends': [], "overrides": {},
'binary': 'Build', 'options': ['tool/0.1:myopt=2'], 'filenames': [],
'info': {'options': {'myopt': '2'}},
'build_args': '--tool-requires=tool/0.1 --build=tool/0.1 -o tool/0.1:myopt=2'},
'build_args': '--tool-requires=tool/0.1 --build=tool/0.1 -o:b="tool/0.1:myopt=2"'},
{'package_id': 'a9035d84c5880b26c4b44acf70078c9a7dd37412', 'prev': None,
'context': 'build', 'depends': [], "overrides": {},
'info': {'options': {'myopt': '1'}},
'binary': 'Build', 'options': ['tool/0.1:myopt=1'],
'filenames': [],
'build_args': '--tool-requires=tool/0.1 --build=tool/0.1 -o tool/0.1:myopt=1'}
'build_args': '--tool-requires=tool/0.1 --build=tool/0.1 -o:b="tool/0.1:myopt=1"'}
]]}
],
[
Expand Down Expand Up @@ -765,3 +765,22 @@ def validate(self):
tc.run("graph build-order-merge --file=order.json --file=order.json --format=json", assert_error=True)
assert "dep/1.0:da39a3ee5e6b4b0d3255bfef95601890afd80709: Invalid configuration" in tc.out
assert "IndexError: list index out of range" not in tc.out

def test_build_order_space_in_options():
tc = TestClient(light=True)
tc.save({"dep/conanfile.py": GenConanfile("dep", "1.0")
.with_option("flags", ["ANY", None])
.with_option("extras", ["ANY", None]),
"conanfile.txt": textwrap.dedent("""
[requires]
dep/1.0

[options]
dep/*:flags=define=FOO define=BAR define=BAZ
dep/*:extras=cxx="yes" gnuext='no'
""")})

tc.run("create dep")
tc.run("graph build-order . --order-by=configuration --build=dep/1.0 -f=json", redirect_stdout="order.json")
order = json.loads(tc.load("order.json"))
assert order["order"][0][0]["build_args"] == '''--requires=dep/1.0 --build=dep/1.0 -o="dep/*:extras=cxx="yes" gnuext='no'" -o="dep/*:flags=define=FOO define=BAR define=BAZ"'''