forked from facebook/buck2-prelude
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink_groups.bzl
75 lines (70 loc) · 2.33 KB
/
link_groups.bzl
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
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load(
"@prelude//utils:dicts.bzl",
"flatten_x",
)
load(
":link_info.bzl",
"LinkInfos",
)
load(
":shared_libraries.bzl",
"SharedLibraries",
)
# Information about a linkable node which explicitly sets `link_group`.
LinkGroupLib = record(
# The label of the owning target (if any).
label = field([Label, None], None),
# The shared libs to package for this link group.
shared_libs = field(SharedLibraries),
# The link info to link against this link group.
shared_link_infos = field(LinkInfos),
)
# Provider propagating info about transitive link group libs.
LinkGroupLibInfo = provider(fields = {
# A map of link group names to their shared libraries.
"libs": provider_field(typing.Any, default = None), # dict[str, LinkGroupLib]
})
def gather_link_group_libs(
libs: list[dict[str, LinkGroupLib]] = [],
children: list[LinkGroupLibInfo] = [],
deps: list[Dependency] = []) -> dict[str, LinkGroupLib]:
"""
Return all link groups libs deps and top-level libs.
"""
return flatten_x(
(libs +
[c.libs for c in children] +
[d[LinkGroupLibInfo].libs for d in deps if LinkGroupLibInfo in d]),
fmt = "conflicting link group roots for \"{0}\": {1} != {2}",
)
def merge_link_group_lib_info(
label: [Label, None] = None,
name: [str, None] = None,
shared_libs: [SharedLibraries, None] = None,
shared_link_infos: [LinkInfos, None] = None,
deps: list[Dependency] = [],
children: list[LinkGroupLibInfo] = []) -> LinkGroupLibInfo:
"""
Merge and return link group info libs from deps and the current rule wrapped
in a provider.
"""
libs = {}
if name != None:
libs[name] = LinkGroupLib(
label = label,
shared_libs = shared_libs,
shared_link_infos = shared_link_infos,
)
return LinkGroupLibInfo(
libs = gather_link_group_libs(
libs = [libs],
deps = deps,
children = children,
),
)