问题
My question is about sub projects and working on them together with their dependencies in bazel.
I have a c++ project I'm working on. Call it project A.
Project A depends on 2 others I'm working on, B and C.
Project B also depends on project C.
so it looks like this.
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:
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 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 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.
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.
回答1:
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
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
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.
回答2:
So the overall solution I've found to work is to create a monorepo and use a tool like copybara to make standalone releases of each of the packages.
来源:https://stackoverflow.com/questions/51511993/how-can-work-on-an-external-dependency-and-my-project-at-the-same-time-in-bazel