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.

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测