Repository: conan-io/conan-center-index

Issue:
[package] tree-sitter/*: tree-sitter needs to be updated to conan2.0
### Description

When I want to add `tree-sitter-cpp` lib recipe to CCI, the tree-sitter lib, which is required by tree-sitter-cpp, cannot be built because it doesn't support conan2.

### Expected
tree-sitter lib built successfully with conan2. 

### Package and Environment Details

* Package Name/Version: **tree-sitter/0.20.0**
* Operating System+version: **Arch Linux**
* Compiler+version: **GCC 13**
* Docker image: **conanio/gcc8**
* Conan version: **conan 2.0.4**
* Python version: **Python 3.9.12**


### Conan profile
```yaml
Host profile:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13.1
os=Linux

Build profile:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=13.1
os=Linux
```

### Steps to reproduce
```shell
cd <CCI-repo>/recipes/tree-sitter
conan create all/conanfile.py --version 0.20.6 -pr:b=default -pr:h=default
```
### Logs
```shell
ERROR: Error loading conanfile at '/home/whalien/codebase/misc/conan-center-index/recipes/tree-sitter/all/conanfile.py': Unable to load conanfile in /home/whalien/codebase/misc/conan-center-index/recipes/tree-sitter/all/conanfile.py
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/whalien/codebase/misc/conan-center-index/recipes/tree-sitter/all/conanfile.py", line 1, in <module>
    from conans import CMake, ConanFile, tools
ImportError: cannot import name 'CMake' from 'conans' (/usr/lib/python3.11/site-packages/conans/__init__.py)
```


Discussion:

Resolving patch:
diff --git a/recipes/tree-sitter/all/conanfile.py b/recipes/tree-sitter/all/conanfile.py
--- a/recipes/tree-sitter/all/conanfile.py
+++ b/recipes/tree-sitter/all/conanfile.py
@@ -1,7 +1,10 @@
-from conans import CMake, ConanFile, tools
-import functools
+import os
 
-required_conan_version = ">=1.33.0"
+from conan import ConanFile
+from conan.tools.cmake import CMake, cmake_layout
+from conan.tools.files import get, copy
+
+required_conan_version = ">=1.53.0"
 
 
 class TreeSitterConan(ConanFile):
@@ -11,6 +14,7 @@ class TreeSitterConan(ConanFile):
     url = "https://github.com/conan-io/conan-center-index"
     homepage = "https://tree-sitter.github.io/tree-sitter"
     license = "MIT"
+    package_type = "library"
     settings = "os", "arch", "compiler", "build_type"
     options = {
         "fPIC": [True, False],
@@ -21,42 +25,39 @@ class TreeSitterConan(ConanFile):
         "shared": False,
     }
 
-    generators = "cmake"
+    generators = "CMakeToolchain"
     exports_sources = "CMakeLists.txt"
 
-    @property
-    def _source_subfolder(self):
-        return "source_subfolder"
-
     def config_options(self):
         if self.settings.os == "Windows":
             del self.options.fPIC
 
     def configure(self):
         if self.options.shared:
-            del self.options.fPIC
-        del self.settings.compiler.cppstd
-        del self.settings.compiler.libcxx
+            self.options.rm_safe("fPIC")
+        self.settings.rm_safe("compiler.cppstd")
+        self.settings.rm_safe("compiler.libcxx")
 
-    def source(self):
-        tools.get(**self.conan_data["sources"][self.version],
-                  destination=self._source_subfolder, strip_root=True)
+    def layout(self):
+        cmake_layout(self, src_folder="src")
 
-    @functools.lru_cache(1)
-    def _configure_cmake(self):
-        cmake = CMake(self)
-        cmake.configure()
-        return cmake
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
 
     def build(self):
-        cmake = self._configure_cmake()
+        cmake = CMake(self)
+        cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
         cmake.build()
 
     def package(self):
-        self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
-        cmake = self._configure_cmake()
+        copy(
+            self,
+            "LICENSE",
+            src=self.source_folder,
+            dst=os.path.join(self.package_folder, "licenses"),
+        )
+        cmake = CMake(self)
         cmake.install()
 
     def package_info(self):
-        self.cpp_info.names["pkg_config"] = "tree-sitter"
         self.cpp_info.libs = ["tree-sitter"]


Test patch:
diff --git a/recipes/tree-sitter/all/test_package/CMakeLists.txt b/recipes/tree-sitter/all/test_package/CMakeLists.txt
--- a/recipes/tree-sitter/all/test_package/CMakeLists.txt
+++ b/recipes/tree-sitter/all/test_package/CMakeLists.txt
@@ -1,9 +1,6 @@
 cmake_minimum_required(VERSION 3.1)
 project(test_package C)
 
-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup(TARGETS)
-
 find_package(tree-sitter REQUIRED CONFIG)
 
 add_executable(${PROJECT_NAME} test_package.c)
diff --git a/recipes/tree-sitter/all/test_package/conanfile.py b/recipes/tree-sitter/all/test_package/conanfile.py
--- a/recipes/tree-sitter/all/test_package/conanfile.py
+++ b/recipes/tree-sitter/all/test_package/conanfile.py
@@ -1,17 +1,27 @@
-from conans import ConanFile, CMake, tools
 import os
 
+from conan import ConanFile
+from conan.tools.cmake import CMake, cmake_layout
+from conan.tools.build import can_run
 
-class TestPackageConan(ConanFile):
-    settings = "os", "arch", "compiler", "build_type"
-    generators = "cmake", "cmake_find_package_multi"
+
+class TestPacakgeConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
+    test_type = "explicit"
+
+    def requirements(self):
+        self.requires(self.tested_reference_str)
 
     def build(self):
         cmake = CMake(self)
         cmake.configure()
         cmake.build()
 
+    def layout(self):
+        cmake_layout(self)
+
     def test(self):
-        if not tools.cross_building(self):
-            bin_path = os.path.join("bin", "test_package")
-            self.run(bin_path, run_environment=True)
+        if can_run(self):
+            bin_path = os.path.join(self.cpp.build.bindir, "test_package")
+            self.run(bin_path, env="conanrun")
diff --git a/recipes/tree-sitter/all/test_package/test_package.c b/recipes/tree-sitter/all/test_package/test_package.c
--- a/recipes/tree-sitter/all/test_package/test_package.c
+++ b/recipes/tree-sitter/all/test_package/test_package.c
@@ -1,8 +1,9 @@
 #include <tree_sitter/api.h>
 
-//More detailed example search at https://tree-sitter.github.io/tree-sitter/using-parsers#getting-started
+// More detailed example search at
+// https://tree-sitter.github.io/tree-sitter/using-parsers#getting-started
 int main() {
-    TSParser *parser = ts_parser_new();
-    ts_parser_delete(parser);
-    return 0;
+  TSParser *parser = ts_parser_new();
+  ts_parser_delete(parser);
+  return 0;
 }