Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gazelle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
# gazelle:prefix github.com/bazel-contrib/rules_python/gazelle
# gazelle:exclude bazel-out
# gazelle:exclude deps.bzl
# gazelle:exclude internal
# gazelle:exclude internal_dev_deps.bzl
# gazelle:resolve go github.com/tree-sitter/tree-sitter-python/bindings/go @com_github_tree_sitter_tree_sitter_python//:go_default_library
gazelle(
name = "gazelle",
)
Expand Down Expand Up @@ -36,7 +38,7 @@ filegroup(
"//modules_mapping:distribution",
"//python:distribution",
"//pythonconfig:distribution",
],
] + glob(["internal/**"]),
visibility = ["@rules_python//:__pkg__"],
)

Expand Down
19 changes: 18 additions & 1 deletion gazelle/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,29 @@ use_repo(
"com_github_bmatcuk_doublestar_v4",
"com_github_emirpasic_gods",
"com_github_ghodss_yaml",
"com_github_smacker_go_tree_sitter",
"com_github_mattn_go_pointer",
"com_github_stretchr_testify",
"in_gopkg_yaml_v2",
"org_golang_x_sync",
)

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "com_github_tree_sitter_go_tree_sitter",
build_file = "//:internal/go_tree_sitter_BUILD.bazel",
integrity = "sha256-rAsyh/Kydqt24TBaA6H14obQlkaQWwj1QNec3xza6NM=",
strip_prefix = "go-tree-sitter-c9492002f76ed75037e3fe6d3bbabb54ed3e1ff5",
url = "https://github.com/tree-sitter/go-tree-sitter/archive/c9492002f76ed75037e3fe6d3bbabb54ed3e1ff5.zip",
)

http_archive(
name = "com_github_tree_sitter_tree_sitter_python",
build_file = "//:internal/tree_sitter_python_BUILD.bazel",
integrity = "sha256-e86IfrLzPpS/dKaWRc9RONQJZyDlT9MmmmEkwGuTxYQ=",
url = "https://github.com/tree-sitter/tree-sitter-python/releases/download/v0.25.0/tree-sitter-python.tar.gz",
)

python_stdlib_list = use_extension("//python:extensions.bzl", "python_stdlib_list")
use_repo(
python_stdlib_list,
Expand Down
54 changes: 46 additions & 8 deletions gazelle/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,49 @@ def python_stdlib_list_deps():
url = "https://files.pythonhosted.org/packages/8c/25/f1540879c8815387980e56f973e54605bd924612399ace31487f7444171c/stdlib_list-0.12.0.tar.gz",
)

def tree_sitter_deps():
"Fetch tree-sitter dependencies with custom BUILD files"
if "com_github_tree_sitter_go_tree_sitter" not in native.existing_rules():
http_archive(
name = "com_github_tree_sitter_go_tree_sitter",
build_file = Label("//:internal/go_tree_sitter_BUILD.bazel"),
integrity = "sha256-rAsyh/Kydqt24TBaA6H14obQlkaQWwj1QNec3xza6NM=",
strip_prefix = "go-tree-sitter-c9492002f76ed75037e3fe6d3bbabb54ed3e1ff5",
url = "https://github.com/tree-sitter/go-tree-sitter/archive/c9492002f76ed75037e3fe6d3bbabb54ed3e1ff5.zip",
)
if "com_github_tree_sitter_tree_sitter_python" not in native.existing_rules():
http_archive(
name = "com_github_tree_sitter_tree_sitter_python",
build_file = Label("//:internal/tree_sitter_python_BUILD.bazel"),
integrity = "sha256-e86IfrLzPpS/dKaWRc9RONQJZyDlT9MmmmEkwGuTxYQ=",
url = "https://github.com/tree-sitter/tree-sitter-python/releases/download/v0.25.0/tree-sitter-python.tar.gz",
)

def gazelle_deps():
tree_sitter_deps()
go_deps()
python_stdlib_list_deps()

