@@ -4,28 +4,159 @@ UNIT = "unit"
4
4
# Name for a integration test
5
5
INTEGRATION = "integration"
6
6
7
+ def _common_c_opts (nocopts , pedantic = False ):
8
+ # The following are set by default by Bazel:
9
+ # -Wall, -Wunused-but-set-parameter, -Wno-free-heap-object
10
+ copts = [
11
+ "-Werror" ,
12
+ "-Wcast-align" ,
13
+ "-Wcast-qual" ,
14
+ "-Wchar-subscripts" ,
15
+ "-Wcomment" ,
16
+ "-Wconversion" ,
17
+ "-Wdisabled-optimization" ,
18
+ "-Wextra" ,
19
+ "-Wfloat-equal" ,
20
+ "-Wformat" ,
21
+ "-Wformat-security" ,
22
+ "-Wformat-y2k" ,
23
+ "-Wimplicit-fallthrough" ,
24
+ "-Wimport" ,
25
+ "-Winit-self" ,
26
+ "-Winvalid-pch" ,
27
+ "-Wmissing-braces" ,
28
+ "-Wmissing-field-initializers" ,
29
+ "-Wparentheses" ,
30
+ "-Wpointer-arith" ,
31
+ "-Wredundant-decls" ,
32
+ "-Wreturn-type" ,
33
+ "-Wsequence-point" ,
34
+ "-Wshadow" ,
35
+ "-Wsign-compare" ,
36
+ "-Wstack-protector" ,
37
+ "-Wswitch" ,
38
+ "-Wswitch-default" ,
39
+ "-Wswitch-enum" ,
40
+ "-Wtrigraphs" ,
41
+ "-Wuninitialized" ,
42
+ "-Wunknown-pragmas" ,
43
+ "-Wunreachable-code" ,
44
+ "-Wunused" ,
45
+ "-Wunused-function" ,
46
+ "-Wunused-label" ,
47
+ "-Wunused-parameter" ,
48
+ "-Wunused-value" ,
49
+ "-Wunused-variable" ,
50
+ "-Wvolatile-register-var" ,
51
+ "-Wwrite-strings" ,
52
+ "-Wno-error=deprecated-declarations" ,
53
+ #TODO: [BUILD-405] - Figure out why build breaks with this flag
54
+ #"-Wmissing-include-dirs"
55
+ ]
56
+
57
+ # filter nocopts from the default list
58
+ copts = [copt for copt in copts if copt not in nocopts ]
59
+
60
+ if pedantic :
61
+ copts .append ("-pedantic" )
62
+
63
+ return copts
64
+
7
65
def swift_cc_library (** kwargs ):
8
66
"""Wraps cc_library to enforce standards for a production library.
67
+
68
+ Primarily this consists of a default set of compiler options and
69
+ language standards.
70
+
71
+ Production targets (swift_cc*), are compiled with the -pedantic flag.
72
+
73
+ Args:
74
+ **kwargs: See https://bazel.build/reference/be/c-cpp#cc_library
75
+
76
+ An additional attribute nocopts is supported. This
77
+ attribute takes a list of flags to remove from the
78
+ default compiler options. Use judiciously.
9
79
"""
80
+ nocopts = kwargs .pop ("nocopts" , []) # pop because nocopts is a deprecated cc* attr.
81
+
82
+ copts = _common_c_opts (nocopts , pedantic = True )
83
+ kwargs ["copts" ] = (kwargs ["copts" ] if "copts" in kwargs else []) + copts
84
+
10
85
native .cc_library (** kwargs )
11
86
12
87
def swift_cc_tool_library (** kwargs ):
13
88
"""Wraps cc_library to enforce standards for a non-production library.
89
+
90
+ Primarily this consists of a default set of compiler options and
91
+ language standards.
92
+
93
+ Non-production targets (swift_cc_tool*), are compiled without the
94
+ -pedantic flag.
95
+
96
+ Args:
97
+ **kwargs: See https://bazel.build/reference/be/c-cpp#cc_library
98
+
99
+ An additional attribute nocopts is supported. This
100
+ attribute takes a list of flags to remove from the
101
+ default compiler options. Use judiciously.
14
102
"""
103
+ nocopts = kwargs .pop ("nocopts" , [])
104
+
105
+ copts = _common_c_opts (nocopts , pedantic = False )
106
+ kwargs ["copts" ] = (kwargs ["copts" ] if "copts" in kwargs else []) + copts
107
+
15
108
native .cc_library (** kwargs )
16
109
17
110
def swift_cc_binary (** kwargs ):
18
111
"""Wraps cc_binary to enforce standards for a production binary.
112
+
113
+ Primarily this consists of a default set of compiler options and
114
+ language standards.
115
+
116
+ Production targets (swift_cc*), are compiled with the -pedantic flag.
117
+
118
+ Args:
119
+ **kwargs: See https://bazel.build/reference/be/c-cpp#cc_binary
120
+
121
+ An additional attribute nocopts is supported. This
122
+ attribute takes a list of flags to remove from the
123
+ default compiler options. Use judiciously.
19
124
"""
125
+ nocopts = kwargs .pop ("nocopts" , [])
126
+
127
+ copts = _common_c_opts (nocopts , pedantic = True )
128
+ kwargs ["copts" ] = (kwargs ["copts" ] if "copts" in kwargs else []) + copts
129
+
20
130
native .cc_binary (** kwargs )
21
131
22
132
def swift_cc_tool (** kwargs ):
23
133
"""Wraps cc_binary to enforce standards for a non-production binary.
134
+
135
+ Primarily this consists of a default set of compiler options and
136
+ language standards.
137
+
138
+ Non-production targets (swift_cc_tool*), are compiled without the
139
+ -pedantic flag.
140
+
141
+ Args:
142
+ **kwargs: See https://bazel.build/reference/be/c-cpp#cc_binary
143
+
144
+ An additional attribute nocopts is supported. This
145
+ attribute takes a list of flags to remove from the
146
+ default compiler options. Use judiciously.
24
147
"""
148
+ nocopts = kwargs .pop ("nocopts" , [])
149
+
150
+ copts = _common_c_opts (nocopts , pedantic = False )
151
+ kwargs ["copts" ] = (kwargs ["copts" ] if "copts" in kwargs else []) + copts
152
+
25
153
native .cc_binary (** kwargs )
26
154
27
155
def swift_cc_test_library (** kwargs ):
28
156
"""Wraps cc_library to enforce Swift test library conventions.
157
+
158
+ Args:
159
+ **kwargs: See https://bazel.build/reference/be/c-cpp#cc_test
29
160
"""
30
161
native .cc_library (** kwargs )
31
162
@@ -38,6 +169,8 @@ def swift_cc_test(name, type, **kwargs):
38
169
39
170
These are passed to cc_test as tags which enables running
40
171
these test types seperately: `bazel test --test_tag_filters=unit //...`
172
+
173
+ **kwargs: See https://bazel.build/reference/be/c-cpp#cc_test
41
174
"""
42
175
43
176
if not (type == UNIT or type == INTEGRATION ):
0 commit comments