conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] test variable substitution in profiles

Open jcar87 opened this issue 2 years ago • 5 comments

Look into revisiting the expected behaviours with regards to variable substitution in profiles

jcar87 avatar Jul 29 '22 12:07 jcar87

Maybe drop our custom made variable substitution in favor of jinja templates ones?

memsharded avatar Jul 29 '22 12:07 memsharded

Maybe drop our custom made variable substitution in favor of jinja templates ones?

no way

SSE4 avatar Jul 29 '22 14:07 SSE4

no way

Why not?

memsharded avatar Jul 29 '22 14:07 memsharded

Why not?

it's useful, clean and easy to understand syntax, compare to obscure and hard to read jinja2 templates

SSE4 avatar Jul 29 '22 14:07 SSE4

But now we have 2 mechanisms to do the same thing, which is undesired, it would make sense to keep only 1 of them, probably the most flexible, generic and "standard" one. In that sense, jinja, even if the syntax is less terse, is more standard than our variable substitution.

It is also not that clean, the way they can propagate and overwrite over multiple composed profiles or included() profiles is less than evident and can lead to confusion. I was thinking of simplifying this bit also.

memsharded avatar Jul 29 '22 14:07 memsharded

Lets try a POC how a profile looks like with Jinja variable substitution

memsharded avatar Sep 06 '22 10:09 memsharded

Simple example doing a bit of inheriting and variables declaring (already working):

profile_vars at ~/.conan2/profiles/profile_vars:

{% set bar = "Bar-baridad" %}

foo at ~/.conan2/profiles/foo:

{% import "profile_vars" as vars %}
{% set foo = "default" %}

include({{ foo }})

[conf]
user.foo.bar = "{{ vars.bar }}"

Running an install with the profile (conan-including the default profile):


conan install . --profile foo

-------- Input profiles --------
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu98
compiler.libcxx=libc++
compiler.version=13
os=Macos
[conf]
user.foo.bar="Bar-baridad"

So I would say, the current include mechanism by Conan is ok, but if you need to reuse variables from other profile (including the default) you should use the jinja2 import and we should drop all that part. WDYT?

lasote avatar Sep 08 '22 13:09 lasote

Yes, I think I would drop support for our own variable replacement and use jinja syntax only for this. Leave the include()

memsharded avatar Sep 09 '22 10:09 memsharded

Yes, I think I would drop support for our own variable replacement and use jinja syntax only for this. Leave the include()

can we consider keeping the old support? there are a lot of existing profiles that use it, it would be a significant effort to re-write them, plus all the tutorials, examples, etc.

SSE4 avatar Sep 09 '22 11:09 SSE4

We want only one way to do things and jinja does it perfectly. It doesn't make any sense to keep the support for a custom one. That is one big purpose of Conan 2, simplify and grow solid and better.

lasote avatar Sep 09 '22 11:09 lasote

Closed by https://github.com/conan-io/conan/pull/12152

memsharded avatar Sep 21 '22 08:09 memsharded