Skip to content

Commit 99b7610

Browse files
author
Gilles Roustan
committed
fix: add scanner.c to binding.gyp sources
1 parent c5a5869 commit 99b7610

14 files changed

Lines changed: 209 additions & 43 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
uses: actions/checkout@v4
3535
- name: Set up tree-sitter
3636
uses: tree-sitter/setup-action/cli@v1
37+
with:
38+
tree-sitter-ref: v0.25.10
3739
- name: Run tests
3840
uses: tree-sitter/parser-test-action@v2
3941
with:

CMakeLists.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
project(tree-sitter-gitcommit
4+
VERSION "0.4.0"
5+
DESCRIPTION "A tree-sitter grammar for git commit messages"
6+
HOMEPAGE_URL "https://github.com/gbprod/tree-sitter-gitcommit"
7+
LANGUAGES C)
8+
9+
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
10+
option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF)
11+
12+
set(TREE_SITTER_ABI_VERSION 15 CACHE STRING "Tree-sitter ABI version")
13+
if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$")
14+
unset(TREE_SITTER_ABI_VERSION CACHE)
15+
message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer")
16+
endif()
17+
18+
include(GNUInstallDirs)
19+
20+
find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI")
21+
22+
add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c"
23+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json"
24+
COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json
25+
--abi=${TREE_SITTER_ABI_VERSION}
26+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
27+
COMMENT "Generating parser.c")
28+
29+
add_library(tree-sitter-gitcommit src/parser.c)
30+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c)
31+
target_sources(tree-sitter-gitcommit PRIVATE src/scanner.c)
32+
endif()
33+
target_include_directories(tree-sitter-gitcommit
34+
PRIVATE src
35+
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/bindings/c>
36+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
37+
38+
target_compile_definitions(tree-sitter-gitcommit PRIVATE
39+
$<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR>
40+
$<$<CONFIG:Debug>:TREE_SITTER_DEBUG>)
41+
42+
set_target_properties(tree-sitter-gitcommit
43+
PROPERTIES
44+
C_STANDARD 11
45+
POSITION_INDEPENDENT_CODE ON
46+
SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}"
47+
DEFINE_SYMBOL "")
48+
49+
configure_file(bindings/c/tree-sitter-gitcommit.pc.in
50+
"${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-gitcommit.pc" @ONLY)
51+
52+
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/c/tree_sitter"
53+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
54+
FILES_MATCHING PATTERN "*.h")
55+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-gitcommit.pc"
56+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
57+
install(TARGETS tree-sitter-gitcommit
58+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
59+
60+
file(GLOB QUERIES queries/*.scm)
61+
install(FILES ${QUERIES}
62+
DESTINATION "${CMAKE_INSTALL_DATADIR}/tree-sitter/queries/gitcommit")
63+
64+
add_custom_target(ts-test "${TREE_SITTER_CLI}" test
65+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
66+
COMMENT "tree-sitter test")

binding.gyp

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/c/tree_sitter/tree-sitter-gitcommit.h

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/node/binding_test.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/python/tests/test_binding.py

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/swift/TreeSitterGitcommitTests/TreeSitterGitcommitTests.swift

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitcommit.so

1.22 MB
Binary file not shown.

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/gbprod/tree-sitter-gitcommit
2+
3+
go 1.22
4+
5+
require github.com/tree-sitter/go-tree-sitter v0.24.0

package-lock.json

Lines changed: 32 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)