【问题标题】:How to specify a target BUILD file如何指定目标 BUILD 文件
【发布时间】:2018-09-12 17:15:41
【问题描述】:

我正在尝试构建/安装名为 envoy 的项目的依赖项。

项目目录如下所示:

$ ls -salt
total 176
 0 drwxr-xr-x.  3 app app    37 Aug 31 13:06 ..
 4 drwxrwxr-x. 16 app app  4096 Aug  4 02:28 .
 0 drwxrwxr-x.  2 app app    23 Aug  4 02:28 .circleci
 4 -rwxrwxr-x.  1 app app   259 Aug  4 02:28 .clang-format
 0 drwxrwxr-x.  2 app app    22 Aug  4 02:28 .github
 4 -rw-rw-r--.  1 app app   217 Aug  4 02:28 .gitignore
 4 -rw-rw-r--.  1 app app    61 Aug  4 02:28 BUILD
 4 -rw-rw-r--.  1 app app   433 Aug  4 02:28 CODEOWNERS
 4 -rw-rw-r--.  1 app app   139 Aug  4 02:28 CODE_OF_CONDUCT.md
12 -rw-rw-r--.  1 app app 10993 Aug  4 02:28 CONTRIBUTING.md
 4 -rw-rw-r--.  1 app app  1421 Aug  4 02:28 DCO
 8 -rw-rw-r--.  1 app app  4221 Aug  4 02:28 DEPRECATED.md
 4 -rw-rw-r--.  1 app app  2189 Aug  4 02:28 DEVELOPER.md
12 -rw-rw-r--.  1 app app  8202 Aug  4 02:28 GOVERNANCE.md
 4 -rw-rw-r--.  1 app app  1718 Aug  4 02:28 ISSUE_TEMPLATE.md
12 -rw-rw-r--.  1 app app 11358 Aug  4 02:28 LICENSE
 4 -rw-rw-r--.  1 app app   108 Aug  4 02:28 NOTICE
 4 -rw-rw-r--.  1 app app  2923 Aug  4 02:28 OWNERS.md
 4 -rw-rw-r--.  1 app app  2211 Aug  4 02:28 PULL_REQUEST_TEMPLATE.md
 8 -rw-rw-r--.  1 app app  4844 Aug  4 02:28 README.md
 8 -rw-rw-r--.  1 app app  6907 Aug  4 02:28 REPO_LAYOUT.md
16 -rw-rw-r--.  1 app app 13200 Aug  4 02:28 SECURITY_RELEASE_PROCESS.md
12 -rw-rw-r--.  1 app app 12085 Aug  4 02:28 STYLE.md
 4 -rw-rw-r--.  1 app app     6 Aug  4 02:28 VERSION
 4 -rw-rw-r--.  1 app app   514 Aug  4 02:28 WORKSPACE
 4 drwxrwxr-x.  9 app app  4096 Aug  4 02:28 api
 4 drwxrwxr-x.  3 app app  4096 Aug  4 02:28 bazel
 4 drwxrwxr-x.  4 app app  4096 Aug  4 02:28 ci
 4 drwxrwxr-x.  4 app app  4096 Aug  4 02:28 configs
 4 drwxrwxr-x.  3 app app  4096 Aug  4 02:28 docs
 4 drwxrwxr-x.  8 app app  4096 Aug  4 02:28 examples
 0 drwxrwxr-x.  3 app app    18 Aug  4 02:28 include
 0 drwxrwxr-x.  2 app app    41 Aug  4 02:28 restarter
 0 drwxrwxr-x.  7 app app    70 Aug  4 02:28 source
 0 drwxrwxr-x.  3 app app    50 Aug  4 02:28 support
 4 drwxrwxr-x. 15 app app  4096 Aug  4 02:28 test
 4 drwxrwxr-x.  6 app app  4096 Aug  4 02:28 tools

有两个bazelWORKSPACE文件:

$ find . -iname WORKSPACE
./WORKSPACE 
./ci/WORKSPACE

我想我必须从顶层目录构建 bazel 本机依赖项,​​但我不知道如何指定目标 BUILD 文件。您能否在bazel build 上提供建议 命令来实现它?

编辑: 我正在尝试构建步骤#2 中提到的内容https://github.com/envoyproxy/envoy/blob/master/bazel/README.md

编辑#2:$ bazel build //source/exe:envoy

我收到以下错误

WARNING: /home/app/.cache/bazel/_bazel_app/93cf2aaa5a193ee1dca34ebc2235b4f8/external/com_github_grpc_grpc/BUILD:1972:1: in srcs attribute of cc_library rule @com_github_grpc_grpc//:grpc_nanopb: please do not import '@com_github_grpc_grpc//third_party/nanopb:pb_common.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/app/.cache/bazel/_bazel_app/93cf2aaa5a193ee1dca34ebc2235b4f8/external/com_github_grpc_grpc/bazel/grpc_build_system.bzl:172:12
WARNING: /home/app/.cache/bazel/_bazel_app/93cf2aaa5a193ee1dca34ebc2235b4f8/external/com_github_grpc_grpc/BUILD:1972:1: in srcs attribute of cc_library rule @com_github_grpc_grpc//:grpc_nanopb: please do not import '@com_github_grpc_grpc//third_party/nanopb:pb_decode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/app/.cache/bazel/_bazel_app/93cf2aaa5a193ee1dca34ebc2235b4f8/external/com_github_grpc_grpc/bazel/grpc_build_system.bzl:172:12
WARNING: /home/app/.cache/bazel/_bazel_app/93cf2aaa5a193ee1dca34ebc2235b4f8/external/com_github_grpc_grpc/BUILD:1972:1: in srcs attribute of cc_library rule @com_github_grpc_grpc//:grpc_nanopb: please do not import '@com_github_grpc_grpc//third_party/nanopb:pb_encode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/app/.cache/bazel/_bazel_app/93cf2aaa5a193ee1dca34ebc2235b4f8/external/com_github_grpc_grpc/bazel/grpc_build_system.bzl:172:12
ERROR: /home/app/.cache/bazel/_bazel_app/93cf2aaa5a193ee1dca34ebc2235b4f8/external/io_bazel_rules_go/proto/BUILD.bazel:21:1: no such package '@org_golang_x_net//context': failed to fetch org_golang_x_net: 2018/09/12 03:10:46 unrecognized import path "golang.org/x/net"
 and referenced by '@io_bazel_rules_go//proto:go_grpc'
ERROR: Analysis of target '//source/exe:envoy' failed; build aborted: no such package '@org_golang_x_net//context': failed to fetch org_golang_x_net: 2018/09/12 03:10:46 unrecognized import path "golang.org/x/net"
INFO: Elapsed time: 73.577s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (253 packages loaded)

您能否提供进一步的建议?

编辑#3:为了完整起见,我在scl 下运行它,这样我就有了更新的 GCC 版本

- name: "Install envoy dependencies"
        yum: name="{{ item }}" state=latest
        with_items:
          - cmake
          - libtool
          - libstdc++
          - bazel
          - centos-release-scl
          - devtoolset-7-gcc-c++   # scl enable devtoolset-7 bash
        environment:
          http_proxy: "{{ prx.http }}"
          https_proxy: "{{ prx.https }}"

意思是我通过输入scl enable devtoolset-7 bash 进入shell,然后输入通常的东西

【问题讨论】:

  • 你到底想要构建什么?
  • 感谢@Jin 对其进行调查,请参阅编辑

标签: bazel


【解决方案1】:

来自DEVELOPER.md,构建 Envoy:

$ bazel build //source/exe:envoy

这个//source/exe:envoy 目标在source/exe/BUILD 中定义。

运行所有测试:

$ bazel test //test/...

... 递归地引用所有目标。

运行特定的测试,例如async_client_impl_test 定义在 test/common/http/BUILD 中。 //test/common/http 是包名。

$ bazel test //test/common/http:async_client_impl_test

您可以从项目目录中的任何位置运行这些命令,因为绝对目标标签中有//

【讨论】:

  • 嗨@Jin 感谢您的提示,但这是关于构建特使本身,而不是它的依赖项。在此之前有 2 个步骤(第 3 部分依赖项和 bazel 依赖项),因此问题是关于这 2 个步骤。
  • 您不需要直接构建它们。 Bazel 了解 Envoy 或其测试依赖于 Bazel 原生的 deps,因此当您自己构建 Envoy 时,这些 deps 将在 Envoy 之前自动构建。
  • 如果你想显式地从 Bazel 本机外部 dep 构建目标,请指定目标标签语法:@<repository name>//package/name:target
  • 请参阅 EDIT#2,根据文档,我不应该独立构建每个目标,对吗?如果我错了,请纠正我
  • 您使用的是什么版本的 Bazel,以及您构建的 Envoy 的哪个提交?我刚刚用 Bazel 0.16.0 构建了 Envoy master。
【解决方案2】:

你可以试试“go get -u google.golang.org/grpc”看看它是否有效?

【讨论】:

  • 是的,这行得通$ go get -u -v google.golang.org/grpc Fetching https://google.golang.org/grpc?go-get=1 Parsing meta tags from https://google.golang.org/grpc?go-get=1 (status code 200) ...
  • 我在 EDIT#2 上添加了更多关于失败前错误消息的信息
  • 所以手动去获取grpc包后无法识别的路径从grpc变成了golang.org/x/net?
  • 感谢@lyuxuan 调查它,但我没有关注你:) 请您进一步详细说明吗?
  • 在你上网编辑之前,我记得错误信息是unrecognized import path "google.golang.org/grpc"。在编辑之后,它显示unrecognized import path "golang.org/x/net"。这就是我在之前评论中的意思,询问go get -u google.golang.org/grpc 是否更改了错误消息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多