conan-io / conan

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

[bug] Conan doesn't remove quotes from tools.build:sysroot #16914

Closed ericriff closed 5 days ago

ericriff commented 2 weeks ago

Describe the bug

OS: Ubuntu 22.04 Conan: 2.7.0

I configured my cross-compilation profile like this

tools.build:compiler_executables = {"cpp": "arm-poky-linux-gnueabi-g++", "c": "arm-poky-linux-gnueabi-gcc"}
tools.build:sysroot = "/opt/arm-sdk/sysroots/armv7at2hf-neon-poky-linux-gnueabi"
tools.build:cflags = ["-march=armv7-a", "-mthumb", "-mfpu=neon", "-mfloat-abi=hard", "-fstack-protector-strong"]
tools.build:cxxflags = ["-march=armv7-a", "-mthumb", "-mfpu=neon", "-mfloat-abi=hard", "-fstack-protector-strong"]

In most scenarios it works fine, but some recipes fail to build because conan doesn't remove the quotes from tools.build:sysroot. I can easily reproduce this by doing

(Pdb) self.conf.get("tools.build:sysroot")
'"/opt/arm-sdk/sysroots/armv7at2hf-neon-poky-linux-gnueabi"'

(notice that there is a single quote followed by a double quote) It works if I use no quotes at all on the profile, which is not the end of the world but I don't think it s the right solution. One affected recipe is openssl/3.x.x, see this but report: https://github.com/conan-io/conan-center-index/issues/4821

How to reproduce it

No response

memsharded commented 2 weeks ago

Hi @ericriff

Thanks for your report.

Something similar was recently discussed in https://github.com/conan-io/conan/issues/16479.

This is mostly by design. Profiles try to do as little processing as possible, and take the user inputs as-is. The reason for this was users wanting to define some inputs with actual spaces or with actual quotes, or even with quotes and internal escaped quotes, and Conan stripping them was not great.

ericriff commented 2 weeks ago

I see. So the guidelines are to set string-like variables with no quotes at all? What about dict-like variables, e.g.

tools.build:compiler_executables = {"cpp": "arm-poky-linux-gnueabi-g++", "c": "arm-poky-linux-gnueabi-gcc"}
memsharded commented 1 week ago

Yes, conf allows complex Python objects like dicts and lists. Those are loaded evaluating the string defining them. So the design/logic is as the examples in https://docs.conan.io/2/reference/config_files/profiles.html and other parts of the docs: