Bazel – BUILD没有引用外部依赖。

huangapple go评论86阅读模式
英文:

Bazel - BUILD not referencing external dependency

问题

我正在尝试使用bazel运行一些grpc测试。
我正在使用"google.golang.org/grpc/credentials/insecure"来进行不安全的拨号。

当运行bazel test ...时,我收到以下错误:

no such package '@org_golang_google_grpc//credentials/insecure': BUILD file not found in directory 'credentials/insecure' of external repository @org_golang_google_grpc. Add a BUILD file to a directory to mark it as a package. and referenced by '//go/internal/handlers/helloworld:helloworld_test'

我使用gazelle生成我的BUILD文件,对于go_test,它输出如下内容:

go_test(
    name = "helloworld_test",
    srcs = ["helloworld_test.go"],
    deps = [
        ":helloworld",
        "//protos/helloworld",
        "@com_github_stretchr_testify//assert",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//credentials/insecure",
        "@org_golang_google_grpc//test/bufconn",
        "@org_uber_go_zap//:zap",
        "@org_uber_go_zap//zaptest",
    ],
)

我的go.mod文件包含以下依赖项:
google.golang.org/grpc v1.47.0

我的deps.bzl是由gazelle自动生成的:

go_repository(
    name = "org_golang_google_grpc",
    importpath = "google.golang.org/grpc",
    sum = "h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=",
    version = "v1.47.0",
)

我漏掉了什么?

英文:

I'm trying to run some grpc tests with bazel.
I'm using "google.golang.org/grpc/credentials/insecure" to dial insecurely.

When running bazel test ..., I get the following error:

no such package '@org_golang_google_grpc//credentials/insecure': BUILD file not found in directory 'credentials/insecure' of external repository @org_golang_google_grpc. Add a BUILD file to a directory to mark it as a package. and referenced by '//go/internal/handlers/helloworld:helloworld_test'

I am generating my BUILD files with gazelle which outputs this for the go_test

go_test(
    name = "helloworld_test",
    srcs = ["helloworld_test.go"],
    deps = [
        ":helloworld",
        "//protos/helloworld",
        "@com_github_stretchr_testify//assert",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//credentials/insecure",
        "@org_golang_google_grpc//test/bufconn",
        "@org_uber_go_zap//:zap",
        "@org_uber_go_zap//zaptest",
    ],
)

My go.mod file contains the dep:
google.golang.org/grpc v1.47.0

My deps.bzl is auto generated by gazelle:

go_repository(
    name = "org_golang_google_grpc",
    importpath = "google.golang.org/grpc",
    sum = "h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=",
    version = "v1.47.0",
)

What am I missing?

答案1

得分: 1

在 WORKSPACE 中,必须在调用 gazelle_dependencies() 之前调用由 gazelle 生成的本地 go_repositories(),如果尚不存在 org_golang_google_grpc 的古老版本,它将被定义,并且较新版本的本地 go_repository 将被静默忽略。参考链接

英文:

In the WORKSPACE, the local go_repositories() generated by gazelle must be called before gazelle_dependencies(), which will
define an ancient version of org_golang_google_grpc if it doesn't
exist yet and the local go_repository for the newer version will be
silently ignored. Reference

huangapple
  • 本文由 发表于 2022年6月19日 22:48:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/72677834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定