0

我想在一个项目上写一些分析脚本,并使用action_listeneraspect采取行动。但是,最好不要修改项目文件。有没有办法在不更改WORKSPACE文件的情况下添加一些外部依赖项?

4

1 回答 1

0

工作空间

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

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 = [
                "...",
                "...",
            ],
        )

仅在需要时才获取依赖项。因此,您可以考虑引入可配置的构建属性

于 2022-02-09T07:41:25.863 回答