Bazel enabled repo as a git submodule/subtree

1,238 views
Skip to first unread message

Sailesh Mittal

unread,
Dec 21, 2015, 2:06:00 PM12/21/15
to bazel-discuss
Hi all,

I have a use case where I want to put my_library, which has a WORKSPACE file at top since it is bazel enabled, to be included in another parent repo as a git subtree. I want the parent repo to be also bazel enabled. Is this setup possible?

For example, can I use relative paths in BUILD files instead of starting with "//" so that I can change the location of WORKSPACE? Or is there any clean way to do it at all?

Thanks,
Sailesh

Sailesh Mittal

unread,
Dec 21, 2015, 8:13:56 PM12/21/15
to bazel-discuss
Part of my answer is here:

Using git_repository and local_repository, I can achieve most of the things I was looking for.

Still have some questions about developing in these two different repos.

1. git_repository requires a commit or tag, which means any change in my_library must be accompanied by a commit in application repo. Can I say "latest"?

2. local_repository requires an absolute path to the repo. Can this is relative path so that I can make my_library as part of my application using git-subtree?

Thanks,
Sailesh

Kristina Chodorow

unread,
Dec 22, 2015, 10:07:58 AM12/22/15
to Sailesh Mittal, bazel-discuss
1. git_repository requires a commit or tag, which means any change in my_library must be accompanied by a commit in application repo. Can I say "latest"?

Bazel is designed to make builds as reproducible as possible: theoretically your build artifacts should be identical to those built on your coworker's machine if you both have the same copy of the code checked out.  Thus, allowing a tag like "latest" runs contrary to this design: depending on when you build your code, you'll get different results.

 
2. local_repository requires an absolute path to the repo. Can this is relative path so that I can make my_library as part of my application using git-subtree?

We're planning to allow this!  I've filed https://github.com/bazelbuild/bazel/issues/733 to track.

Sailesh Mittal

unread,
Dec 23, 2015, 2:11:42 AM12/23/15
to Kristina Chodorow, bazel-discuss
Thanks Kristina,


Since this change is probably not going to be released soon, is there a way to get current directory in WORKSPACE file? Some kind of bound variable?

Kristina Chodorow

unread,
Dec 28, 2015, 9:39:53 AM12/28/15
to Sailesh Mittal, bazel-discuss
Actually, yes, __workspace_dir__ should be a variable you can use in the WORKSPACE file. You can probably do something like:

local_repository(
    name = "x",
    path = __workspace_dir__ + "/foo/bar"
)

I've actually got a fix in progress for #733 that covers a couple other related rules (e.g., the android_*_repo functions) and has some unit tests.  It probably won't be in until January, though.

Sailesh Mittal

unread,
Dec 28, 2015, 12:59:16 PM12/28/15
to Kristina Chodorow, bazel-discuss
Thanks Kristina, __workspace_dir__ works like a charm, even with relative paths using "..".

Kristina Chodorow

unread,
Dec 28, 2015, 1:41:33 PM12/28/15
to Sailesh Mittal, bazel-discuss
Probably it shouldn't allow .., but good (I guess).
Reply all
Reply to author
Forward
0 new messages