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

Draft
wants to merge 4 commits into
base: develop2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 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
8 changes: 6 additions & 2 deletions conans/model/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ def dumps(self, scope=None):
if self._value is None:
return None
important = "!" if self.important else ""
value = self._value
if " " in value:
value = value.replace('"', r'\"')
value = f'"{value}"'
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
if scope:
return "%s:%s%s=%s" % (scope, self._name, important, self._value)
return "%s:%s%s=%s" % (scope, self._name, important, value)
else:
return "%s%s=%s" % (self._name, important, self._value)
return "%s%s=%s" % (self._name, important, value)

def copy_conaninfo_option(self):
# To generate a copy without validation, for package_id info.options value
Expand Down
46 changes: 34 additions & 12 deletions test/integration/command_v2/test_info_build_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def test_info_build_order():
c = TestClient()
c = TestClient(light=True)
c.save({"dep/conanfile.py": GenConanfile(),
"pkg/conanfile.py": GenConanfile().with_requires("dep/0.1"),
"consumer/conanfile.txt": "[requires]\npkg/0.1"})
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_info_build_order():


def test_info_build_order_configuration():
c = TestClient()
c = TestClient(light=True)
c.save({"dep/conanfile.py": GenConanfile(),
"pkg/conanfile.py": GenConanfile().with_requires("dep/0.1"),
"consumer/conanfile.txt": "[requires]\npkg/0.1"})
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_info_build_order_configuration():


def test_info_build_order_configuration_text_formatter():
c = TestClient()
c = TestClient(light=True)
c.save({"dep/conanfile.py": GenConanfile(),
"pkg/conanfile.py": GenConanfile().with_requires("dep/0.1"),
"consumer/conanfile.txt": "[requires]\npkg/0.1"})
Expand All @@ -144,7 +144,7 @@ def test_info_build_order_configuration_text_formatter():


def test_info_build_order_build_require():
c = TestClient()
c = TestClient(light=True)
c.save({"dep/conanfile.py": GenConanfile(),
"pkg/conanfile.py": GenConanfile().with_tool_requires("dep/0.1"),
"consumer/conanfile.txt": "[requires]\npkg/0.1"})
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_info_build_order_build_require():


def test_info_build_order_options():
c = TestClient()
c = TestClient(light=True)
# The normal default_options do NOT propagate to build_requires, it is necessary to use
# self.requires(..., options=xxx)
c.save({"tool/conanfile.py": GenConanfile().with_option("myopt", [1, 2, 3]),
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_info_build_order_options():


def test_info_build_order_merge_multi_product():
c = TestClient()
c = TestClient(light=True)
c.save({"dep/conanfile.py": GenConanfile(),
"pkg/conanfile.py": GenConanfile().with_requires("dep/0.1"),
"consumer1/conanfile.txt": "[requires]\npkg/0.1",
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_info_build_order_merge_multi_product():


def test_info_build_order_merge_multi_product_configurations():
c = TestClient()
c = TestClient(light=True)
c.save({"dep/conanfile.py": GenConanfile(),
"pkg/conanfile.py": GenConanfile().with_requires("dep/0.1"),
"consumer1/conanfile.txt": "[requires]\npkg/0.1",
Expand Down Expand Up @@ -517,7 +517,7 @@ def test_info_build_order_lockfile_location():
""" the lockfile should be in the caller cwd
https://github.com/conan-io/conan/issues/13850
"""
c = TestClient()
c = TestClient(light=True)
c.save({"dep/conanfile.py": GenConanfile("dep", "0.1"),
"pkg/conanfile.py": GenConanfile("pkg", "0.1").with_requires("dep/0.1")})
c.run("create dep")
Expand All @@ -529,7 +529,7 @@ def test_info_build_order_lockfile_location():

def test_info_build_order_broken_recipe():
# https://github.com/conan-io/conan/issues/14104
c = TestClient()
c = TestClient(light=True)
dep = textwrap.dedent("""
from conan import ConanFile
from conan.tools.files import replace_in_file
Expand All @@ -549,7 +549,7 @@ def export(self):
class TestBuildOrderReduce:
@pytest.mark.parametrize("order", ["recipe", "configuration"])
def test_build_order_reduce(self, order):
c = TestClient()
c = TestClient(light=True)
c.save({"liba/conanfile.py": GenConanfile("liba", "0.1"),
"libb/conanfile.py": GenConanfile("libb", "0.1").with_requires("liba/0.1"),
"libc/conanfile.py": GenConanfile("libc", "0.1").with_requires("libb/0.1"),
Expand Down Expand Up @@ -625,7 +625,7 @@ def test_build_order_merge_reduce(self, order):
assert level1[1]["depends"] == [liba2]

def test_error_reduced(self):
c = TestClient()
c = TestClient(light=True)
c.save({"conanfile.py": GenConanfile("liba", "0.1")})
c.run("graph build-order . --format=json", redirect_stdout="bo1.json")
c.run("graph build-order . --order-by=recipe --reduce --format=json",
Expand All @@ -637,7 +637,7 @@ def test_error_reduced(self):
assert "ERROR: Reduced build-order file cannot be merged: bo2.json"

def test_error_different_orders(self):
c = TestClient()
c = TestClient(light=True)
c.save({"conanfile.py": GenConanfile("liba", "0.1")})
c.run("graph build-order . --format=json", redirect_stdout="bo1.json")
c.run("graph build-order . --order-by=recipe --format=json", redirect_stdout="bo2.json")
Expand All @@ -652,3 +652,25 @@ def test_error_different_orders(self):
# different order
c.run(f"graph build-order-merge --file=bo3.json --file=bo2.json", assert_error=True)
assert "ERROR: Cannot merge build-orders of configuration!=recipe" in c.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"'''
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

# '--requires=dep/1.0 --build=dep/1.0 -o dep/*:extras="\\"cxx=yes gnuext=no\\"" -o dep/*:flags="define=FOO define=BAR define=BAZ"'