diff --git a/conans/client/graph/install_graph.py b/conans/client/graph/install_graph.py index d51f9082c8f..cc7db6587c2 100644 --- a/conans/client/graph/install_graph.py +++ b/conans/client/graph/install_graph.py @@ -1,5 +1,6 @@ import json import os +import shlex import textwrap from conan.api.output import ConanOutput @@ -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 @@ -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 diff --git a/test/integration/command_v2/test_info_build_order.py b/test/integration/command_v2/test_info_build_order.py index 21f6b86a4d9..bb9c688c7a0 100644 --- a/test/integration/command_v2/test_info_build_order.py +++ b/test/integration/command_v2/test_info_build_order.py @@ -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"'} ]]} ], [ @@ -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"'''