Skip to content

Commit

Permalink
(#18572) migrate tree-sitter to conan2
Browse files Browse the repository at this point in the history
* build: update to conan2

* build: bump version v0.20.8

* fix: fix lint errors

* fix: fix forgotten of bump version 0.20.8

* fix: migrate del to rm_safe in configure

* style: add newline to test-pacaage.c

* fix: add conan v1 test

* Add missing test_type, remove test_v1_package

* Dont import every tool

* Tooooooools

* some fixes

* Update recipes/tree-sitter/all/conanfile.py

---------

Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>
Co-authored-by: czoido <mrgalleta@gmail.com>
  • Loading branch information
3 people authored Jul 20, 2023
1 parent 8a8966a commit 9eabe04
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 45 deletions.
13 changes: 5 additions & 8 deletions recipes/tree-sitter/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
cmake_minimum_required(VERSION 3.4)
project(tree-sitter C)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

# Use cmake script instead of Makefile to support MSVC + follow fPIC option

file(GLOB SOURCES RELATIVE "${PROJECT_SOURCE_DIR}" source_subfolder/lib/src/*.c)
list(REMOVE_ITEM SOURCES source_subfolder/lib/src/lib.c)
file(GLOB SOURCES RELATIVE "${PROJECT_SOURCE_DIR}" src/lib/src/*.c)
list(REMOVE_ITEM SOURCES src/lib/src/lib.c)

file(GLOB HEADERS source_subfolder/lib/include/tree_sitter/*.h)
file(GLOB HEADERS src/lib/include/tree_sitter/*.h)

add_library(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME}
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/source_subfolder/lib/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/source_subfolder/lib/src>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/lib/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/lib/src>
)
set_target_properties(${PROJECT_NAME}
PROPERTIES
Expand Down
3 changes: 3 additions & 0 deletions recipes/tree-sitter/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"0.20.8":
url: "https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v0.20.8.tar.gz"
sha256: "6181ede0b7470bfca37e293e7d5dc1d16469b9485d13f13a605baec4a8b1f791"
"0.20.6":
url: "https://github.com/tree-sitter/tree-sitter/archive/v0.20.6.tar.gz"
sha256: "4d37eaef8a402a385998ff9aca3e1043b4a3bba899bceeff27a7178e1165b9de"
Expand Down
47 changes: 24 additions & 23 deletions recipes/tree-sitter/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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],
Expand All @@ -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"]
3 changes: 0 additions & 3 deletions recipes/tree-sitter/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
24 changes: 17 additions & 7 deletions recipes/tree-sitter/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 5 additions & 4 deletions recipes/tree-sitter/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions recipes/tree-sitter/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"0.20.8":
folder: all
"0.20.6":
folder: all
"0.20.0":
Expand Down

0 comments on commit 9eabe04

Please sign in to comment.