Skip to content

Commit f915bd1

Browse files
committed
Update to latest version of go-tree-sitter
Include a patch to the build files generated by the go_repository to support building with uplevel files references.
1 parent c31f6cc commit f915bd1

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Unreleased changes template.
7474
Other changes:
7575
* (python_repository) Start honoring the `strip_prefix` field for `zstd` archives.
7676
* (pypi) {bzl:obj}`pip_parse.extra_hub_aliases` now works in WORKSPACE files.
77+
* (gazelle): Update to latest version of go-tree-sitter which supports python 3.12 syntax.
7778

7879
{#v0-0-0-fixed}
7980
### Fixed

gazelle/MODULE.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use_repo(
2222
"com_github_bmatcuk_doublestar_v4",
2323
"com_github_emirpasic_gods",
2424
"com_github_ghodss_yaml",
25-
"com_github_smacker_go_tree_sitter",
2625
"com_github_stretchr_testify",
2726
"in_gopkg_yaml_v2",
2827
"org_golang_x_sync",

gazelle/deps.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ def go_deps():
188188
go_repository(
189189
name = "com_github_smacker_go_tree_sitter",
190190
importpath = "github.com/smacker/go-tree-sitter",
191-
sum = "h1:7QZKUmQfnxncZIJGyvX8M8YeMfn8kM10j3J/2KwVTN4=",
192-
version = "v0.0.0-20240422154435-0628b34cbf9c",
191+
patch_args = ["-p1", "--fuzz=10", "--verbose"],
192+
patches = ["//:patches/0001-go-tree-sitter-build.patch"],
193+
sum = "h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=",
194+
version = "v0.0.0-20240827094217-dd81d9e9be82",
193195
)
194196
go_repository(
195197
name = "com_github_stretchr_objx",

gazelle/go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/bazelbuild/rules_python/gazelle
22

3-
go 1.19
3+
go 1.23
44

55
require (
66
github.com/bazelbuild/bazel-gazelle v0.31.1
@@ -9,7 +9,6 @@ require (
99
github.com/bmatcuk/doublestar/v4 v4.6.1
1010
github.com/emirpasic/gods v1.18.1
1111
github.com/ghodss/yaml v1.0.0
12-
github.com/smacker/go-tree-sitter v0.0.0-20240422154435-0628b34cbf9c
1312
github.com/stretchr/testify v1.9.0
1413
golang.org/x/sync v0.2.0
1514
gopkg.in/yaml.v2 v2.4.0
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/BUILD.bazel b/BUILD.bazel
2+
index 6aa29a3..155129f 100644
3+
--- a/BUILD.bazel
4+
+++ b/BUILD.bazel
5+
@@ -3,3 +3,9 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
6+
+filegroup(
7+
+ name = "common",
8+
+ srcs = ["alloc.h", "api.h", "array.h"],
9+
+ visibility = [":__subpackages__"],
10+
+)
11+
+
12+
go_library(
13+
name = "go-tree-sitter",
14+
srcs = [
15+
diff --git a/python/BUILD.bazel b/python/BUILD.bazel
16+
index 04c7312..b184ac8 100644
17+
--- a/python/BUILD.bazel
18+
+++ b/python/BUILD.bazel
19+
@@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
20+
go_library(
21+
name = "python",
22+
srcs = [
23+
+ "//:common",
24+
"binding.go",
25+
"parser.c",
26+
"parser.h",

gazelle/python/file_parser.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ func (p *FileParser) parseMain(ctx context.Context, node *sitter.Node) bool {
106106
if a.Type() == sitterNodeTypeIdentifier && a.Content(p.code) == "__name__" &&
107107
// at github.com/smacker/go-tree-sitter@latest (after v0.0.0-20240422154435-0628b34cbf9c we used)
108108
// "__main__" is the second child of b. But now, it isn't.
109-
// we cannot use the latest go-tree-sitter because of the top level reference in scanner.c.
110-
// https://github.com/smacker/go-tree-sitter/blob/04d6b33fe138a98075210f5b770482ded024dc0f/python/scanner.c#L1
111109
b.Type() == sitterNodeTypeString && string(p.code[b.StartByte()+1:b.EndByte()-1]) == "__main__" {
112110
return true
113111
}

0 commit comments

Comments
 (0)