简体   繁体   中英

How to load local_repository dependencies on external dependency in Bazel?

Project MAIN has multiple local_repository rules: A, B, C . They are added into a common macro and loaded by MAIN WORKSPACE file:

def load_dependencies():
  native.local_repository(name="A"...) # many of those
  ...

Now, I want to create new project NEW which depends on MAIN . MAIN is loaded by git_repository repository_rule.

How to properly load these local repositories?

I can't just hardcode absolute path to MAIN root dir since it is downloaded by git.

If MAIN is imported into NEW using a git_repository rule like this:

git_repository(
    name = "MAIN",
    <other stuff>
)

then you can load that macro into NEW's workspace and use it like this:

load("@MAIN//path/to:the_file.bzl", "load_dependencies")

load_dependencies()

git_repository is used instead of local_repository . They both create a Bazel repository which you can reference with labels. Once you have the git_repository , you don't need a path like you would with local_repository because it's already a repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM