forked from storypku/bazel_iwyu
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextensions.bzl
More file actions
50 lines (41 loc) · 1.5 KB
/
Copy pathextensions.bzl
File metadata and controls
50 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Module extensions for bazel_iwyu"""
load("//bazel:prebuilt_pkg.bzl", "prebuilt_pkg")
load("//bazel/iwyu:versions.bzl", "DEFAULT_VERSION", "SUPPORTED_VERSIONS")
def _iwyu_impl(module_ctx):
version = DEFAULT_VERSION
# Find the version requested by modules. We'll use the root module's request
# or the first version we find.
for mod in module_ctx.modules:
for tag in mod.tags.toolchain:
if tag.version:
version = tag.version
if version not in SUPPORTED_VERSIONS:
fail("Unsupported IWYU version: {}. Supported versions: {}".format(
version,
", ".join(SUPPORTED_VERSIONS.keys()),
))
version_info = SUPPORTED_VERSIONS[version]
urls = {platform: [info["url"]] for platform, info in version_info.items()}
sha256 = {platform: info["sha256"] for platform, info in version_info.items()}
strip_prefix = {platform: info["strip_prefix"] for platform, info in version_info.items()}
prebuilt_pkg(
name = "iwyu_prebuilt_pkg",
build_file = Label("//bazel/iwyu:BUILD.prebuilt_pkg"),
urls = urls,
sha256 = sha256,
strip_prefix = strip_prefix,
)
toolchain_tag = tag_class(
attrs = {
"version": attr.string(
doc = "The prebuilt IWYU version to use (e.g. '0.24.0', '0.25.0').",
default = DEFAULT_VERSION,
),
},
)
iwyu = module_extension(
implementation = _iwyu_impl,
tag_classes = {
"toolchain": toolchain_tag,
},
)