def go_deps():
# Prevent `bazel run //:gazelle_update_repos` from generating `go_repository`
# entries for the repos managed by `tree_sitter_deps()` or for the 11 other
# language grammars required by upstream `go-tree-sitter/go.mod` for its own
# internal unit tests. Without these directives, `gazelle update-repos` sees
# those modules in `go list -m all` and re-adds them here; declaring
# `# gazelle:repository` directives tells `update-repos` to skip them.
# gazelle:repository http_archive name=com_github_tree_sitter_go_tree_sitter
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_c
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_cpp
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_embedded_template
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_go
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_html
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_java
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_javascript
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_json
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_php
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_python
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_ruby
# gazelle:repository http_archive name=com_github_tree_sitter_tree_sitter_rust
"Fetch go dependencies"
go_repository(
name = "com_github_bazelbuild_bazel_gazelle",
Expand Down Expand Up @@ -110,18 +148,18 @@ def go_deps():
sum = "h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=",
version = "v0.6.0",
)
go_repository(
name = "com_github_mattn_go_pointer",
importpath = "github.com/mattn/go-pointer",
sum = "h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=",
version = "v0.0.1",
)
go_repository(
name = "com_github_pmezard_go_difflib",
importpath = "github.com/pmezard/go-difflib",
sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=",
version = "v1.0.0",
)
go_repository(
name = "com_github_smacker_go_tree_sitter",
importpath = "github.com/smacker/go-tree-sitter",
sum = "h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=",
version = "v0.0.0-20240827094217-dd81d9e9be82",
)
go_repository(
name = "com_github_stretchr_objx",
importpath = "github.com/stretchr/objx",
Expand All @@ -131,8 +169,8 @@ def go_deps():
go_repository(
name = "com_github_stretchr_testify",
importpath = "github.com/stretchr/testify",
sum = "h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=",
version = "v1.9.0",
sum = "h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=",
version = "v1.10.0",
)
go_repository(
name = "in_gopkg_check_v1",
Expand Down
4 changes: 3 additions & 1 deletion gazelle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ require (
github.com/bmatcuk/doublestar/v4 v4.9.1
github.com/emirpasic/gods v1.18.1
github.com/ghodss/yaml v1.0.0
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82
github.com/stretchr/testify v1.9.0
github.com/tree-sitter/go-tree-sitter v0.24.1-0.20251112183152-c9492002f76e
github.com/tree-sitter/tree-sitter-python v0.25.0
golang.org/x/sync v0.11.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/sys v0.30.0 // indirect
Expand Down
8 changes: 6 additions & 2 deletions gazelle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82/go.mod h1:xe4pgH49k4SsmkQq5OT8abwhWmnzkhpgnXeekbx2efw=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tree-sitter/go-tree-sitter v0.24.1-0.20251112183152-c9492002f76e h1:B9WMBx89/TkqtmwfP+7OhREoGB6RdgmGk9ErlbiTOFI=
github.com/tree-sitter/go-tree-sitter v0.24.1-0.20251112183152-c9492002f76e/go.mod h1:r77ig7BikoZhHrrsjAnv8RqGti5rtSyvDHPzgTPsUuU=
github.com/tree-sitter/tree-sitter-python v0.25.0 h1:O6XD9v8U1LOcRc3cNj9nM7XufrtEBezE6VrpRrHZDf0=
github.com/tree-sitter/tree-sitter-python v0.25.0/go.mod h1:cpdthSy/Yoa28aJFBscFHlGiU+cnSiSh1kuDVtI8YeM=
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
Expand Down
47 changes: 47 additions & 0 deletions gazelle/internal/go_tree_sitter_BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Build file for github.com/tree-sitter/go-tree-sitter."""

load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
name = "tree_sitter_sources",
hdrs = glob([
"include/**/*.h",
"src/**/*.h",
"src/**/*.c",
]),
defines = [
"_DEFAULT_SOURCE",
"_POSIX_C_SOURCE=200112L",
],
includes = [
"include",
"src",
],
visibility = ["//visibility:private"],
)

go_library(
name = "go-tree-sitter",
srcs = glob(
["*.go"],
exclude = ["*_test.go"],
) + [
"allocator.c",
"allocator.h",
],
cdeps = [":tree_sitter_sources"],
cgo = True,
copts = [
"-std=c11",
],
importpath = "github.com/tree-sitter/go-tree-sitter",
visibility = ["//visibility:public"],
deps = ["@com_github_mattn_go_pointer//:go_default_library"],
)

alias(
name = "go_default_library",
actual = ":go-tree-sitter",
visibility = ["//visibility:public"],
)
36 changes: 36 additions & 0 deletions gazelle/internal/tree_sitter_python_BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Build file for github.com/tree-sitter/tree-sitter-python."""

load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
name = "tree_sitter_python_sources",
hdrs = [
"src/parser.c",
"src/scanner.c",
"src/tree_sitter/alloc.h",
"src/tree_sitter/array.h",
"src/tree_sitter/parser.h",
],
includes = ["bindings/go"],
visibility = ["//visibility:private"],
)

go_library(
name = "go",
srcs = ["bindings/go/binding.go"],
cdeps = [":tree_sitter_python_sources"],
cgo = True,
copts = [
"-std=c11",
"-fPIC",
],
importpath = "github.com/tree-sitter/tree-sitter-python/bindings/go",
visibility = ["//visibility:public"],
)

alias(
name = "go_default_library",
actual = ":go",
visibility = ["//visibility:public"],
)
4 changes: 2 additions & 2 deletions gazelle/manifest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ go_library(
importpath = "github.com/bazel-contrib/rules_python/gazelle/manifest",
visibility = ["//visibility:public"],
deps = [
"@com_github_emirpasic_gods//sets/treeset:go_default_library",
"@in_gopkg_yaml_v2//:go_default_library",
"@com_github_emirpasic_gods//sets/treeset",
"@in_gopkg_yaml_v2//:yaml_v2",
],
)

Expand Down
10 changes: 5 additions & 5 deletions gazelle/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ go_library(
"@bazel_gazelle//rule",
"@com_github_bazelbuild_buildtools//build",
"@com_github_bmatcuk_doublestar_v4//:doublestar",
"@com_github_emirpasic_gods//lists/singlylinkedlist:go_default_library",
"@com_github_emirpasic_gods//sets/treeset:go_default_library",
"@com_github_emirpasic_gods//utils:go_default_library",
"@com_github_smacker_go_tree_sitter//:go_default_library",
"@com_github_smacker_go_tree_sitter//python:go_default_library",
"@com_github_emirpasic_gods//lists/singlylinkedlist",
"@com_github_emirpasic_gods//sets/treeset",
"@com_github_emirpasic_gods//utils",
"@com_github_tree_sitter_go_tree_sitter//:go-tree-sitter",
"@com_github_tree_sitter_tree_sitter_python//:go_default_library",
"@org_golang_x_sync//errgroup",
],
)
Expand Down
Loading
Loading