Repository not defined and referenced
I don't know if this a bug or it is a configuration issue, but on my project that uses both Go and Python, I can't use Gazelle with python and golang since it gives the following error.
no such package '@com_github_bmatcuk_doublestar//': The repository '@com_github_bmatcuk_doublestar' could not be resolved: Repository '@com_github_bmatcuk_doublestar' is not defined and referenced by '@rules_python_gazelle_plugin//python:python'
This is my root BUILD.bazel.
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle_binary")
load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:prefix github.com/MachComputing/apps
gazelle_binary(
name = "gazelle",
languages = [
"@rules_python_gazelle_plugin//python:gazelle_binary", # Use gazelle from rules_python.
"@bazel_gazelle//language/go", # Built-in rule from gazelle for Golang.
],
visibility = ["//visibility:public"],
)
gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=NoteMC/go.work",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)
And this is my workspace:
# Declares that this directory is the root of a Bazel workspace.
# See https://docs.bazel.build/versions/main/build-ref.html#workspace
workspace(
# How this workspace would be referenced with absolute labels from another workspace
name = "machcompting_apps",
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "278b7ff5a826f3dc10f04feaf0b70d48b68748ccd512d7f98bf442077f043fe3",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
],
)
http_archive(
name = "bazel_gazelle",
sha256 = "d3fa66a39028e97d76f9e2db8f1b0c11c099e8e01bf363a923074784e451f809",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.33.0/bazel-gazelle-v0.33.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.33.0/bazel-gazelle-v0.33.0.tar.gz",
],
)
http_archive(
name = "rules_python",
sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036",
strip_prefix = "rules_python-0.25.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz",
)
http_archive(
name = "rules_python_gazelle_plugin",
sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036",
strip_prefix = "rules_python-0.25.0/gazelle",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz",
)
### Python Setup
# Next we load the setup and toolchain from rules_python.
load("@rules_python//python:repositories.bzl", "py_repositories")
# Perform general setup
py_repositories()
### Golang Setup
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("//:deps.bzl", "go_dependencies")
# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()
go_rules_dependencies()
go_register_toolchains(version = "1.20.5")
gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE.bazel")
I tried looking all over the docs but the closest thing I saw was the need to use gazelle-binary for a multilanguage project.
So maybe add a section on how to use Rules Python alongside other languages?
Thanks in advance.
I think you are missing
# To compile the rules_python gazelle extension from source,
# we must fetch some third-party go dependencies that it uses.
load("@rules_python_gazelle_plugin//:deps.bzl", _py_gazelle_deps = "gazelle_deps")
_py_gazelle_deps()
which is documented in the release notes snippet.
What is more, you should have
"@rules_python_gazelle_plugin//python", # Use gazelle from rules_python.
dependency when building the gazelle binary as your current setup won't produce the desired outcome.
Thanks I must have missed those steps on the documentation. I now have the following errors:
ERROR: /home/lukas/.cache/bazel/_bazel_lukas/d097f134efe29f375f1f1fa988d7c998/external/bazel_gazelle/rule/BUILD.bazel:3:11: no such target '@com_github_bazelbuild_buildtools//build:build': target 'build' not declared in package 'build' defined by /home/lukas/.cache/bazel/_bazel_lukas/d097f134efe29f375f1f1fa988d7c998/external/com_github_bazelbuild_buildtools/build/BUILD.bazel (Tip: use `query "@com_github_bazelbuild_buildtools//build:*"` to see all the targets in that package) and referenced by '@bazel_gazelle//rule:rule'
ERROR: /home/lukas/.cache/bazel/_bazel_lukas/d097f134efe29f375f1f1fa988d7c998/external/bazel_gazelle/rule/BUILD.bazel:3:11: no such target '@com_github_bazelbuild_buildtools//tables:tables': target 'tables' not declared in package 'tables' defined by /home/lukas/.cache/bazel/_bazel_lukas/d097f134efe29f375f1f1fa988d7c998/external/com_github_bazelbuild_buildtools/tables/BUILD.bazel (Tip: use `query "@com_github_bazelbuild_buildtools//tables:*"` to see all the targets in that package) and referenced by '@bazel_gazelle//rule:rule'
ERROR: Analysis of target '//:gazelle-update-repos' failed; build aborted:
INFO: Elapsed time: 1.302s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (79 packages loaded, 9377 targets configured)
ERROR: Build failed. Not running target
This now seems something related to buildtools, is there a fix?
I am not familiar with this error.
@MachComputing, could you please check if you are still facing the issue with the latest releases?
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!
This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"