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