conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.23k stars 980 forks source link

[bug] MesonToolchain: project options of type string are not quoted (ERROR: Malformed value in machine file variable) #14453

Closed SpaceIm closed 1 year ago

SpaceIm commented 1 year ago

Environment details

Steps to reproduce

Create a conan recipe based on Meson, and pass a recipe option of type ["ANY"] (with a string as default_options) to project_options.

For example:

options = {
    "foo": ["ANY"],
    "bar": ["ANY"],
}
default_options = {
    "foo": "/var/run/foo",
    "bar": "BAR",
}

(...)

tc = MesonToolchain(self)
tc.project_options["foo"] = self.options.foo
tc.project_options["bar"] = self.options.bar
tc.generate()

The problem is that values are not quoted in generated machine file. Surprisingly, they are quoted if value is passed directly tc.project_options["foo"] = "/var/run/foo", I guess there is something wrong when self.options.foo is resolved.

(I'm not sure, but for the fix you likely want to avoid to quote boolean options)

Logs

First option gives this error:

ERROR: Malformed value in machine file variable 'foo': Unsupported node type.

Second option gives this error:

ERROR: Undefined constant 'BAR' in machine file variable 'bar'.
SpaceIm commented 1 year ago

As a workaround, I pass str(self.options.foo) to project_options, so that to_meson_value() can go into the branch isinstance(value, str).

EDIT: see https://github.com/conan-io/conan-center-index/pull/19115