|
| 1 | +# Copyright 2018 The Bazel Authors. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Macro to translate Bazel modules into legacy WORKSPACE compatible repos. |
| 16 | +
|
| 17 | +Used only for Bazel modules that don't offer a legacy WORKSPACE compatible API |
| 18 | +already. This became necessary for bazel-worker-api which only provides bzlmod |
| 19 | +support. |
| 20 | +""" |
| 21 | + |
| 22 | +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| 23 | +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") |
| 24 | + |
| 25 | +def _bazel_worker_api_repo(name, strip_prefix): |
| 26 | + """Download bazel-worker-api from GitHub releases. |
| 27 | +
|
| 28 | + Args: |
| 29 | + name: The name of the repository to create. |
| 30 | + strip_prefix: The path within the archive to use as the root (e.g., "proto" or "java"). |
| 31 | + """ |
| 32 | + maybe( |
| 33 | + http_archive, |
| 34 | + name = name, |
| 35 | + sha256 = "5aac6ae6a23015cc7984492a114dc539effc244ec5ac7f8f6b1539c15fb376eb", |
| 36 | + urls = [ |
| 37 | + "https://github.com/bazelbuild/bazel-worker-api/releases/download/v0.0.6/bazel-worker-api-v0.0.6.tar.gz", |
| 38 | + ], |
| 39 | + strip_prefix = "bazel-worker-api-0.0.6/" + strip_prefix, |
| 40 | + ) |
| 41 | + |
| 42 | +def workspace_compat(): |
| 43 | + """Setup bazel-worker-api repositories for WORKSPACE. |
| 44 | +
|
| 45 | + This function creates the necessary repository rules for bazel-worker-api |
| 46 | + proto and java implementations, making them available in WORKSPACE mode. |
| 47 | + In bzlmod mode, these are loaded via bazel_dep in MODULE.bazel. |
| 48 | + """ |
| 49 | + |
| 50 | + # Proto definitions (worker_protocol.proto) |
| 51 | + _bazel_worker_api_repo( |
| 52 | + name = "bazel_worker_api", |
| 53 | + strip_prefix = "proto", |
| 54 | + ) |
| 55 | + |
| 56 | + # Java implementation (WorkRequestHandler, etc.) |
| 57 | + _bazel_worker_api_repo( |
| 58 | + name = "bazel_worker_java", |
| 59 | + strip_prefix = "java", |
| 60 | + ) |
0 commit comments