Skip to content

Conversation

@ViktorHofer
Copy link
Member

@ViktorHofer ViktorHofer commented Jun 1, 2023

Fixes #28070

Adds the following flags to the APICompat frontends:

MSBuild CLI Default value
/p:ApiCompatPreserveUnnecessarySuppressions --preserve-unnecessary-suppressions false
/p:ApiCompatPermitUnnecessarySuppressions --permit-unnecessary-suppressions false

dotnet/runtime will need to opt-out of these switches for packable projects which have a reference assembly as we do a two phase validation for these.

Note for reviewers: Hide whitespaces and exclude resx and xlf changes in the GH review pane.

@ghost
Copy link

ghost commented Jun 1, 2023

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged Request triage from a team member label Jun 1, 2023
@ViktorHofer ViktorHofer force-pushed the ValidateSuppressions branch from 66971d3 to e84d7e0 Compare June 1, 2023 14:07
@ViktorHofer ViktorHofer added Area-ApiCompat and removed untriaged Request triage from a team member labels Jun 1, 2023
@ViktorHofer ViktorHofer force-pushed the ValidateSuppressions branch 2 times, most recently from 197d65a to 7b0a2a0 Compare June 2, 2023 15:25
@ViktorHofer ViktorHofer force-pushed the ValidateSuppressions branch from 7b0a2a0 to 196afa5 Compare June 2, 2023 15:36
@ViktorHofer ViktorHofer changed the title Validate suppressions Validate existing suppressions and remove obsolete suppressions when re-generating suppression files Jun 2, 2023
@ViktorHofer ViktorHofer marked this pull request as ready for review June 2, 2023 16:00
@ViktorHofer ViktorHofer requested review from a team, ericstj and joperezr as code owners June 2, 2023 16:00
@ericstj ericstj requested a review from carlossanlop June 2, 2023 16:44
/// <summary>
/// If true, validates that baseline suppressions aren't obsolete.
/// </summary>
public bool ValidateSuppressions { get; set; } = true;
Copy link
Member

Choose a reason for hiding this comment

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

Setting the default to true here will be breaking. Make sure you raise that as a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Every new rule in APICompat that is on by default is considered a breaking change. As well as infrastructure changes that enable more validation, i.e. #32930. I will group both changes together into one breaking change notice.

Copy link
Member

Choose a reason for hiding this comment

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

That's true. Perhaps simply documenting the new validation is sufficient here.

engine.AddSuppression(newSuppression);
string filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName(), "DummyFile.xml");
Assert.True(engine.WriteSuppressionsToFile(filePath));
Assert.True(engine.WriteSuppressionsToFile(filePath, removeObsoleteSuppressions: false));
Copy link
Member

Choose a reason for hiding this comment

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

Can we add tests that cover the new behavior?

@ViktorHofer ViktorHofer changed the title Validate existing suppressions and remove obsolete suppressions when re-generating suppression files Validate existing suppressions and remove unnecessary suppressions when re-generating suppression files Jun 3, 2023
ViktorHofer added a commit to dotnet/runtime that referenced this pull request Jun 3, 2023
- 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
Copy link
Member Author

Just tried the changes out on runtime and submitted dotnet/runtime#87094 to remove the unnecessary suppressions and already set the required properties to opt-out of the new behavior for packable projects that also have a reference source project.

dotnet/runtime#87094

ViktorHofer added a commit to dotnet/runtime that referenced this pull request Jun 5, 2023
* Remove unnecessary suppressions in APICompat files

- 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.

* Add suppressions back for two CoreLib flavors

* Fix CoreLib suppression because of API attribute difference
Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

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

Changes look good. Thank you for addressing. I didn't see tests yet so I imagine that's still pending.

I left one small observation now that we've aligned the properties.

@ViktorHofer ViktorHofer self-assigned this Jul 5, 2023
@ViktorHofer ViktorHofer requested a review from ericstj July 11, 2023 16:02
@ViktorHofer
Copy link
Member Author

@ericstj can you please take another look? I just pushed two more commits which add tests, refactor the existing ones. I also found one bug in the WriteSuppressionFilesToFile method which I fixed by creating a new HashSet based on the existing one for the suppressions.

The tests were quite messy so I spent some time cleaning them up.

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

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

LGTM - modulo one nit on the tests. Thank you for adding them.

Right = "lib/net6.0/tempValidation.dll"
}));
TestSuppressionEngine suppressionEngine = new();
suppressionEngine.LoadSuppressions("NonExistentFile.xml");
Copy link
Member

Choose a reason for hiding this comment

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

Is loading a non-existent file essential to these test cases? That seems like a single test case rather than something we need to do in every one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's essential as it trigger loading the test suppression file content. See TestSuppressionEngine.cs which has an override to get the readable stream. Without calling the newly introduced LoadSuppressions method, the baseline suppressions won't get loaded.

@ViktorHofer ViktorHofer merged commit a3303b6 into main Jul 11, 2023
@ViktorHofer ViktorHofer deleted the ValidateSuppressions branch July 11, 2023 19:32
@RussKie
Copy link
Contributor

RussKie commented Jul 12, 2023

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove obsolete suppressions when re-generating suppression files

4 participants