首页 > 解决方案 > 为第三方依赖创建 Bazel distdir

问题描述

我在一个在气隙环境中使用 SpringBoot 和 JUnit 的代码库上使用 Bazel。以下是我需要运行以获取所有第三方依赖项的命令:

bazel fetch '@bazel_tools//tools/build_defs/repo:*'
bazel fetch '@rules_java//java:*'
bazel fetch '@rules_cc//cc:*'
bazel fetch @local_config_platform//...
bazel fetch @local_config_sh//...
bazel fetch @maven//...
bazel fetch @org_opentest4j_opentest4j//jar:jar
bazel fetch @org_junit_jupiter_junit_jupiter_params//jar:jar
bazel fetch @org_junit_jupiter_junit_jupiter_engine//jar:jar
bazel fetch @org_junit_platform_junit_platform_console//jar:jar
bazel fetch @org_junit_platform_junit_platform_engine//jar:jar
bazel fetch @org_junit_platform_junit_platform_commons//jar:jar
bazel fetch @org_junit_platform_junit_platform_suite_api//jar:jar
bazel fetch @org_junit_platform_junit_platform_launcher//jar:jar
bazel fetch @org_apiguardian_apiguardian_api//jar:jar
bazel fetch @remote_coverage_tools//:coverage_report_generator
bazel fetch @remotejdk11_linux//:jdk

如何使这些依赖项在气隙环境中可用(我无法从 Internet 下载内容)?Bazel 是否具有为第三方依赖项创建下载缓存的命令,类似于https://docs.bazel.build/versions/master/guide.html#running-bazel-in-an-airgapped-environment?换句话说,Bazel 可以填充一个可以与其他机器共享并通过--distdir那里使用的目录吗?还有其他方法可以共享 Bazel 的下载缓存吗?

标签: bazel

解决方案


也许bazel sync可以在这里提供帮助。通过此命令,您可以创建一个已解析的文件(例如resolved.bzl

bazel sync --experimental_repository_resolved_file=resolved.bzl

该文件是一个 .json 文件。内容与此类似:

"repositories": [
    {
        "rule_class": "@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
        "attributes": {
            "url": "",
            "urls": [
                "https://github.com/embree/embree/archive/v2.16.5.zip"
            ],
            "sha256": "9c4c0c385a7725946648578c1b58e887caa8b4a675a9356e76b9501d9e2e9e42",
            "netrc": "",
            "auth_patterns": {},
            "canonical_id": "",
            "strip_prefix": "embree-2.16.5",
            "type": "",
            "patches": [],
            "patch_tool": "",
            "patch_args": [
                "-p0"
            ],
            "patch_cmds": [],
            "patch_cmds_win": [],
            "build_file": "//ThirdParty:embree.BUILD",
            "build_file_content": "",
            "workspace_file_content": "",
            "name": "embree"
        },
        "output_tree_hash": "b96d3a8db2ddd4bbc7ccde297a1d12e8be48c768bddde1ade53a4987861a1fe7"
    }
]

您现在需要一个小助手工具(python 脚本 - 不管),它访问确定的存储库中的每个url/urls并将其添加到您的--distdir文件夹中。


推荐阅读