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

[bug] {{conan_home_folder}} doesn't work with backslash '\' #15868

Closed
andrey-zherikov opened this issue Mar 13, 2024 · 6 comments · Fixed by #15870
Closed

[bug] {{conan_home_folder}} doesn't work with backslash '\' #15868

andrey-zherikov opened this issue Mar 13, 2024 · 6 comments · Fixed by #15870
Assignees

Comments

@andrey-zherikov
Copy link

Environment details

  • Operating System+version: Windows 11
  • Compiler+version: N/A
  • Conan version: 2.2.0-dev
  • Python version: 3.10.2

Steps to reproduce

Bat script to reproduce the issue:

mkdir foo
cd foo

git clone https://github.com/conan-io/conan
cd conan
git checkout develop2
cd ..

python -m venv venv
call venv\Scripts\activate
python -m pip install -e .\conan
python -m pip install cmake

set CONAN_HOME=%cd%\.conan2
mkdir %CONAN_HOME%\profiles\toolchain
copy NUL %CONAN_HOME%\profiles\toolchain\windows.cmake
echo tools.cmake.cmaketoolchain:user_toolchain = [ "{{conan_home_folder}}/profiles/toolchain/{{platform.system().lower()}}.cmake" ] > %CONAN_HOME%\global.conf

conan profile detect

mkdir test-package
cd test-package
conan new cmake_lib -d name=hello -d version=0.1
conan create .

Logs

Executing the script above in c:\test gives the following.
First of all the [conf] section is incorrect in conan create output:

[conf]
tools.cmake.cmaketoolchain:user_toolchain=['c:\test\x0coo\\.conan2/profiles/toolchain/windows.cmake']

Then CMake errors out with this:

-- Using Conan toolchain: C:/test/foo/.conan2/p/b/helloa85cf36358bd6/b/build/generators/conan_toolchain.cmake
CMake Error at build/generators/conan_toolchain.cmake:17 (include):
  include could not find requested file:

    c:  est
oo/.conan2/profiles/toolchain/windows.cmake
Call Stack (most recent call first):
  C:/test/foo/venv/Lib/site-packages/cmake/data/share/cmake-3.28/Modules/CMakeDetermineSystem.cmake:170 (include)
  CMakeLists.txt:2 (project)

This CMake error comes from incorrect include statement in conan_toolchain.cmake:

include("c:	estoo/.conan2/profiles/toolchain/windows.cmake")

The correct statement should be this:

include("c:/test/foo/.conan2/profiles/toolchain/windows.cmake")
@memsharded
Copy link
Member

Thanks for reporting @andrey-zherikov

A couple of quick hints:

  • The problem is defining the tools.cmake.cmaketoolchain:user_toolchain in the global.conf and using that conan_home_folder inside a string, inside a list
  • The isse can be workarounded avoiding the list, with the sintax tools.cmake.cmaketoolchain:user_toolchain+=value instead of the list.
  • This tools.cmake.cmaketoolchain:user_toolchain is not very expected to be in global.conf. That would mean that the same toolchain is used absolutely always, for all different configurations, and this would be very unlikely.
  • The recommended way is defining tools.cmake.cmaketoolchain:user_toolchain in profiles, not in global.conf, being the toolchain different for different profiles.

@memsharded
Copy link
Member

Proposing potential fix in #15870

@memsharded
Copy link
Member

#15870 merged, it will be in next 2.2 release

@andrey-zherikov
Copy link
Author

andrey-zherikov commented Mar 14, 2024

  • The isse can be workarounded avoiding the list, with the sintax tools.cmake.cmaketoolchain:user_toolchain+=value instead of the list.

I confirm that += solves the issue.

Correction: += workaround works for the top of develop2 branch of conan. It does not work for conan 2.1.0 - generated conan_toolchain.cmake still contains this:

include(""C:<0xFF>oo<0xFF>oo/.conan2/profiles/toolchain/windows.cmake"")

instead of

include(""C:\foo\foo/.conan2/profiles/toolchain/windows.cmake"")

The latest conan (future 2.2.0) has this in generated toolchain:

include(""C:/foo/foo/.conan2/profiles/toolchain/windows.cmake"")

@andrey-zherikov
Copy link
Author

Just for the record if anyone faces the issue (idk whether this is an issue of my misunderstanding or unclear conan documentation).

This doesn't work:

tools.cmake.cmaketoolchain:user_toolchain += "{{conan_home_folder}}/profiles/toolchain/{{platform.system().lower()}}.cmake"

Instead, remove quotes and it works:

tools.cmake.cmaketoolchain:user_toolchain += {{conan_home_folder}}/profiles/toolchain/{{platform.system().lower()}}.cmake

The latter does not produce two double quotes in toolchain:

include("C:/foo/foo/.conan2/profiles/toolchain/windows.cmake")

This even works with conan 2.1.0

@memsharded
Copy link
Member

Just for the record if anyone faces the issue (idk whether this is an issue of my misunderstanding or unclear conan documentation).

I cannot find any place in the docs where quotes are used for that syntax, only:

tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/myvars.cmake

the places where quotes are used are when defining lists, because mostly the value is eval() evaluated, and the individual elements of the list need to be quoted. This is described in https://docs.conan.io/2/reference/config_files/global_conf.html#configuration-data-types

There I can see that values are not quoted, so it looks good, but if you have seen it somewhere, please let me know so we can fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants