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

Write APICompat suppressions when baseline suppressions aren't empty #44965

Merged
merged 4 commits into from
Nov 20, 2024

Conversation

ViktorHofer
Copy link
Member

When there aren't any suppressions but baseline suppressions exist, write to the suppression file to make it empty.

Pass information back to the caller so that even if an empty collection of suppression are written to the file, still log a message to indicate that the suppression file got updated.

When there aren't any suppressions but baseline suppressions exist,
write to the suppression file to make it empty.

Pass information back to the caller so that even if an empty collection
of suppression are written to the file, still log a message to indicate
that the suppression file got updated.
@ViktorHofer ViktorHofer requested a review from a team as a code owner November 19, 2024 21:44
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-ApiCompat untriaged Request triage from a team member labels Nov 19, 2024
@ViktorHofer
Copy link
Member Author

ViktorHofer commented Nov 19, 2024

@ericstj when the /p:GenerateAPICompatSuppressionFile=true flag is passed in, the baseline suppression file not being empty but there aren't actual suppressions, should we write an empty suppressions file or not write at all and try to delete if it exists?

With this change, we update the file and make it empty:

<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />

@ericstj
Copy link
Member

ericstj commented Nov 19, 2024

@ericstj when the /p:GenerateAPICompatSuppressionFile=true flag is passed in, the baseline suppression file not being empty but there aren't actual suppressions, should we write an empty suppressions file or not write at all and try to delete if it exists?

With this change, we update the file and make it empty:

<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />

I think in our case we'd prefer to delete the file since we conditionally set it based on existence -- would that work in general? Suppose someone specified the file name - if we deleted that file would we handle a specified path to a non-existent file on run? Maybe not. I guess emitting an empty file is OK. If folks want to delete it, then can notice the empty file and delete it.

@ViktorHofer
Copy link
Member Author

ViktorHofer commented Nov 19, 2024

Suppose someone specified the file name - if we deleted that file would we handle a specified path to a non-existent file on run? Maybe not. I guess emitting an empty file is OK. If folks want to delete it, then can notice the empty file and delete it.

The suppression engine file loader would throw a FileNotFoundException when GenerateAPICompatSuppressionFile is false:

catch (FileNotFoundException) when (BaselineAllErrors)

I kind of lean towards deleting the empty suppression file. The switch name might confusing here though as it implies something getting generated, not deleted (GenerateAPICompatSuppressionFile).

EDIT: Given this a second thought, not deleting is probably less breaking here and won't change a potential exisiting workflow. I.e. for runtime's ApiCompat.proj we want the suppression files emptied but not deleted. If they would get deleted we would see the FileNotFoundException.

@ericstj
Copy link
Member

ericstj commented Nov 19, 2024

I'm fine either way, just test the behavior works in and doesn't introduce new errors for folks.


Assert.True(suppressionFileUpdated);
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a test case for the scenario where we had baselines and they are no longer needed -- ensure that the file is emptied and true is returned?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just noticed that we already have one that validates that: SuppressionEngine_WriteSuppressionsToFile_ReturnsEmptyWithAllUnnecessarySuppressions

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.

change looks ok, please consider adding a test for this scenario.

@ViktorHofer
Copy link
Member Author

Yes, I will add a test for that scenario before merging.

The SuppressionEngine_WriteSuppressionsToFile_ReturnsEmptyWithAllUnnecessarySuppressions
test already validates the new behavior.
@ViktorHofer ViktorHofer enabled auto-merge (squash) November 20, 2024 18:34
@ViktorHofer ViktorHofer merged commit 425cbaa into main Nov 20, 2024
38 checks passed
@ViktorHofer ViktorHofer deleted the WriteSuppressionsWhenBaselineContainsSuppressions branch November 20, 2024 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-ApiCompat untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants