Skip to content

Commit 53b38ca

Browse files
committed
Implement warning suppression by group
1 parent c28d697 commit 53b38ca

15 files changed

Lines changed: 540 additions & 9 deletions

File tree

doc/rules.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ its transitive dependencies be propagated.
458458
<pre>
459459
swift_library(<a href="#swift_library-name">name</a>, <a href="#swift_library-deps">deps</a>, <a href="#swift_library-srcs">srcs</a>, <a href="#swift_library-data">data</a>, <a href="#swift_library-always_include_developer_search_paths">always_include_developer_search_paths</a>, <a href="#swift_library-alwayslink">alwayslink</a>, <a href="#swift_library-copts">copts</a>,
460460
<a href="#swift_library-defines">defines</a>, <a href="#swift_library-generated_header_name">generated_header_name</a>, <a href="#swift_library-generates_header">generates_header</a>, <a href="#swift_library-library_evolution">library_evolution</a>, <a href="#swift_library-linkopts">linkopts</a>,
461-
<a href="#swift_library-linkstatic">linkstatic</a>, <a href="#swift_library-module_name">module_name</a>, <a href="#swift_library-package_name">package_name</a>, <a href="#swift_library-plugins">plugins</a>, <a href="#swift_library-private_deps">private_deps</a>, <a href="#swift_library-swiftc_inputs">swiftc_inputs</a>)
461+
<a href="#swift_library-linkstatic">linkstatic</a>, <a href="#swift_library-module_name">module_name</a>, <a href="#swift_library-package_name">package_name</a>, <a href="#swift_library-plugins">plugins</a>, <a href="#swift_library-private_deps">private_deps</a>, <a href="#swift_library-suppress_warning_groups">suppress_warning_groups</a>,
462+
<a href="#swift_library-swiftc_inputs">swiftc_inputs</a>)
462463
</pre>
463464

464465
Compiles and links Swift code into a static library and Swift module.
@@ -485,6 +486,7 @@ Compiles and links Swift code into a static library and Swift module.
485486
| <a id="swift_library-package_name"></a>package_name | The semantic package of the Swift target being built. Targets with the same package_name can access APIs using the 'package' access control modifier in Swift 5.9+. | String | optional | `""` |
486487
| <a id="swift_library-plugins"></a>plugins | A list of `swift_compiler_plugin` targets that should be loaded by the compiler when compiling this module and any modules that directly depend on it. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
487488
| <a id="swift_library-private_deps"></a>private_deps | A list of targets that are implementation-only dependencies of the target being built. Libraries/linker flags from these dependencies will be propagated to dependent for linking, but artifacts/flags required for compilation (such as .swiftmodule files, C headers, and search paths) will not be propagated.<br><br>Allowed kinds of dependencies are:<br><br>* `swift_library` (or anything propagating `SwiftInfo`)<br><br>* `cc_library` and `objc_library` (or anything propagating `CcInfo`) | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
489+
| <a id="swift_library-suppress_warning_groups"></a>suppress_warning_groups | A list of Swift diagnostic groups to suppress in build output (for example, `DeprecatedDeclaration`). These diagnostics are filtered from the compiler's output by the wrapper and do not change the compiler's behavior. See https://docs.swift.org/compiler/documentation/diagnostics/diagnostic-groups/ for available diagnostic groups. | List of strings | optional | `[]` |
488490
| <a id="swift_library-swiftc_inputs"></a>swiftc_inputs | Additional files that are referenced using `$(location ...)` in attributes that support location expansion. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
489491

490492

@@ -618,7 +620,7 @@ remaining modules collected are not present in the `aliases` of the
618620
<pre>
619621
swift_overlay(<a href="#swift_overlay-name">name</a>, <a href="#swift_overlay-deps">deps</a>, <a href="#swift_overlay-srcs">srcs</a>, <a href="#swift_overlay-always_include_developer_search_paths">always_include_developer_search_paths</a>, <a href="#swift_overlay-alwayslink">alwayslink</a>, <a href="#swift_overlay-copts">copts</a>, <a href="#swift_overlay-defines">defines</a>,
620622
<a href="#swift_overlay-library_evolution">library_evolution</a>, <a href="#swift_overlay-linkopts">linkopts</a>, <a href="#swift_overlay-linkstatic">linkstatic</a>, <a href="#swift_overlay-package_name">package_name</a>, <a href="#swift_overlay-plugins">plugins</a>, <a href="#swift_overlay-private_deps">private_deps</a>,
621-
<a href="#swift_overlay-swiftc_inputs">swiftc_inputs</a>)
623+
<a href="#swift_overlay-suppress_warning_groups">suppress_warning_groups</a>, <a href="#swift_overlay-swiftc_inputs">swiftc_inputs</a>)
622624
</pre>
623625

624626
A Swift overlay that sits on top of a C/Objective-C library, allowing an author
@@ -709,6 +711,7 @@ almost always an anti-pattern.
709711
| <a id="swift_overlay-package_name"></a>package_name | The semantic package of the Swift target being built. Targets with the same package_name can access APIs using the 'package' access control modifier in Swift 5.9+. | String | optional | `""` |
710712
| <a id="swift_overlay-plugins"></a>plugins | A list of `swift_compiler_plugin` targets that should be loaded by the compiler when compiling this module and any modules that directly depend on it. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
711713
| <a id="swift_overlay-private_deps"></a>private_deps | A list of targets that are implementation-only dependencies of the target being built. Libraries/linker flags from these dependencies will be propagated to dependent for linking, but artifacts/flags required for compilation (such as .swiftmodule files, C headers, and search paths) will not be propagated.<br><br>Allowed kinds of dependencies are:<br><br>* `swift_library` (or anything propagating `SwiftInfo`)<br><br>* `cc_library` and `objc_library` (or anything propagating `CcInfo`) | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
714+
| <a id="swift_overlay-suppress_warning_groups"></a>suppress_warning_groups | A list of Swift diagnostic groups to suppress in build output (for example, `DeprecatedDeclaration`). These diagnostics are filtered from the compiler's output by the wrapper and do not change the compiler's behavior. See https://docs.swift.org/compiler/documentation/diagnostics/diagnostic-groups/ for available diagnostic groups. | List of strings | optional | `[]` |
712715
| <a id="swift_overlay-swiftc_inputs"></a>swiftc_inputs | Additional files that are referenced using `$(location ...)` in attributes that support location expansion. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
713716

714717

@@ -772,7 +775,8 @@ swift_proto_compiler(<a href="#swift_proto_compiler-name">name</a>, <a href="#sw
772775
swift_proto_library(<a href="#swift_proto_library-name">name</a>, <a href="#swift_proto_library-deps">deps</a>, <a href="#swift_proto_library-srcs">srcs</a>, <a href="#swift_proto_library-data">data</a>, <a href="#swift_proto_library-additional_compiler_deps">additional_compiler_deps</a>, <a href="#swift_proto_library-additional_compiler_info">additional_compiler_info</a>,
773776
<a href="#swift_proto_library-always_include_developer_search_paths">always_include_developer_search_paths</a>, <a href="#swift_proto_library-alwayslink">alwayslink</a>, <a href="#swift_proto_library-compilers">compilers</a>, <a href="#swift_proto_library-copts">copts</a>, <a href="#swift_proto_library-defines">defines</a>,
774777
<a href="#swift_proto_library-generated_header_name">generated_header_name</a>, <a href="#swift_proto_library-generates_header">generates_header</a>, <a href="#swift_proto_library-library_evolution">library_evolution</a>, <a href="#swift_proto_library-linkopts">linkopts</a>, <a href="#swift_proto_library-linkstatic">linkstatic</a>,
775-
<a href="#swift_proto_library-module_name">module_name</a>, <a href="#swift_proto_library-package_name">package_name</a>, <a href="#swift_proto_library-plugins">plugins</a>, <a href="#swift_proto_library-protos">protos</a>, <a href="#swift_proto_library-swiftc_inputs">swiftc_inputs</a>)
778+
<a href="#swift_proto_library-module_name">module_name</a>, <a href="#swift_proto_library-package_name">package_name</a>, <a href="#swift_proto_library-plugins">plugins</a>, <a href="#swift_proto_library-protos">protos</a>, <a href="#swift_proto_library-suppress_warning_groups">suppress_warning_groups</a>,
779+
<a href="#swift_proto_library-swiftc_inputs">swiftc_inputs</a>)
776780
</pre>
777781

