Repository: conan-io/conan-center-index

Issue:
[package] onetbb/2021.3.0: Invalid character escape '\l'
### Description

For details on this, see : https://github.com/conan-io/conan/issues/10539

`conan_toolchain.cmake` is broken due to unescaped backslashes on windows. See log.

### Package and Environment Details

* Package Name/Version: **onetbb/2021.3.0#e447f12564bd0a5df3f2bd5781cf5cc7**
* Operating System+version: **Windows 11**
* Compiler+version: **MSVC 2022**
* Docker image: **?**
* Conan version: **conan 2.0.9**
* Python version: **Python 3.7.9**


### Conan profile

======== Input profiles ========
Profile host:
[settings]
arch=x86
build_type=Debug
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Debug
compiler.version=193
os=Windows

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows


### Steps to reproduce

Install (build) onetbb/2021.3.0#e447f12564bd0a5df3f2bd5781cf5cc7 with cmakedeps / cmaketoolchain generator.

### Logs

<details><summary>Click to expand log</summary>

```
CMake Error at C:/Users/pgroarke/.conan2/p/b/onetb3e83bbcb22a9a/b/build/generators/conan_toolchain.cmake:117 (set):
  Syntax error in cmake code at

    C:/Users/pgroarke/.conan2/p/b/onetb3e83bbcb22a9a/b/build/generators/conan_toolchain.cmake:117

  when parsing string

    C:/Users/pgroarke/.conan2/p/b/hwloc93107a9ec9dfe/p\lib\hwloc.lib

  Invalid character escape '\l'.
```

</details>



Discussion:
Yep, https://github.com/conan-io/conan-center-index/pull/17939 is broken on Windows. You can submit a PR to fix these paths by adding `.replace("\\", "/")` when there are passed to toolchain variables.

Basically instead of:

```python
        if self._tbbbind_explicit_hwloc:
            hwloc_package_folder = self.dependencies["hwloc"].package_folder.replace("\\", "/")
            hwloc_lib_name = "hwloc.lib" if self.settings.os == "Windows" else "libhwloc.so"
            toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_LIBRARY_PATH"] = os.path.join(hwloc_package_folder, "lib", hwloc_lib_name)
            toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_INCLUDE_PATH"] = os.path.join(hwloc_package_folder, "include")
            if self.settings.os == "Windows":
                toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_DLL_PATH"] = os.path.join(hwloc_package_folder, "bin", "hwloc.dll")
```

it should be:

```python
        if self._tbbbind_explicit_hwloc:
            hwloc_package_folder = self.dependencies["hwloc"].package_folder
            hwloc_lib_name = "hwloc.lib" if self.settings.os == "Windows" else "libhwloc.so"
            toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_LIBRARY_PATH"] = os.path.join(hwloc_package_folder, "lib", hwloc_lib_name).replace("\\", "/")
            toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_INCLUDE_PATH"] = os.path.join(hwloc_package_folder, "include").replace("\\", "/")
            if self.settings.os == "Windows":
                toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_DLL_PATH"] = os.path.join(hwloc_package_folder, "bin", "hwloc.dll").replace("\\", "/")
```

Resolving patch:
diff --git a/recipes/onetbb/all/conanfile.py b/recipes/onetbb/all/conanfile.py
--- a/recipes/onetbb/all/conanfile.py
+++ b/recipes/onetbb/all/conanfile.py
@@ -125,18 +125,22 @@ def generate(self):
         if Version(self.version) >= "2021.6.0" and self.options.get_safe("tbbproxy"):
             toolchain.variables["TBBMALLOC_PROXY_BUILD"] = self.options.tbbproxy
         toolchain.variables["TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH"] = not self._tbbbind_build
-        if self._tbbbind_build:
-            deps = PkgConfigDeps(self)
-            deps.generate()
         if self._tbbbind_explicit_hwloc:
-            hwloc_package_folder = self.dependencies["hwloc"].package_folder.replace("\\", "/")
+            hwloc_package_folder = self.dependencies["hwloc"].package_folder
             hwloc_lib_name = "hwloc.lib" if self.settings.os == "Windows" else "libhwloc.so"
-            toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_LIBRARY_PATH"] = os.path.join(hwloc_package_folder, "lib", hwloc_lib_name)
-            toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_INCLUDE_PATH"] = os.path.join(hwloc_package_folder, "include")
+            toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_LIBRARY_PATH"] = \
+                os.path.join(hwloc_package_folder, "lib", hwloc_lib_name).replace("\\", "/")
+            toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_INCLUDE_PATH"] = \
+                os.path.join(hwloc_package_folder, "include").replace("\\", "/")
             if self.settings.os == "Windows":
-                toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_DLL_PATH"] = os.path.join(hwloc_package_folder, "bin", "hwloc.dll")
+                toolchain.variables[f"CMAKE_HWLOC_{self._tbbbind_hwloc_version}_DLL_PATH"] = \
+                    os.path.join(hwloc_package_folder, "bin", "hwloc.dll").replace("\\", "/")
         toolchain.generate()
 
+        if self._tbbbind_build:
+            deps = PkgConfigDeps(self)
+            deps.generate()
+
     def build(self):
         apply_conandata_patches(self)
         cmake = CMake(self)


Test patch: