blob: ebd6e7448a57c35284bd4c4b4653744977b5072c [file] [log] [blame]
Nathaniel Broughfc95cca2021-04-18 22:20:26 +08001# 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
15def _pigweed_config_impl(repository_ctx):
16 if repository_ctx.attr.build_file_content and \
17 repository_ctx.attr.build_file:
18 fail("Attributes 'build_file_content' and 'build_file' cannot both be \
19 defined at the same time.")
20 if not repository_ctx.attr.build_file_content and \
21 not repository_ctx.attr.build_file:
22 fail("Either 'build_file_content' or 'build_file' must be defined.")
23
24 if repository_ctx.name != "pigweed_config":
25 fail("This repository should be name 'pigweed_config'")
26
27 if repository_ctx.attr.build_file_content:
28 repository_ctx.file("BUILD", repository_ctx.attr.build_file_content)
29
30 if repository_ctx.attr.build_file:
31 repository_ctx.template("BUILD", repository_ctx.attr.build_file, {})
32
33pigweed_config = repository_rule(
34 _pigweed_config_impl,
35 attrs = {
36 "build_file_content": attr.string(
37 doc = "The build file content to configure Pigweed.",
38 mandatory = False,
39 default = "",
40 ),
41 "build_file": attr.label(
42 doc = "The label for the Pigweed config build file to use.",
43 mandatory = False,
44 default = "@pigweed//targets/host:host_config.BUILD",
45 ),
46 },
47 doc = """
48Configure Pigweeds backend implementations.
49
50Example:
51 # WORKSPACE
52 pigweed_config(
53 # This must use the exact name specified here otherwise this
54 # remote repository will not function as expected.
55 name = "pigweed_config",
56 build_file = "//path/to/config.BUILD",
57 )
58""",
59)