Skip to content

Commit 2af3c4d

Browse files
authored
Add run_analyzers option (#419)
Add run_analyzers option
1 parent 38bf1c6 commit 2af3c4d

File tree

8 files changed

+31
-12
lines changed

8 files changed

+31
-12
lines changed

docs/csharp_binary.md

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/csharp_library.md

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/csharp_test.md

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dotnet/private/rules/common/attrs.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ CSHARP_COMMON_ATTRS = dicts.add(
233233
default = "disable",
234234
values = ["disable", "enable", "warnings", "annotations"],
235235
),
236+
"run_analyzers": attr.bool(
237+
doc = "Controls whether analyzers run at build time.",
238+
mandatory = False,
239+
default = True,
240+
),
236241
},
237242
)
238243

dotnet/private/rules/csharp/actions/csharp_assembly.bzl

+10-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def AssemblyAction(
8181
warning_level,
8282
project_sdk,
8383
allow_unsafe_blocks,
84-
nullable):
84+
nullable,
85+
run_analyzers):
8586
"""Creates an action that runs the CSharp compiler with the specified inputs.
8687
8788
This macro aims to match the [C# compiler](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/listed-alphabetically), with the inputs mapping to compiler options.
@@ -117,6 +118,7 @@ def AssemblyAction(
117118
project_sdk: The project sdk being targeted
118119
allow_unsafe_blocks: Compiles the target with /unsafe
119120
nullable: Enable nullable context, or nullable warnings.
121+
run_analyzers: Enable analyzers.
120122
Returns:
121123
The compiled csharp artifacts.
122124
"""
@@ -176,6 +178,7 @@ def AssemblyAction(
176178
warning_level,
177179
allow_unsafe_blocks,
178180
nullable,
181+
run_analyzers,
179182
out_dll = out_dll,
180183
out_ref = out_ref,
181184
out_pdb = out_pdb,
@@ -220,6 +223,7 @@ def AssemblyAction(
220223
warning_level,
221224
allow_unsafe_blocks,
222225
nullable,
226+
run_analyzers,
223227
out_ref = out_iref,
224228
out_dll = out_dll,
225229
out_pdb = out_pdb,
@@ -253,6 +257,7 @@ def AssemblyAction(
253257
warning_level,
254258
allow_unsafe_blocks,
255259
nullable,
260+
run_analyzers,
256261
out_dll = None,
257262
out_ref = out_ref,
258263
out_pdb = None,
@@ -311,6 +316,7 @@ def _compile(
311316
warning_level,
312317
allow_unsafe_blocks,
313318
nullable,
319+
run_analyzers,
314320
out_dll = None,
315321
out_ref = None,
316322
out_pdb = None,
@@ -389,8 +395,9 @@ def _compile(
389395
format_ref_arg(args, depset(framework_files, transitive = [refs]))
390396

391397
# analyzers
392-
args.add_all(analyzer_assemblies, format_each = "/analyzer:%s")
393-
args.add_all(additionalfiles, format_each = "/additionalfile:%s")
398+
if run_analyzers:
399+
args.add_all(analyzer_assemblies, format_each = "/analyzer:%s")
400+
args.add_all(additionalfiles, format_each = "/additionalfile:%s")
394401

395402
# .cs files
396403
args.add_all(srcs)

dotnet/private/rules/csharp/binary.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def _compile_action(ctx, tfm):
4646
project_sdk = ctx.attr.project_sdk,
4747
allow_unsafe_blocks = ctx.attr.allow_unsafe_blocks,
4848
nullable = ctx.attr.nullable,
49+
run_analyzers = ctx.attr.run_analyzers,
4950
)
5051

5152
def _binary_private_impl(ctx):

dotnet/private/rules/csharp/library.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def _compile_action(ctx, tfm):
4545
project_sdk = ctx.attr.project_sdk,
4646
allow_unsafe_blocks = ctx.attr.allow_unsafe_blocks,
4747
nullable = ctx.attr.nullable,
48+
run_analyzers = ctx.attr.run_analyzers,
4849
)
4950

5051
def _library_impl(ctx):

dotnet/private/rules/csharp/test.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def _compile_action(ctx, tfm):
4848
project_sdk = ctx.attr.project_sdk,
4949
allow_unsafe_blocks = ctx.attr.allow_unsafe_blocks,
5050
nullable = ctx.attr.nullable,
51+
run_analyzers = ctx.attr.run_analyzers,
5152
)
5253

5354
def _csharp_test_impl(ctx):

0 commit comments

Comments
 (0)