为Bazel中的Git_存储库指定多个Git Remote

为Bazel中的Git_存储库指定多个Git Remote,bazel,Bazel,我们的Bazel项目从GitHub上托管的私有Git存储库中提取代码 在某些环境中(碰巧都是macOS),我们希望使用SSH身份验证来访问repo。因此,对于这些环境,我们可以指定remote=git@github.com:orgname/reponame.git在new\u git\u repository规则中 在其他环境中(碰巧都是Linux),我们希望使用令牌身份验证通过HTTPS访问repo。对于这些环境,我们可以使用remote=https://github.com/orgname/

我们的Bazel项目从GitHub上托管的私有Git存储库中提取代码

在某些环境中(碰巧都是macOS),我们希望使用SSH身份验证来访问repo。因此,对于这些环境,我们可以指定
remote=git@github.com:orgname/reponame.git
new\u git\u repository
规则中

在其他环境中(碰巧都是Linux),我们希望使用令牌身份验证通过HTTPS访问repo。对于这些环境,我们可以使用
remote=https://github.com/orgname/reponame.git

如何创建在两种环境下都能工作的工作区文件?我试着像这样使用
select
调用:

new_git_repository(
   ...
   remote = select({
       "@bazel_tools//src/conditions:linux": "https://github.com/orgname/reponame.git",
       "@bazel_tools//src/conditions:darwin": "git@github.com:orgname/reponame.git",
   }),
)
但是我弄错了

ERROR: An error occurred during the fetch of repository 'myrepo':
   got value of type 'select' for attribute 'remote' of new_git_repository rule 'myrepo'; select may not be used in repository rules
如果
new\u git\u repository
有一个带列表的
remotes
选项(类似于
http\u archive
url
选项),那就太好了,但是它没有。
select()
可以与构建规则一起使用(用于可配置属性),但不能与存储库规则一起使用。我不认为有一个完全琐碎的方式来完成你所描述的

我真的会尝试统一身份验证方法,以及如何跨主机寻址和访问repo

如果由于某种原因无法实现,则可以定义“两个”依赖项:

new_git_repository(
   name = "some_repo_mac",
   remote = "git@github.com:orgname/reponame.git",
   ...
)

new_git_repository(
   name = "some_repo_linux",
   remote = "https://github.com/orgname/reponame.git",
   ...
)
并在稍后阶段执行
选择
(分辨率):

alias(
    name = "some_ext_lib",
    actual = select({
       "@bazel_tools//src/conditions:linux_x86_64": "@some_repo_linux//:lib",
       "@bazel_tools//src/conditions:darwin_x86_64": "@some_repo_mac//:lib",
    }),
    visibility = ["//visibility:public"],
)
它会污染依赖关系图,但实际上不会检索不需要的外部依赖关系

您还需要别名实际目标(每个一个),而不是通过外部依赖关系提供和访问的目标束

您可以使用一个宏和一个小的自定义规则来自动执行该过程,以生成基于
别名的选择器


或者,您可以继续编写一个git获取的自定义规则,并将其绑定到。至少在构建的这个阶段,我还没有立即意识到另一种访问主机操作系统信息的方法。

myrepo的来源是哪里?@MarcinOrlowski在。。。部分它应该是name=“myrepo”,但为了简洁起见,我把它删掉了。