• 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_version_file": attr.label(default = "@pigweed//pw_env_setup:py/pw_env_setup/cipd_setup/.cipd_version"),
27        "_cipd_digest_file": attr.label(default = "@pigweed//pw_env_setup:py/pw_env_setup/cipd_setup/.cipd_version.digests"),
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        "_cipd_client": attr.label(default = "@cipd_client//:cipd"),
52        "path": attr.string(),
53        "tag": attr.string(),
54    },
55    doc = """
56Downloads a singular CIPD dependency to the root of a remote repository.
57
58Example:
59
60    load(
61        "//pw_env_setup/bazel/cipd_setup:cipd_rules.bzl",
62        "cipd_client_repository",
63        "cipd_repository",
64    )
65
66    # Must be called before cipd_repository
67    cipd_client_repository()
68
69    cipd_repository(
70        name = "bloaty",
71        path = "pigweed/third_party/bloaty-embedded/${os=linux,mac}-${arch=amd64}",
72        tag = "git_revision:2d87d204057b419f5290f8d38b61b9c2c5b4fb52-2",
73    )
74""",
75)
76
77_pigweed_deps = repository_rule(
78    _cipd_deps_impl,
79    attrs = {
80        "_pigweed_packages_json": attr.label(
81            default = "@pigweed//pw_env_setup:py/pw_env_setup/cipd_setup/pigweed.json",
82        ),
83        "_python_packages_json": attr.label(
84            default = "@pigweed//pw_env_setup:py/pw_env_setup/cipd_setup/python.json",
85        ),
86    },
87)
88
89def pigweed_deps():
90    """Configures Pigweeds Bazel dependencies
91
92    Example:
93        load("@pigweed//pw_env_setup:pigweed_deps.bzl", "pigweed_deps")
94
95        pigweed_deps()
96
97        load("@cipd_deps//:cipd_init.bzl", "cipd_init")
98
99        cipd_init()
100"""
101    _pigweed_deps(
102        name = "cipd_deps",
103    )
104