Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run_analyzers option #419

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/csharp_binary.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions docs/csharp_library.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions docs/csharp_test.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dotnet/private/rules/common/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ CSHARP_COMMON_ATTRS = dicts.add(
default = "disable",
values = ["disable", "enable", "warnings", "annotations"],
),
"run_analyzers": attr.bool(
doc = "Controls whether analyzers run at build time.",
mandatory = False,
default = True,
),
},
)

Expand Down
13 changes: 10 additions & 3 deletions dotnet/private/rules/csharp/actions/csharp_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def AssemblyAction(
warning_level,
project_sdk,
allow_unsafe_blocks,
nullable):
nullable,
run_analyzers):
"""Creates an action that runs the CSharp compiler with the specified inputs.

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.
Expand Down Expand Up @@ -117,6 +118,7 @@ def AssemblyAction(
project_sdk: The project sdk being targeted
allow_unsafe_blocks: Compiles the target with /unsafe
nullable: Enable nullable context, or nullable warnings.
run_analyzers: Enable analyzers.
Returns:
The compiled csharp artifacts.
"""
Expand Down Expand Up @@ -176,6 +178,7 @@ def AssemblyAction(
warning_level,
allow_unsafe_blocks,
nullable,
run_analyzers,
out_dll = out_dll,
out_ref = out_ref,
out_pdb = out_pdb,
Expand Down Expand Up @@ -220,6 +223,7 @@ def AssemblyAction(
warning_level,
allow_unsafe_blocks,
nullable,
run_analyzers,
out_ref = out_iref,
out_dll = out_dll,
out_pdb = out_pdb,
Expand Down Expand Up @@ -253,6 +257,7 @@ def AssemblyAction(
warning_level,
allow_unsafe_blocks,
nullable,
run_analyzers,
out_dll = None,
out_ref = out_ref,
out_pdb = None,
Expand Down Expand Up @@ -311,6 +316,7 @@ def _compile(
warning_level,
allow_unsafe_blocks,
nullable,
run_analyzers,
out_dll = None,
out_ref = None,
out_pdb = None,
Expand Down Expand Up @@ -389,8 +395,9 @@ def _compile(
format_ref_arg(args, depset(framework_files, transitive = [refs]))

# analyzers
args.add_all(analyzer_assemblies, format_each = "/analyzer:%s")
args.add_all(additionalfiles, format_each = "/additionalfile:%s")
if run_analyzers:
args.add_all(analyzer_assemblies, format_each = "/analyzer:%s")
args.add_all(additionalfiles, format_each = "/additionalfile:%s")

# .cs files
args.add_all(srcs)
Expand Down
1 change: 1 addition & 0 deletions dotnet/private/rules/csharp/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _compile_action(ctx, tfm):
project_sdk = ctx.attr.project_sdk,
allow_unsafe_blocks = ctx.attr.allow_unsafe_blocks,
nullable = ctx.attr.nullable,
run_analyzers = ctx.attr.run_analyzers,
)

def _binary_private_impl(ctx):
Expand Down
1 change: 1 addition & 0 deletions dotnet/private/rules/csharp/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def _compile_action(ctx, tfm):
project_sdk = ctx.attr.project_sdk,
allow_unsafe_blocks = ctx.attr.allow_unsafe_blocks,
nullable = ctx.attr.nullable,
run_analyzers = ctx.attr.run_analyzers,
)

def _library_impl(ctx):
Expand Down
1 change: 1 addition & 0 deletions dotnet/private/rules/csharp/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _compile_action(ctx, tfm):
project_sdk = ctx.attr.project_sdk,
allow_unsafe_blocks = ctx.attr.allow_unsafe_blocks,
nullable = ctx.attr.nullable,
run_analyzers = ctx.attr.run_analyzers,
)

def _csharp_test_impl(ctx):
Expand Down