forked from hexdae/toolchains_arm_gnu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensions.bzl
More file actions
81 lines (68 loc) · 2.08 KB
/
extensions.bzl
File metadata and controls
81 lines (68 loc) · 2.08 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
load(
"@arm_gnu_toolchain//:deps.bzl",
"arm_none_eabi_deps",
"arm_none_linux_gnueabihf_deps",
)
def compare_versions(left, right):
"""
Compare two version strings, assuming that they're both of the form
major.minor.patch.
Returns:
-1 if left < right
0 if left == right
1 if left > right
"""
left_parts = [int(i) for i in left.split('.')]
right_parts = [int(i) for i in right.split('.')]
for i in range(3):
if left_parts[0] < right_parts[0]:
return -1
if left_parts[0] > right_parts[0]:
return 1
return 0
def minimum_supported_version(versions):
"""Obtains the minimum version from the list of version strings."""
if not len(versions):
return None
if 1 == len(versions):
return versions[0]
minimum = versions[0]
for version in versions[1:]:
if compare_versions(minimum, version) > 0:
minimum = version
return minimum
def get_toolchain_versions(module_ctx, tag_class):
"""Extract toolchain versions from tag classes obtained by evaluating
the lambda on each module."""
versions = []
for mod in module_ctx.modules:
for attr in tag_class(mod):
versions.append(attr.version)
return versions
def _arm_toolchain_impl(ctx):
selected_baremetal_version = minimum_supported_version(
get_toolchain_versions(
ctx,
lambda mod: mod.tags.arm_none_eabi,
)
)
if selected_baremetal_version:
arm_none_eabi_deps(version = selected_baremetal_version)
selected_linux_version = minimum_supported_version(
get_toolchain_versions(
ctx,
lambda mod: mod.tags.arm_none_linux_gnueabihf,
)
)
if selected_linux_version:
arm_none_linux_gnueabihf_deps(version = selected_linux_version)
_toolchain = tag_class(attrs = {
"version": attr.string(),
})
arm_toolchain = module_extension(
implementation = _arm_toolchain_impl,
tag_classes = {
"arm_none_eabi": _toolchain,
"arm_none_linux_gnueabihf": _toolchain,
},
)