dongza1708 2018-01-24 13:28
浏览 211
已采纳

对于瞪羚,如何使用WORKSPACE中定义的go_repository?

In my WORKSPACE, I have defined the go_repostitory for importpath golang.org/x/net.

go_repository(
   name = "org_golang_x_net",
   commit = "5ccada7d0a7ba9aeb5d3aca8d3501b4c2a509fec",
   importpath = "golang.org/x/net",
)

But when I run gazelle, the dependency added to BUILD.Bazel is not @org_golang_x_net//context:go_default_library. Instead, it is the following: //golang.org/x/net/context:go_default_library

Why does gazelle ignore the defined go_repository? Is there a way for it to consider deps defined in WORKSPACE?

  • 写回答

1条回答 默认 最新

  • dp0518 2018-01-25 16:15
    关注

    I'm guessing from your previous question this is because you're using an empty prefix.

    Gazelle resolves Go imports to Bazel labels in several steps:

    1. If there is a go_library in your workspace with a matching importpath, Gazelle will use the name of that library.
    2. If the import path is below the top-level prefix for your repository, the import will be considered "local", so you'll get a label like //golang.org/x/net/content:go_default_library.
      • Since you're using an empty prefix at the top level, this catch will catch every unknown import.
      • This should be improved. Gazelle's resolver should be aware of prefixes defined in different directories (currently, those are only used to determine the importpath attribute on generated rules). I've filed bazelbuild/bazel-gazelle#101 to fix that.
    3. If the import is not considered local, Gazelle will generate a label for an external repository or for the vendor directory, depending on the external mode.

    For now, you may want to add a directive to your top-level build file like:

    # gazelle:prefix __do_not_match__
    

    This will basically disable the second case, since no import will start with that. You'll still have an empty prefix in your src directory (set with # gazelle:prefix in src/BUILD.bazel), so your libraries will still have the correct importpath directives. You might want to set that to more specific subdirectories though.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常