Skip to content

Remove unnecessary suppressions in APICompat files#87094

Merged
ViktorHofer merged 3 commits intomainfrom
RemoveUnnecessarySuppressionsAPICompat
Jun 5, 2023
Merged

Remove unnecessary suppressions in APICompat files#87094
ViktorHofer merged 3 commits intomainfrom
RemoveUnnecessarySuppressionsAPICompat

Conversation

@ViktorHofer
Copy link
Member

@ViktorHofer ViktorHofer commented Jun 3, 2023

Related dotnet/sdk#32964

- Remove unnecessary suppressions in APICompat files. This is in
  preparation for dotnet/sdk#32964 which will
  validate the existing suppressions going forward.
- Set the required APICompat properties for the future tooling support.
@ViktorHofer ViktorHofer added this to the 8.0.0 milestone Jun 3, 2023
@ViktorHofer ViktorHofer self-assigned this Jun 3, 2023
@ghost
Copy link

ghost commented Jun 3, 2023

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Issue Details

Related dotnet/sdk#32964

Author: ViktorHofer
Assignees: ViktorHofer
Labels:

area-Infrastructure-libraries

Milestone: 8.0.0

Comment on lines +78 to +79
<ApiCompatPreserveUnnecessarySuppressions>true</ApiCompatPreserveUnnecessarySuppressions>
<ApiCompatPermitUnnecessarySuppressions>true</ApiCompatPermitUnnecessarySuppressions>
Copy link
Contributor

Choose a reason for hiding this comment

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

These two properties sound very similar. Why two?

Copy link
Member Author

Choose a reason for hiding this comment

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

APICompat is used in dotnet/runtime but also in various other repositories. these two new settings are on by default but need to be disabled at least in runtime for a few projects (mentioned that in the code comment in resolveContract.targets). The feature flags are distinct as the latter allows unnecessary suppressions to exist in the suppression files and the former trims out unnecessary suppressions when re-generating a suppression file via the /p:GenerateAPICompatSuppressionFile=true switch.


<PropertyGroup>
<IsRuntimeAndReferenceAssembly Condition="'$(IsRuntimeAndReferenceAssembly)' == '' and
'$(HasMatchingContract)' != 'true' and
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own education: What is a "matching contract"?

Copy link
Member Author

@ViktorHofer ViktorHofer Jun 5, 2023

Choose a reason for hiding this comment

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

A matching contract is a reference source project assembly in the context of a source project, i.e. ref/net8.0/System.Text.Json.dll is the matching contract assembly for lib/net8.0/System.Text.Json.dll. Matching refers to the compatible TFM.

<PropertyGroup>
<IsRuntimeAndReferenceAssembly Condition="'$(IsRuntimeAndReferenceAssembly)' == '' and
'$(HasMatchingContract)' != 'true' and
'$(IsPrivateAssembly)' != 'true'">true</IsRuntimeAndReferenceAssembly>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you give me an example of a private assembly?

Copy link
Member Author

Choose a reason for hiding this comment

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

System.Private.Uri

<PropertyGroup>
<BinPlaceRef Condition="'$(BinPlaceRef)' == '' and ('$(IsReferenceAssemblyProject)' == 'true' or '$(IsRuntimeAndReferenceAssembly)' == 'true')">true</BinPlaceRef>
<BinPlaceRuntime Condition="'$(BinPlaceRuntime)' == '' and ('$(IsSourceProject)' == 'true' or '$(IsRuntimeAndReferenceAssembly)' == 'true')">true</BinPlaceRuntime>
<BinPlaceRuntime Condition="'$(BinPlaceRuntime)' == '' and '$(IsSourceProject)' == 'true'">true</BinPlaceRuntime>
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you moved IsRuntimeAndReferenceAssembly to resolveContract.targets` and changed it a bit. Why did you move it there?

Can you please explain why you removed the condition from IsNETCoreAppSrc and BinPlaceRuntime?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because IsruntimeAndReferenceAssembly is used in a condition in resolveContract.targets and resolveContract.targets is imported before src/libraries/Directory.Build.targets.

<Target>T:System.Runtime.CompilerServices.AsyncMethodBuilderAttribute:[T:System.AttributeUsageAttribute]</Target>
<Left>netstandard2.1/netstandard.dll</Left>
<Right>net8.0/netstandard.dll</Right>
</Suppression>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please explain why all these suppressions got removed if both ApiCompatPreserveUnnecessarySuppressions and ApiCompatPermitUnnecessarySuppressions are set to true in resolveContract.targets?

Copy link
Member Author

Choose a reason for hiding this comment

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

These two properties are conditionally set to true for IsSourceProject projects (which apicompat.proj isn't):

'$(UsingMicrosoftNoTargetsSdk)' != 'true' and

In general, we want to disable these new features for packable projects that also have a matching reference source project. I tried to capture that in the added comment in resolveContract.targets.

@ViktorHofer ViktorHofer merged commit 533d70c into main Jun 5, 2023
@ViktorHofer ViktorHofer deleted the RemoveUnnecessarySuppressionsAPICompat branch June 5, 2023 17:00
@ghost ghost locked as resolved and limited conversation to collaborators Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants