douba9425 2018-03-25 15:06 采纳率: 100%
浏览 280
已采纳

项目具有内部依赖项时,bazel golang构建失败

I'm on MacOS 10.13.2. Go 1.10. bazel 0.11.1

I need to compile a repo that has 2 projects (project1 and project2). project1 has 2 subpacakges. p1lib and dep1 p1lib uses dep1.

I generate BUILD files with gazelle, files look ok.

gazelle -go_prefix=github.com/BazelBuildForGo

But when I run build I get an error that says that I'm missing direct dependency.

bazel build //project1
INFO: Analysed target //project1:project1 (3 packages loaded).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_user1/df78026a5ee0c7ed3d23dd05c3a3b1f7/external/com_github_wix_private_bazelbuildforgo/project1/p1lib/BUILD.bazel:3:1: GoCompile external/com_github_wix_private_bazelbuildforgo/project1/p1lib/darwin_amd64_stripped/go_default_library~/github.com/BazelBuildForGo/project1/p1lib.a failed (Exit 1)
2018/03/25 18:02:55 missing strict dependencies:
    external/com_github_wix_private_bazelbuildforgo/project1/p1lib/p1lib.go: import of github.com/wix-private/BazelBuildForGo/project1/dep1, which is not a direct dependency
Target //project1:project1 failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.358s, Critical Path: 0.12s
FAILED: Build did NOT complete successfully

My project can be found here https://github.com/wix-playground/BazelBuildForGo

  • 写回答

1条回答 默认 最新

  • dongxun8189 2018-03-26 15:31
    关注

    I think the problem is that the import prefix you passed to Gazelle on the command line (github.com/BazelBuildForGo) is different from the imports in the .go files (github.com/wix-private/BazelBuildForGo). When Gazelle sees imports that are outside the current prefix, it will generate external dependencies for those imports, and those dependencies will be missing:

    go_library(
        name = "go_default_library",
        srcs = ["p1lib.go"],
        importpath = "github.com/BazelBuildForGo/project1/p1lib",
        visibility = ["//visibility:public"],
        deps = ["@com_github_wix_private_bazelbuildforgo//project1/dep1:go_default_library"],
    )
    

    The fix for this is pretty easy though. Just run Gazelle with the prefix github.com/wix-private/BazelBuildForGo. You actually already have this in //:gazelle, so just run that, then rebuild.

    $ bazel run //:gazelle
    $ bazel build //...
    

    That will change the go_library rule above to this:

    go_library(
        name = "go_default_library",
        srcs = ["p1lib.go"],
        importpath = "github.com/wix-private/BazelBuildForGo/project1/p1lib",
        visibility = ["//visibility:public"],
        deps = ["//project1/dep1:go_default_library"],
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 angular项目错误
  • ¥20 需要帮我远程操控一下,运行一下我的那个代码,我觉得我无能为力了
  • ¥20 有偿:在ubuntu上安装arduino以及其常用库文件。
  • ¥15 请问用arcgis处理一些数据和图形,通常里面有一个根据点划泰森多边形的命令,直接划的弊端是只能执行一个完整的边界,但是我们有时候会用到需要在有很多边界内利用点来执行划泰森多边形的命令
  • ¥30 在wave2foam中执行setWaveField时遇到了如下的浮点异常问题,请问该如何解决呢?
  • ¥750 关于一道数论方面的问题,求解答!(关键词-数学方法)
  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件