Repository: conan-io/conan
Pull request #17379 (2024-11-25 23:03:17)

[CMakeToolchain] fix adding tools.android:ndk_path with spaces in path
Changelog: Bugfix: [CMakeToolchain] fix adding tools.android:ndk_path with spaces in path #17378

- [x] Refer to the issue that supports this Pull Request.
- [ ] If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
- [x] I've read the [Contributing guide](https://github.com/conan-io/conan/blob/develop2/.github/CONTRIBUTING.md).
- [x] I've followed the PEP8 style guides for Python code.
- [ ] I've opened another PR in the Conan docs repo to the ``develop`` branch, documenting this one.



Patch:
diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py
index e19b113a9..7767a7a6d 100644
--- a/conan/tools/cmake/toolchain/blocks.py
+++ b/conan/tools/cmake/toolchain/blocks.py
@@ -375,7 +375,7 @@ class AndroidSystemBlock(Block):
         {% if android_use_legacy_toolchain_file %}
         set(ANDROID_USE_LEGACY_TOOLCHAIN_FILE {{ android_use_legacy_toolchain_file }})
         {% endif %}
-        include({{ android_ndk_path }}/build/cmake/android.toolchain.cmake)
+        include("{{ android_ndk_path }}/build/cmake/android.toolchain.cmake")
         """)
 
     def context(self):
diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py
index c1aeb577a..f3578e2c9 100644
--- a/conan/tools/scm/git.py
+++ b/conan/tools/scm/git.py
@@ -231,6 +231,7 @@ class Git:
         """
         if os.path.exists(url):
             url = url.replace("\\", "/")  # Windows local directory
+        mkdir(self.folder)
         self._conanfile.output.info("Shallow fetch of git repo")
         self.run('init')
         self.run(f'remote add origin "{url}"', hidden_output=url if hide_url else None)


Test patch:
diff --git a/test/functional/tools/scm/test_git.py b/test/functional/tools/scm/test_git.py
index 47214e461..ceef1e686 100644
--- a/test/functional/tools/scm/test_git.py
+++ b/test/functional/tools/scm/test_git.py
@@ -504,6 +504,46 @@ class TestGitShallowClone:
         c.run("source .")
         assert f'conanfile.py (pkg/0.1): RUN: git remote add origin "{url}"' in c.out
 
+    @pytest.mark.skipif(platform.system() == "Linux", reason="Git version in Linux not support it")
+    def test_clone_to_subfolder(self):
+        conanfile = textwrap.dedent("""
+            import os
+            from conan import ConanFile
+            from conan.tools.scm import Git
+            from conan.tools.files import load
+
+            class Pkg(ConanFile):
+                name = "pkg"
+                version = "0.1"
+
+                def layout(self):
+                    self.folders.source = "source"
+
+                def source(self):
+                    git = Git(self, folder="folder")
+                    git.fetch_commit(url="{url}", commit="{commit}")
+                    self.output.info("MYCMAKE: {{}}".format(load(self, "folder/CMakeLists.txt")))
+                    self.output.info("MYFILE: {{}}".format(load(self, "folder/src/myfile.h")))
+            """)
+        folder = os.path.join(temp_folder(), "myrepo")
+        url, commit = create_local_git_repo(files={"src/myfile.h": "myheader!",
+                                                   "CMakeLists.txt": "mycmake"}, folder=folder)
+        # This second commit will NOT be used, as I will use the above commit in the conanfile
+        save_files(path=folder, files={"src/myfile.h": "my2header2!"})
+        git_add_changes_commit(folder=folder)
+
+        c = TestClient()
+        c.save({"conanfile.py": conanfile.format(url=url, commit=commit)})
+        c.run("create . -v")
+        assert "pkg/0.1: MYCMAKE: mycmake" in c.out
+        assert "pkg/0.1: MYFILE: myheader!" in c.out
+
+        # It also works in local flow
+        c.run("source .")
+        assert "conanfile.py (pkg/0.1): MYCMAKE: mycmake" in c.out
+        assert "conanfile.py (pkg/0.1): MYFILE: myheader!" in c.out
+        assert c.load("source/folder/CMakeLists.txt") == "mycmake"
+        assert c.load("source/folder/src/myfile.h") == "myheader!"
 
 class TestGitCloneWithArgs:
     """ Git cloning passing additional arguments
diff --git a/test/integration/toolchains/cmake/test_cmaketoolchain.py b/test/integration/toolchains/cmake/test_cmaketoolchain.py
index 7af778df4..c9629d565 100644
--- a/test/integration/toolchains/cmake/test_cmaketoolchain.py
+++ b/test/integration/toolchains/cmake/test_cmaketoolchain.py
@@ -831,7 +831,7 @@ def test_android_c_library():
     conan_toolchain = client.load(os.path.join(client.current_folder, "conan_toolchain.cmake"))
     assert "set(ANDROID_PLATFORM android-23)" in conan_toolchain
     assert "set(ANDROID_ABI x86_64)" in conan_toolchain
-    assert "include(/foo/build/cmake/android.toolchain.cmake)" in conan_toolchain
+    assert 'include("/foo/build/cmake/android.toolchain.cmake")' in conan_toolchain
     client.run("create . --name=foo --version=1.0 " + settings)