-
Notifications
You must be signed in to change notification settings - Fork 989
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] CMakeToolchain user_toolchain invalid escape character on Windows #10539
Comments
Hi @jwillikers I haven't managed to reproduce this. I have modified tests to cover this case, and they keep passing in Windows: diff --git a/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py b/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py
index 4316a5650..26b1f8a38 100644
--- a/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py
+++ b/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py
@@ -46,12 +46,14 @@ def test_cmake_toolchain_user_toolchain():
client = TestClient(path_with_spaces=False)
conanfile = GenConanfile().with_settings("os", "compiler", "build_type", "arch").\
with_generator("CMakeToolchain")
- save(client.cache.new_config_path, "tools.cmake.cmaketoolchain:user_toolchain=mytoolchain.cmake")
+ # use backslash, make sure https://github.com/conan-io/conan/issues/10539 works
+ save(client.cache.new_config_path,
+ r"tools.cmake.cmaketoolchain:user_toolchain=folder\mytoolchain.cmake")
client.save({"conanfile.py": conanfile})
client.run("install .")
toolchain = client.load("conan_toolchain.cmake")
- assert 'include("mytoolchain.cmake")' in toolchain
+ assert 'include("folder/mytoolchain.cmake")' in toolchain
def test_cmake_toolchain_custom_toolchain():
@@ -73,6 +75,7 @@ def test_cmake_toolchain_user_toolchain_from_dep():
import os
from conans import ConanFile
class Pkg(ConanFile):
+ short_paths = True
exports_sources = "*"
def package(self):
self.copy("*") Furthermore, the code that writes the toolchain is this: class UserToolchain(Block):
template = textwrap.dedent("""
{% for user_toolchain in paths %}
include("{{user_toolchain}}")
{% endfor %}
""")
def context(self):
# This is global [conf] injection of extra toolchain files
user_toolchain = self._conanfile.conf["tools.cmake.cmaketoolchain:user_toolchain"]
toolchains = [user_toolchain.replace("\\", "/")] if user_toolchain else []
return {"paths": toolchains if toolchains else []} I cannot find how a path would be saved there without replacing the backslash for forward slash could be saved into the |
@memsharded Thanks for doing that! My generate method looks like this: def generate(self):
user_toolchains = []
for dep in self.dependencies.test.values():
ut = dep.conf_info["tools.cmake.cmaketoolchain:user_toolchain"]
if ut:
user_toolchains.append(ut)
t = CMakeToolchain(self)
t.blocks["user_toolchain"].values["paths"] = user_toolchains
t.generate() As you can see, I overwrite the sanitized Feel free to close this issue if nothing has been left outstanding on your side. Thanks! |
Oh, that makes sense indeed, if you are directly providing unsanitized paths, then there is little that Conan can do (the template could try to do it too, but the template can also be overriden, so probably not worth the effort). As the solution is straightforward and is reasonable, I think we can close this, thanks for the feedback! |
@memsharded @jwillikers I just hit the same error on https://github.com/eirikb/proof-of-conan/actions/runs/3636633060/jobs/6136798729#step:10:11464:
This is triggered by |
Note that this happens because Conan takes the inputs as-is and outputs them inside a double quote string, where CMake will try to interpret the backslashes as escapes. The easiest solution to this would be to use the Lua style brackets instead of double quotes. So instead of |
@ericLemanissier In all CCI recipes migrated to conan v2, I add |
* use is_mvc * use CMakeDeps fixes #13144 * use PkgConfigDeps * use modern CMake integration * debug cmake find package * work arround conan-io/conan#11962 * don't test with qmake on static qt * fix Invalid character escape cf conan-io/conan#10539
Environment Details (include every applicable attribute)
Steps to reproduce (Include if Applicable)
Create a package for providing a CMake toolchain file via
tool_requires
and enableshort_paths
on Windows.When building a test package on Windows the following error occurs, which looks like it could be fixed by using forward slashes in the CMake toolchain instead of backslashes when including the
user_toolchain
.Logs (Executed commands with output) (Include/Attach if Applicable)
The text was updated successfully, but these errors were encountered: