-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprovider.bzl
123 lines (111 loc) · 4.53 KB
/
provider.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright 2015-2020 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
"""Functions generating or modifying the LispInfo provider struct."""
LispInfo = provider(
doc = "Information about a lisp_* target and its transitive dependencies.",
fields = {
"fasls": "Depset of FASLs for transitive dependencies",
"srcs": "Depset of transitive sources",
"hashes": "Depset of md5 hash files for transitive sources",
"warnings": (
"Depset of files of warnings checked at link time (FASL load) " +
"for transitive sources"
),
"features": "Depset of transitive declared Lisp features",
"compile_data": (
"Depset of files from transitive compile_data, made available " +
"at build time as well as runtime."
),
"cc_info": "CcInfo representing transitive C++ dependencies for linking",
},
)
def collect_lisp_info(deps = [], cdeps = [], build_image = None, features = [], compile_data = []):
"""Create a LispInfo collecting the data needed for Lisp compilation.
Args:
deps: Immediate Lisp dependencies of this target.
cdeps: Immediate C++ dependencies of this target.
build_image: Optional build image Target, which may also contain
dependencies. May be unset if this target just propagates LispInfo
from its dependencies.
features: Lisp features added by this target.
compile_data: Data dependency Targets of this target, which are made
available to this target and its consumers' at build time as well
as runtime.
Returns:
LispInfo
"""
lisp_infos = [dep[LispInfo] for dep in deps]
if build_image and LispInfo in build_image:
lisp_infos.append(build_image[LispInfo])
cc_infos = [lisp_info.cc_info for lisp_info in lisp_infos]
for cdep in cdeps:
cc_infos.append(cdep[CcInfo])
transitive_compile_data = [li.compile_data for li in lisp_infos]
for compile_data_target in compile_data:
default_info = compile_data_target[DefaultInfo]
if default_info.files:
transitive_compile_data.append(default_info.files)
if default_info.default_runfiles:
transitive_compile_data.append(default_info.default_runfiles.files)
return LispInfo(
fasls = depset(
transitive = [li.fasls for li in lisp_infos],
order = "postorder",
),
srcs = depset(
transitive = [li.srcs for li in lisp_infos],
order = "postorder",
),
hashes = depset(transitive = [li.hashes for li in lisp_infos]),
warnings = depset(transitive = [li.warnings for li in lisp_infos]),
features = depset(
features,
transitive = [li.features for li in lisp_infos],
),
compile_data = depset(transitive = transitive_compile_data),
cc_info = cc_common.merge_cc_infos(cc_infos = cc_infos),
)
def extend_lisp_info(
base,
fasls = [],
srcs = [],
hashes = [],
warnings = []):
"""Extends a LispInfo with compilation inputs and outputs.
Args:
base: The base LispInfo provider to be extended.
fasls: FASLs generated for this target.
srcs: This target's Lisp sources.
hashes: Hash files for each file in srcs.
warnings: Warnings files for each file in srcs.
"""
return LispInfo(
fasls = depset(fasls, transitive = [base.fasls], order = "postorder"),
srcs = depset(srcs, transitive = [base.srcs], order = "postorder"),
hashes = depset(hashes, transitive = [base.hashes]),
warnings = depset(warnings, transitive = [base.warnings]),
features = base.features,
compile_data = base.compile_data,
cc_info = base.cc_info,
)
# buildozer: disable=print
def print_provider(p):
"""Prints the LispInfo provider.
Args:
p: A LispInfo provider.
"""
if p.fasls:
print("FASLs: %s" % [f.short_path for f in p.fasls.to_list()])
if p.srcs:
print("Srcs: %s" % [s.short_path for s in p.srcs.to_list()])
if p.hashes:
print("Hashes: %s" % [h.short_path for h in p.hashes.to_list()])
if p.warnings:
print("Warnings: %s" % [w.short_path for w in p.warnings.to_list()])
if p.features:
print("Features: %s" % p.features.to_list())
if p.compile_data:
print("Compile Data: %s" % p.compile_data.to_list())