forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_exclusions.bxl
71 lines (57 loc) · 2.27 KB
/
find_exclusions.bxl
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
# 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//cxx:omnibus.bzl",
"all_deps",
"get_omnibus_graph",
)
load(
"@prelude//linking:link_info.bzl",
"Linkage",
)
load(
"@prelude//linking:linkable_graph.bzl",
"LinkableGraph",
"LinkableGraphTSet",
)
def _skip_node(n):
# LUA isn't supported in analysis so we need to skip them.
if "lua_library" in n.rule_type:
return True
return False
def _find_exclusions_impl(ctx):
platform = (
"ovr_config//platform/linux:x86_64-fbcode-platform010-clang"
)
cquery = ctx.cquery(platform)
# Note: ideally we'd just do all of third-party here, but there are some
# targets files that don't parse there, so for now this adds ucc ad-hoc,
# which is depended on by Caffe2 (through Torch), which is where most of
# our large Omnibuses come from.
tp2_labels = cquery.eval("fbcode//third-party-buck/platform010/...")
tp2_labels += cquery.eval("fbsource//third-party/ucc/...")
nodes = list(tp2_labels)
nodes = [n for n in nodes if not _skip_node(n)]
all_analysis = ctx.analysis(nodes)
linkable_graphs = filter(None, [analysis.providers().get(LinkableGraph) for analysis in all_analysis.values()])
linkable_graph = ctx.actions_factory.tset(
LinkableGraphTSet,
children = [graph.nodes for graph in linkable_graphs],
)
linkable_graph = LinkableGraph(label = "bxl", nodes = linkable_graph)
omnibus_graph = get_omnibus_graph(linkable_graph, {}, {})
for label, node in omnibus_graph.nodes.items():
if node.preferred_linkage == Linkage("shared") and label not in omnibus_graph.roots:
omnibus_graph.excluded[label] = True
transitive_excluded = all_deps(omnibus_graph.nodes, omnibus_graph.excluded.keys())
transitive_excluded = [e.raw_target() for e in transitive_excluded]
transitive_excluded = sorted(transitive_excluded)
ctx.output.print_json(transitive_excluded)
find_exclusions = bxl(
impl = _find_exclusions_impl,
cli_args = {},
)