简体   繁体   English

Bazel 构建:添加不在“WORKSPACE”中的额外依赖项

[英]Bazel build: Add extra dependencies not in `WORKSPACE`

I'd like to write some profiling scripts on a project, and use action_listener or aspect to take action.我想在一个项目上写一些分析脚本,并使用action_listeneraspect来采取行动。 However, it's better not modifying the project files.但是,最好不要修改项目文件。 Is there any way to add some external dependencies without change WORKSPACE file?有没有办法在不更改WORKSPACE文件的情况下添加一些外部依赖项?

WORKSPACE工作区

workspace(name = "my_workspace")

load("//:bazel/third_party/my_profile_deps.bzl", "my_profile_deps")

my_profile_deps()

bazel/third_party/my_profile_deps.bzl bazel/third_party/my_profile_deps.bzl

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def my_profile_deps():
    """Fetch my profile deps."""
    

    if True: # Switch to turn on/off
        # ... 
        maybe(
            http_archive,
            name = "some_lib",
            build_file = "...",
            sha256 = "...",
            strip_prefix = "..",
            urls = [
                "...",
                "...",
            ],
        )

Dependencies are only fetched if needed.仅在需要时才获取依赖项。 Therefore, you can think of introducing configurable build attributes .因此,可以考虑引入可配置的构建属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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