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

Do not warn when invoking APIs that has SupportedOSPlatformGuard attribute #7326

Merged
merged 4 commits into from
Jun 14, 2024

Conversation

buyaa-n
Copy link
Contributor

@buyaa-n buyaa-n commented Jun 11, 2024

Do not warn when invoking Guard APIs that has SupportedOSPlatformGuard attribute

Fixes issue @ManickaP encountered on https://github.com/dotnet/runtime/compare/main...ManickaP:runtime:quic-platform-guard?expand=1

Added unit test that reproes the issue

Repro:

[assembly: System.Runtime.Versioning.SupportedOSPlatform(""windows"")]
[assembly: System.Runtime.Versioning.SupportedOSPlatform(""linux"")]
[assembly: System.Runtime.Versioning.SupportedOSPlatform(""osx"")]

namespace System.Net.Quic;
public sealed partial class QuicConnection
{
    [SupportedOSPlatformGuard("windows")]
    [SupportedOSPlatformGuard("linux")]
    [SupportedOSPlatformGuard("osx")]
    public static bool IsSupported => false;
    ...
}

The Guard API used from another assembly, should not warn on QuicConnection.IsSupported invocation

namespace System.Net.Http;
internal sealed partial class HttpConnectionPool : IDisposable
{
    private async ValueTask<QuicConnection> ConnectAsync(CancellationToken cancellationToken) ()
    {
        if (QuicConnection.IsSupported) // Currently warning here, fixing this
        {
            await QuicConnection.ConnectAsync(new QuicClientConnectionOptions(), cancellationToken).ConfigureAwait(false);
        }
    }
}

@buyaa-n buyaa-n requested a review from a team as a code owner June 11, 2024 22:02
@buyaa-n
Copy link
Contributor Author

buyaa-n commented Jun 11, 2024

@sharwell there is something broke in the repo, normal build succeeds but dotnet build /t:pack fails with MSBuild error:
How can I fix this? cc @mavasani

Microsoft.CodeAnalysis.PublicApiAnalyzers.Package failed with 1 error(s) (1.0s)
    D:\dotnet\roslyn-analyzers\eng\GenerateAnalyzerNuspec.targets(113,5): error MSB3073: The command ""D:\dotnet\roslyn-analyzers\.dotnet\dotnet.exe" --roll-forward major "D:\dotnet\roslyn-analyzers\artifacts\bin\GenerateDocumentationAndConfigFiles\Debug\net9.0\GenerateDocumentationAndConfigFiles.dll" "-validateOnly:false" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PublicApiAnalyzers.Package\Debug\netstandard2.0\Rulesets" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PublicApiAnalyzers.Package\Debug\netstandard2.0\Editorconfig" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PublicApiAnalyzers.Package\Debug\netstandard2.0\GlobalAnalyzerConfigs" "D:\dotnet\roslyn-analyzers\artifacts\bin\\" "Debug" "netstandard2.0" "Microsoft.CodeAnalysis.PublicApiAnalyzers.dll;Microsoft.CodeAnalysis.PublicApiAnalyzers.CodeFixes.dll" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PublicApiAnalyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.PublicApiAnalyzers.props" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PublicApiAnalyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.PublicApiAnalyzers.targets" "" "D:\dotnet\roslyn-analyzers\src\PublicApiAnalyzers" "Microsoft.CodeAnalysis.PublicApiAnalyzers.md" "D:\dotnet\roslyn-analyzers\src\PublicApiAnalyzers" "Microsoft.CodeAnalysis.PublicApiAnalyzers.sarif" "3.11.0" Microsoft.CodeAnalysis.PublicApiAnalyzers false true "" false" exited with code -2147450730.
  Roslyn.Diagnostics.Analyzers.Package failed with 1 error(s) (3.2s)
    D:\dotnet\roslyn-analyzers\eng\GenerateAnalyzerNuspec.targets(113,5): error MSB3073: The command ""D:\dotnet\roslyn-analyzers\.dotnet\dotnet.exe" --roll-forward major "D:\dotnet\roslyn-analyzers\artifacts\bin\GenerateDocumentationAndConfigFiles\Debug\net9.0\GenerateDocumentationAndConfigFiles.dll" "-validateOnly:false" "D:\dotnet\roslyn-analyzers\artifacts\obj\Roslyn.Diagnostics.Analyzers.Package\Debug\netstandard2.0\Rulesets" "D:\dotnet\roslyn-analyzers\artifacts\obj\Roslyn.Diagnostics.Analyzers.Package\Debug\netstandard2.0\Editorconfig" "D:\dotnet\roslyn-analyzers\artifacts\obj\Roslyn.Diagnostics.Analyzers.Package\Debug\netstandard2.0\GlobalAnalyzerConfigs" "D:\dotnet\roslyn-analyzers\artifacts\bin\\" "Debug" "netstandard2.0" "Roslyn.Diagnostics.Analyzers.dll;Roslyn.Diagnostics.CSharp.Analyzers.dll;Roslyn.Diagnostics.VisualBasic.Analyzers.dll" "D:\dotnet\roslyn-analyzers\artifacts\obj\Roslyn.Diagnostics.Analyzers.Package\Debug\netstandard2.0\Build" "Roslyn.Diagnostics.Analyzers.props" "D:\dotnet\roslyn-analyzers\artifacts\obj\Roslyn.Diagnostics.Analyzers.Package\Debug\netstandard2.0\Build" "Roslyn.Diagnostics.Analyzers.targets" "" "D:\dotnet\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers" "Roslyn.Diagnostics.Analyzers.md" "D:\dotnet\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers" "Roslyn.Diagnostics.Analyzers.sarif" "3.11.0" Roslyn.Diagnostics.Analyzers false true "" false" exited with code -2147450730.
  Microsoft.CodeAnalysis.ResxSourceGenerator.Package failed with 1 error(s) (1.3s)
    D:\dotnet\roslyn-analyzers\eng\GenerateAnalyzerNuspec.targets(113,5): error MSB3073: The command ""D:\dotnet\roslyn-analyzers\.dotnet\dotnet.exe" --roll-forward major "D:\dotnet\roslyn-analyzers\artifacts\bin\GenerateDocumentationAndConfigFiles\Debug\net9.0\GenerateDocumentationAndConfigFiles.dll" "-validateOnly:false" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.ResxSourceGenerator.Package\Debug\netstandard2.0\Rulesets" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.ResxSourceGenerator.Package\Debug\netstandard2.0\Editorconfig" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.ResxSourceGenerator.Package\Debug\netstandard2.0\GlobalAnalyzerConfigs" "D:\dotnet\roslyn-analyzers\artifacts\bin\\" "Debug" "netstandard2.0" "Microsoft.CodeAnalysis.ResxSourceGenerator.dll;Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.dll;Microsoft.CodeAnalysis.ResxSourceGenerator.VisualBasic.dll" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.ResxSourceGenerator.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.ResxSourceGenerator.props" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.ResxSourceGenerator.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.ResxSourceGenerator.targets" "" "D:\dotnet\roslyn-analyzers\src\Microsoft.CodeAnalysis.ResxSourceGenerator" "Microsoft.CodeAnalysis.ResxSourceGenerator.md" "D:\dotnet\roslyn-analyzers\src\Microsoft.CodeAnalysis.ResxSourceGenerator" "Microsoft.CodeAnalysis.ResxSourceGenerator.sarif" "3.11.0" Microsoft.CodeAnalysis.ResxSourceGenerator false true "true" false" exited with code -2147450730.
  Microsoft.CodeAnalysis.NetAnalyzers.Package failed with 1 error(s) (1.5s)
    D:\dotnet\roslyn-analyzers\eng\GenerateAnalyzerNuspec.targets(113,5): error MSB3073: The command ""D:\dotnet\roslyn-analyzers\.dotnet\dotnet.exe" --roll-forward major "D:\dotnet\roslyn-analyzers\artifacts\bin\GenerateDocumentationAndConfigFiles\Debug\net9.0\GenerateDocumentationAndConfigFiles.dll" "-validateOnly:false" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.NetAnalyzers.Package\Debug\netstandard2.0\Rulesets" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.NetAnalyzers.Package\Debug\netstandard2.0\Editorconfig" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.NetAnalyzers.Package\Debug\netstandard2.0\GlobalAnalyzerConfigs" "D:\dotnet\roslyn-analyzers\artifacts\bin\\" "Debug" "netstandard2.0" "Microsoft.CodeAnalysis.NetAnalyzers.dll;Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll;Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers.dll" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.NetAnalyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.NetAnalyzers.props" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.NetAnalyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.NetAnalyzers.targets" "DisableNETAnalyzersForNuGetPackage.props" "D:\dotnet\roslyn-analyzers\src\NetAnalyzers" "Microsoft.CodeAnalysis.NetAnalyzers.md" "D:\dotnet\roslyn-analyzers\src\NetAnalyzers" "Microsoft.CodeAnalysis.NetAnalyzers.sarif" "9.0.0" Microsoft.CodeAnalysis.NetAnalyzers true true "" false" exited with code -2147450730.
  Microsoft.CodeAnalysis.Analyzers.Package failed with 1 error(s) (0.8s)
    D:\dotnet\roslyn-analyzers\eng\GenerateAnalyzerNuspec.targets(113,5): error MSB3073: The command ""D:\dotnet\roslyn-analyzers\.dotnet\dotnet.exe" --roll-forward major "D:\dotnet\roslyn-analyzers\artifacts\bin\GenerateDocumentationAndConfigFiles\Debug\net9.0\GenerateDocumentationAndConfigFiles.dll" "-validateOnly:false" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.Analyzers.Package\Debug\netstandard2.0\Rulesets" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.Analyzers.Package\Debug\netstandard2.0\Editorconfig" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.Analyzers.Package\Debug\netstandard2.0\GlobalAnalyzerConfigs" "D:\dotnet\roslyn-analyzers\artifacts\bin\\" "Debug" "netstandard2.0" "Microsoft.CodeAnalysis.Analyzers.dll;Microsoft.CodeAnalysis.CSharp.Analyzers.dll;Microsoft.CodeAnalysis.VisualBasic.Analyzers.dll" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.Analyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.Analyzers.props" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.Analyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.Analyzers.targets" "" "D:\dotnet\roslyn-analyzers\src\Microsoft.CodeAnalysis.Analyzers" "Microsoft.CodeAnalysis.Analyzers.md" "D:\dotnet\roslyn-analyzers\src\Microsoft.CodeAnalysis.Analyzers" "Microsoft.CodeAnalysis.Analyzers.sarif" "3.11.0" Microsoft.CodeAnalysis.Analyzers false true "" false" exited with code -2147450730.
  Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.Package failed with 1 error(s) (0.6s)
    D:\dotnet\roslyn-analyzers\eng\GenerateAnalyzerNuspec.targets(113,5): error MSB3073: The command ""D:\dotnet\roslyn-analyzers\.dotnet\dotnet.exe" --roll-forward major "D:\dotnet\roslyn-analyzers\artifacts\bin\GenerateDocumentationAndConfigFiles\Debug\net9.0\GenerateDocumentationAndConfigFiles.dll" "-validateOnly:false" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.Package\Debug\netstandard2.0\Rulesets" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.Package\Debug\netstandard2.0\Editorconfig" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.Package\Debug\netstandard2.0\GlobalAnalyzerConfigs" "D:\dotnet\roslyn-analyzers\artifacts\bin\\" "Debug" "netstandard2.0" "Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.dll;Microsoft.CodeAnalysis.CSharp.PerformanceSensitiveAnalyzers.dll;Microsoft.CodeAnalysis.CSharp.PerformanceSensitiveAnalyzers.CodeFixes.dll" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.props" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.targets" "" "D:\dotnet\roslyn-analyzers\src\PerformanceSensitiveAnalyzers" "Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.md" "D:\dotnet\roslyn-analyzers\src\PerformanceSensitiveAnalyzers" "Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.sarif" "3.11.0" Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers false true "" false" exited with code -2147450730.
  Microsoft.CodeAnalysis.BannedApiAnalyzers.Package failed with 1 error(s) (0.2s)
    D:\dotnet\roslyn-analyzers\eng\GenerateAnalyzerNuspec.targets(113,5): error MSB3073: The command ""D:\dotnet\roslyn-analyzers\.dotnet\dotnet.exe" --roll-forward major "D:\dotnet\roslyn-analyzers\artifacts\bin\GenerateDocumentationAndConfigFiles\Debug\net9.0\GenerateDocumentationAndConfigFiles.dll" "-validateOnly:false" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.BannedApiAnalyzers.Package\Debug\netstandard2.0\Rulesets" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.BannedApiAnalyzers.Package\Debug\netstandard2.0\Editorconfig" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.BannedApiAnalyzers.Package\Debug\netstandard2.0\GlobalAnalyzerConfigs" "D:\dotnet\roslyn-analyzers\artifacts\bin\\" "Debug" "netstandard2.0" "Microsoft.CodeAnalysis.BannedApiAnalyzers.dll;Microsoft.CodeAnalysis.CSharp.BannedApiAnalyzers.dll;Microsoft.CodeAnalysis.VisualBasic.BannedApiAnalyzers.dll" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.BannedApiAnalyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.BannedApiAnalyzers.props" "D:\dotnet\roslyn-analyzers\artifacts\obj\Microsoft.CodeAnalysis.BannedApiAnalyzers.Package\Debug\netstandard2.0\Build" "Microsoft.CodeAnalysis.BannedApiAnalyzers.targets" "" "D:\dotnet\roslyn-analyzers\src\Microsoft.CodeAnalysis.BannedApiAnalyzers" "Microsoft.CodeAnalysis.BannedApiAnalyzers.md" "D:\dotnet\roslyn-analyzers\src\Microsoft.CodeAnalysis.BannedApiAnalyzers" "Microsoft.CodeAnalysis.BannedApiAnalyzers.sarif" "3.11.0" Microsoft.CodeAnalysis.BannedApiAnalyzers false true "" false" exited with code -2147450730.
  Text.Analyzers.Package failed with 1 error(s) (0.6s)
    D:\dotnet\roslyn-analyzers\eng\GenerateAnalyzerNuspec.targets(113,5): error MSB3073: The command ""D:\dotnet\roslyn-analyzers\.dotnet\dotnet.exe" --roll-forward major "D:\dotnet\roslyn-analyzers\artifacts\bin\GenerateDocumentationAndConfigFiles\Debug\net9.0\GenerateDocumentationAndConfigFiles.dll" "-validateOnly:false" "D:\dotnet\roslyn-analyzers\artifacts\obj\Text.Analyzers.Package\Debug\netstandard2.0\Rulesets" "D:\dotnet\roslyn-analyzers\artifacts\obj\Text.Analyzers.Package\Debug\netstandard2.0\Editorconfig" "D:\dotnet\roslyn-analyzers\artifacts\obj\Text.Analyzers.Package\Debug\netstandard2.0\GlobalAnalyzerConfigs" "D:\dotnet\roslyn-analyzers\artifacts\bin\\" "Debug" "netstandard2.0" "Text.Analyzers.dll;Text.CSharp.Analyzers.dll;Text.VisualBasic.Analyzers.dll;C:\Users\bunamnan\.nuget\packages\humanizer.core\2.14.1\lib\netstandard1.0\Humanizer.dll" "D:\dotnet\roslyn-analyzers\artifacts\obj\Text.Analyzers.Package\Debug\netstandard2.0\Build" "Text.Analyzers.props" "D:\dotnet\roslyn-analyzers\artifacts\obj\Text.Analyzers.Package\Debug\netstandard2.0\Build" "Text.Analyzers.targets" "DisableNETAnalyzersForNuGetPackage.props" "D:\dotnet\roslyn-analyzers\src\Text.Analyzers" "Text.Analyzers.md" "D:\dotnet\roslyn-analyzers\src\Text.Analyzers" "Text.Analyzers.sarif" "3.11.0" Text.Analyzers true true "" false" exited with code -2147450730.

Build failed with 8 error(s) in 77.0s

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an expert here though.

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Jun 12, 2024

@sharwell there is something broke in the repo, normal build succeeds but dotnet build /t:pack fails with MSBuild error:
How can I fix this? cc @mavasani

Turns out .NET version I was using was higher than the repo version, after the versions sync dotnet build /t:pack succeeded and produced the missing update

Copy link

codecov bot commented Jun 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.49%. Comparing base (4d5fd9d) to head (a532d1c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7326      +/-   ##
==========================================
- Coverage   96.49%   96.49%   -0.01%     
==========================================
  Files        1443     1443              
  Lines      345592   345670      +78     
  Branches    11370    11370              
==========================================
+ Hits       333484   333550      +66     
- Misses       9230     9241      +11     
- Partials     2878     2879       +1     

Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source changes look good, but I wonder if we should have additional test cases.

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Jun 13, 2024

The source changes look good, but I wonder if we should have additional test cases.

Added additional tests, thanks!

@buyaa-n buyaa-n merged commit 52913b2 into dotnet:main Jun 14, 2024
11 checks passed
@buyaa-n buyaa-n deleted the fix-ca1416-bug branch June 14, 2024 00:30
@ManickaP
Copy link
Member

@buyaa-n do you know when this will be available in runtime repo? Or could you let me know when the time comes?

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Jun 14, 2024

Must be it dotnet/runtime#103473

@ManickaP
Copy link
Member

ManickaP commented Jun 17, 2024

Works like charm, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants