如何在bazel中同时处理外部依赖项和我的项目? [英] How can work on an external dependency and my project at the same time in bazel?

查看:346
本文介绍了如何在bazel中同时处理外部依赖项和我的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于子项目以及如何在bazel中对其进行依赖.

My question is about sub projects and working on them together with their dependencies in bazel.

我正在处理一个c ++项目.称为项目A.

I have a c++ project I'm working on. Call it project A.

项目A取决于我正在研究的另外两个项目B和C.

Project A depends on 2 others I'm working on, B and C.

项目B也取决于项目C.

Project B also depends on project C.

所以看起来像这样.

A -> (B, C)
B -> (C)
C -> no external dependencies

我希望能够并行处理这三个项目,但我希望保持它们独立.

I want to be able to work on these 3 projects in parallel, but I want to keep them independent.

我尝试了几种设置方法:

I have tried a few ways of setting this up:

  1. 我的WORKSPACE文件中git的外部依赖项.这里的问题是,当我希望对它们进行更改,就好像它们是一个较大的项目时,它们不会保持同步.该工作流程也非常麻烦,可以不断切换目录,推送我的存储库,返回到另一个目录并潜在地进行拉动(如果bazel决定这样做,仍然不知道如何强制执行此操作).

  1. External dependencies from git in my WORKSPACE file. Here the issue is that when I wish to make changes to them as if they were one larger project, they dont stay in sync. The workflow is also janky to constantly switch directories, push my repository, go back to the other, and pull potentially (if bazel decides to do it, still don't know how to force it).

Git子模块&存储库中的外部依赖关系.这里的问题出在CLion中,或者我用来跳转到引用的任何内容实际上都是从某个地方专门创建的bazel缓存中获取引用的,而不是我想要提交的实际回购.

Git submodules & external dependencies within the repository. Here the issue is in CLion or whatever I use to jump to the reference actually gets its reference from a speically created bazel cache somewhere, not the actual repo I wish to commit to.

Git子模块,其中的子模块只是我依赖的软件包. 这将是我最喜欢的解决方案,但是如果执行此操作,则每个子模块(全部存储在third_party或其他目录中)中的BUILD文件都是无效的,因为它们本身依赖于外部依赖关系.例如,项目B包括C作为外部依赖关系,而不是在我正在工作的工作空间中,而是在该工作空间C中是一个程序包.我能想到的处理这种情况的唯一方法是为包含Bazel库的每个程序包重写所有构建文件.这似乎没有效果.

Git submodules where the submodules are just packages that I depend on. This would be my favourite solution, but if I do this the BUILD files within each of the submodules (all stored in third_party or some other directory) are invalid, since they themselves depend on external dependencies. For example, project B includes C as an external dependency NOT in the workspace I'm working in, but in this workspace C is a package. The only way I can think of to manage THAT case is to rewrite all the build files for each package a Bazel library is included in in this way. This doesn't seem productive.

我知道在google上我们使用的是其他版本,我们将其全部保留在内部工作区中,但是bazel必须有解决方案才能做到这一点.

I know at google we use a different version of this and we keep it all in an internal workspace, but there must be a solution for bazel to do this.

推荐答案

对于类似的用例(在发送拉取请求之前测试对第三方依赖项的更改,我使用基于--override_repository的工作流.这告诉Bazel不要从Github中提取给定的外部存储库,但要在本地磁盘上使用副本.

For a similar use case (testing changes to third party dependencies before sending a pull request, I use a workflow based on --override_repository. This tells Bazel not to pull a given external repository from Github, but instead to use a copy on your local disk.

例如,在您的情况下,我可能具有以下布局:

For example, in your case I might have this layout:


> ls ~/git
project_a
project_b
project_c

我可以在~/git/project_b内部进行更改,然后按以下方式构建项目A:

I can make a change inside ~/git/project_b and then build Project A as follows:


cd ~/git/project_b
# edit files
cd ~/git/project_a
bazel build //... --override_repository com_github_username_project_b=$HOME/git/project_b

您还可以在.bazelrc上添加一行build --override_repository name=/path/to/repo,但我不想这样做,以免我提交的代码依赖于未提交的对依赖项的更改.

You could also add a line build --override_repository name=/path/to/repo to .bazelrc but I prefer not to do this, lest I submit code that depends on an unsubmitted change to a dependency.

这篇关于如何在bazel中同时处理外部依赖项和我的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