Kevin Goslar
Kevin Goslar

Reputation: 445

Creating a Bazel distdir for third-party dependencies

I am using Bazel on a codebase that uses SpringBoot and JUnit in an airgapped environment. Here are the commands I need to run in order to fetch all the third-party dependencies:

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

How do I make these dependencies available in an airgapped environment (where I cannot download things from the internet)? Does Bazel have a command that creates a download cache for third-party dependencies similar to https://docs.bazel.build/versions/master/guide.html#running-bazel-in-an-airgapped-environment? Said another way, can Bazel populate a directory that can be shared with other machines and used via --distdir there? Are there other ways to share Bazel's download cache?

Upvotes: 4

Views: 2101

Answers (1)

Vertexwahn
Vertexwahn

Reputation: 8172

Maybe bazel sync can help here. Via this command, you can create a resolved file (e.g. resolved.bzl)

bazel sync --experimental_repository_resolved_file=resolved.bzl

This file is a .json file. With content similar to this:

"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"
    }
]

You need now a little helper tool (python script - whatever) that visits each url/urls in the determined repositories and adds it to your --distdir folder.

Upvotes: 5

Related Questions