778782
Generates a Swift static library from one or more targets producing `ProtoInfo`.
@@ -837,6 +841,7 @@ swift_proto_library(
837841
| <a id="swift_proto_library-package_name"></a>package_name | The semantic package of the Swift target being built. Targets with the same package_name can access APIs using the 'package' access control modifier in Swift 5.9+. | String | optional | `""` |
838842
| <a id="swift_proto_library-plugins"></a>plugins | A list of `swift_compiler_plugin` targets that should be loaded by the compiler when compiling this module and any modules that directly depend on it. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
839843
| <a id="swift_proto_library-protos"></a>protos | A list of `proto_library` targets (or targets producing `ProtoInfo`), from which the Swift source files should be generated. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
844+
| <a id="swift_proto_library-suppress_warning_groups"></a>suppress_warning_groups | A list of Swift diagnostic groups to suppress in build output (for example, `DeprecatedDeclaration`). These diagnostics are filtered from the compiler's output by the wrapper and do not change the compiler's behavior. See https://docs.swift.org/compiler/documentation/diagnostics/diagnostic-groups/ for available diagnostic groups. | List of strings | optional | `[]` |
840845
| <a id="swift_proto_library-swiftc_inputs"></a>swiftc_inputs | Additional files that are referenced using `$(location ...)` in attributes that support location expansion. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
841846

842847

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("//swift:swift_library.bzl", "swift_library")
2+
3+
swift_library(
4+
name = "impl_dep",
5+
srcs = ["ImplDep.swift"],
6+
module_name = "ImplDep",
7+
)
8+
9+
swift_library(
10+
name = "impl_only_suppressed",
11+
srcs = ["ImplementationOnlySuppressed.swift"],
12+
private_deps = [":impl_dep"],
13+
suppress_warning_groups = ["ImplementationOnlyDeprecated"],
14+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public struct Dep {
2+
public init() {}
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@_implementationOnly import ImplDep
2+
3+
func useDepSuppressed() {
4+
_ = Dep()
5+
}

proto/swift_proto_utils.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ def compile_swift_protos_for_target(
271271
copts = expand_make_variables(ctx, copts, "copts")
272272
linkopts = expand_locations(ctx, getattr(attr, "linkopts", []), swiftc_inputs)
273273
linkopts = expand_make_variables(ctx, linkopts, "linkopts")
274+
suppress_warning_groups = getattr(attr, "suppress_warning_groups", [])
275+
if suppress_warning_groups:
276+
if "-print-diagnostic-groups" not in copts:
277+
copts.append("-print-diagnostic-groups")
278+
for group in suppress_warning_groups:
279+
copts.append(
280+
"-Xwrapped-swift=-suppress-warning-group={}".format(group),
281+
)
274282

275283
# Compile the generated Swift source files as a module:
276284
include_dev_srch_paths = include_developer_search_paths(attr)

swift/internal/attrs.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,15 @@ Note that by default, this value will default to True. But if the
323323
swift.enable_embedded feature is on, this value will be automatically overridden
324324
to False, as the swift features that cause -force_load to be required (such as
325325
reflection) are not available in that mode.
326+
""",
327+
),
328+
"suppress_warning_groups": attr.string_list(
329+
doc = """\
330+
A list of Swift diagnostic groups to suppress in build output (for example,
331+
`DeprecatedDeclaration`). These diagnostics are filtered from the compiler's
332+
output by the wrapper and do not change the compiler's behavior. See
333+
https://docs.swift.org/compiler/documentation/diagnostics/diagnostic-groups/
334+
for available diagnostic groups.
326335
""",
327336
),
328337
"generated_header_name": attr.string(

swift/swift_library.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ def _swift_library_impl(ctx):
129129
linkopts = expand_locations(ctx, ctx.attr.linkopts, ctx.attr.swiftc_inputs)
130130
linkopts = expand_make_variables(ctx, linkopts, "linkopts")
131131
srcs = ctx.files.srcs
132+
if ctx.attr.suppress_warning_groups:
133+
if "-print-diagnostic-groups" not in copts:
134+
copts.append("-print-diagnostic-groups")
135+
for group in ctx.attr.suppress_warning_groups:
136+
copts.append(
137+
"-Xwrapped-swift=-suppress-warning-group={}".format(
138+
group,
139+
),
140+
)
132141

133142
module_copts = additional_per_module_swiftcopts(
134143
ctx.label,

swift/swift_overlay.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ def _swift_overlay_impl(ctx):
4747
deps = ctx.attr.deps
4848
private_deps = ctx.attr.private_deps
4949

50+
copts = list(ctx.attr.copts)
51+
if ctx.attr.suppress_warning_groups:
52+
if "-print-diagnostic-groups" not in copts:
53+
copts.append("-print-diagnostic-groups")
54+
for group in ctx.attr.suppress_warning_groups:
55+
copts.append(
56+
"-Xwrapped-swift=-suppress-warning-group={}".format(
57+
group,
58+
),
59+
)
60+
5061
features = list(ctx.features)
5162
if ctx.attr.library_evolution:
5263
features.append(SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION)
@@ -59,7 +70,7 @@ def _swift_overlay_impl(ctx):
5970
label = ctx.label,
6071
srcs = ctx.files.srcs,
6172
additional_inputs = ctx.files.swiftc_inputs,
62-
copts = ctx.attr.copts,
73+
copts = copts,
6374
defines = ctx.attr.defines,
6475
disabled_features = ctx.disabled_features,
6576
enabled_features = ctx.features,

test/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ load(":private_deps_tests.bzl", "private_deps_test_suite")
2222
load(":private_swiftinterface_tests.bzl", "private_swiftinterface_test_suite")
2323
load(":runtime_deps_tests.bzl", "runtime_deps_test_suite")
2424
load(":split_derived_files_tests.bzl", "split_derived_files_test_suite")
25+
load(":suppress_warning_groups_tests.bzl", "suppress_warning_groups_test_suite")
2526
load(":swift_binary_linking_tests.bzl", "swift_binary_linking_test_suite")
2627
load(":swift_through_non_swift_tests.bzl", "swift_through_non_swift_test_suite")
2728
load(":symbol_graphs_tests.bzl", "symbol_graphs_test_suite")
@@ -69,6 +70,8 @@ private_deps_test_suite(name = "private_deps")
6970

7071
split_derived_files_test_suite(name = "split_derived_files")
7172

73+
suppress_warning_groups_test_suite(name = "suppress_warning_groups")
74+
7275
swift_binary_linking_test_suite(name = "swift_binary_rules")
7376

7477
swift_through_non_swift_test_suite(name = "swift_through_non_swift")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("//swift:swift_library.bzl", "swift_library")
2+
load("//swift:swift_overlay.bzl", "swift_overlay")
3+
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")
4+
5+
package(
6+
default_visibility = ["//test:__subpackages__"],
7+
)
8+
9+
swift_library(
10+
name = "single_category",
11+
srcs = ["Library.swift"],
12+
suppress_warning_groups = ["DeprecatedDeclaration"],
13+
tags = FIXTURE_TAGS,
14+
)
15+
16+
swift_library(
17+
name = "multiple_categories",
18+
srcs = ["Library.swift"],
19+
suppress_warning_groups = [
20+
"DeprecatedDeclaration",
21+
"ImplementationOnlyDeprecated",
22+
],
23+
tags = FIXTURE_TAGS,
24+
)
25+
26+
swift_overlay(
27+
name = "overlay",
28+
srcs = ["Overlay.swift"],
29+
suppress_warning_groups = ["OverlayDeprecated"],
30+
tags = FIXTURE_TAGS,
31+
)

0 commit comments

Comments
 (0)