• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14"""Bazel rules for downloading CIPD packages."""
15
16load(
17    "//pw_env_setup/bazel/cipd_setup/internal:cipd_internal.bzl",
18    _cipd_client_impl = "cipd_client_impl",
19    _cipd_deps_impl = "cipd_deps_impl",
20    _cipd_repository_impl = "cipd_repository_impl",
21)
22
23_cipd_client_repository = repository_rule(
24    _cipd_client_impl,
25    attrs = {
26        "_cipd_digest_file": attr.label(default = "@pigweed//pw_env_setup:py/pw_env_setup/cipd_setup/.cipd_version.digests"),
27        "_cipd_version_file": attr.label(default = "@pigweed//pw_env_setup:py/pw_env_setup/cipd_setup/.cipd_version"),
28    },
29    doc = """
30Fetches the cipd client.
31
32This rule should not be used directly and instead should be called via
33the cipd_client_repository macro.
34""",
35)
36
37def cipd_client_repository():
38    """Fetches the cipd client.
39
40    Fetches the cipd client to the prescribed remote repository target
41    prefix 'cipd_client'. This rule should be called before a
42    cipd_repository rule is instantiated.
43    """
44    _cipd_client_repository(
45        name = "cipd_client",
46    )
47
48cipd_repository = repository_rule(
49    _cipd_repository_impl,
50    attrs = {
51        "build_file": attr.label(
52            allow_single_file = True,
53            doc = "Override the BUILD file in the new CIPD repository.",
54        ),
55        "path": attr.string(
56            doc = "Path within CIPD where this repository lives.",
57        ),
58        "tag": attr.string(
59            doc = "Tag specifying which version of the repository to fetch.",
60        ),
61        "_cipd_client": attr.label(
62            default = "@cipd_client//:cipd",
63            doc = "Location of the CIPD client binary (internal).",
64        ),
65    },
66    doc = """
67Downloads a singular CIPD dependency to the root of a remote repository.
68
69Example:
70
71    load(
72        "//pw_env_setup/bazel/cipd_setup:cipd_rules.bzl",
73        "cipd_client_repository",
74        "cipd_repository",
75    )
76
77    # Must be called before cipd_repository
78    cipd_client_repository()
79
80    cipd_repository(
81        name = "bloaty",
82        path = "pigweed/third_party/bloaty-embedded/${os=linux,mac}-${arch=amd64}",
83        tag = "git_revision:2d87d204057b419f5290f8d38b61b9c2c5b4fb52-2",
84    )
85""",
86)
87
88_pigweed_deps = repository_rule(
89    _cipd_deps_impl,
90    attrs = {
91        "_pigweed_packages_json": attr.label(
92            default = "@pigweed//pw_env_setup:py/pw_env_setup/cipd_setup/pigweed.json",
93        ),
94        "_upstream_testing_packages_json": attr.label(
95            default = "@pigweed//pw_env_setup:py/pw_env_setup/cipd_setup/testing.json",
96        ),
97    },
98)
99
100def pigweed_deps():
101    """Configures Pigweeds Bazel dependencies
102
103    Example:
104        load("@pigweed//pw_env_setup:pigweed_deps.bzl", "pigweed_deps")
105
106        pigweed_deps()
107
108        load("@cipd_deps//:cipd_init.bzl", "cipd_init")
109
110        cipd_init()
111"""
112    _pigweed_deps(
113        name = "cipd_deps",
114    )
115