-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.bzl
151 lines (138 loc) · 4.47 KB
/
tools.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Building boost results in many warnings. Downstream users won't be interested, so just disable them.
default_copts = select({
"@platforms//os:windows": ["/W0"],
"//conditions:default": ["-w"],
})
# + select({
# "//conditions:default": ["-std=c++17"],
# })
# TODO defines = [ "BOOST_NO_CXX20_HDR_RANGES",
# TODO set all to cxx20?
default_defines = select({
"@boost.rules.tools//:windows_x86_64": ["BOOST_ALL_NO_LIB"], # Turn auto_link off in MSVC compiler
"//conditions:default": [],
})
def boost_library(
name,
defines = [],
includes = ["include"],
hdrs = [],
srcs = [],
copts = [],
exclude_hdr = [],
exclude_src = [],
visibility = ["//visibility:public"],
alias_repo_name = None,
no_alias = False,
**kwargs):
if visibility == ["//visibility:public"] and not no_alias:
if alias_repo_name == None:
alias_repo_name = name
native.alias(
name = "boost." + alias_repo_name,
actual = "@boost." + alias_repo_name + "//:" + name,
visibility = ["//visibility:public"],
)
return native.cc_library(
name = name,
visibility = visibility,
defines = default_defines + defines,
includes = includes,
hdrs = native.glob(
["include/boost/**"],
exclude = exclude_hdr,
allow_empty = True,
) + hdrs,
srcs = native.glob(
["src/*"],
exclude = ["**/*.asm", "**/*.S", "**/*.doc"] + exclude_src,
allow_empty = True,
) + srcs,
copts = default_copts + copts,
**kwargs
)
def boost_test(
name,
size = "small",
srcs = [],
includes = [],
exclude_src = [],
deps = [],
file_extensions = ".cpp",
expect_fail = False,
**kwargs):
if expect_fail:
pass
else:
native.cc_test(
name = name + "_test",
size = size,
srcs = srcs + [name + file_extensions] + native.glob(
["**/*.hpp"],
exclude = exclude_src,
allow_empty = True,
),
includes = includes + ["."],
deps = deps,
**kwargs
)
return ":" + name + "_test"
def boost_test_set(
positive_test_names = None,
negative_test_names = [],
exclude_tests = [],
file_extensions = ".cpp",
**kwargs):
test_targets = []
if positive_test_names == None:
positive_test_names = native.glob(
["**/*{}".format(file_extensions)],
exclude = [name + file_extensions for name in exclude_tests] + [name + file_extensions for name in negative_test_names],
allow_empty = True,
)
extension_length = len(file_extensions)
positive_test_names = [name[:-extension_length] for name in positive_test_names]
for name in positive_test_names:
target_result = boost_test(name = name, file_extensions = file_extensions, expect_fail = False, **kwargs)
if target_result:
test_targets.append(target_result)
for name in negative_test_names:
target_result = boost_test(name = name, file_extensions = file_extensions, expect_fail = True, **kwargs)
if target_result:
test_targets.append(target_result)
return test_targets
# def boost_test(
# name,
# size = "small",
# srcs = [],
# exclude_src = [],
# deps = [],
# expect_fail = False,
# **kwargs):
# if expect_fail:
# # Generate a custom script that inverts the test result
# test_wrapper_name = name + "_wrapper.sh"
# native.genrule(
# name = test_wrapper_name,
# outs = [test_wrapper_name],
# cmd = "echo '#!/bin/bash' > $@ && " +
# "echo './$(location :%s)' >> $@ && " % name +
# "echo 'exit $((! $?))' >> $@",
# tools = [":" + test_wrapper_name],
# executable = True,
# )
# test_target = ":" + test_wrapper_name
# else:
# test_target = ":" + name
# native.cc_test(
# name = name,
# size = size,
# srcs = srcs + [name + ".cpp"] + native.glob(
# ["**/*.hpp"],
# exclude = exclude_src,
# allow_empty = True,
# ),
# deps = deps,
# **kwargs
# )
# return test_target