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 location string to drive enumerating wildcard warning #7553

Merged
merged 2 commits into from
May 11, 2022

Conversation

mruxmohan4
Copy link
Contributor

@mruxmohan4 mruxmohan4 commented Apr 19, 2022

Fixes #7029 by associating a file location string with the WildcardResultsInDriveEnumeration resource name.

Context

For https://github.com/dotnet/project-system/blob/main/build/import/Workarounds.targets#L8, it was difficult to detect the location at which the drive enumerating wildcard pattern was occurring even though a warning was logged, since 1) there was no location string added to the warning, and 2) the Exclude rather than the Remove element was shown in the warning. To resolve 1), it would be better to associate the location string with the WildcardResultsInDriveEnumeration resource name.

Changes Made

Added location string to the WildcardResultsInDriveEnumeration resource name in order to view the location for drive enumerating wildcard warnings and errors.

Testing

Modified ProjectItem, ObjectModelHelper (for ProjectItemInstance), and CreateItem unit tests to ensure that the project file location was placed in the warning or error message.

Notes

Any <i Remove=<drive enumerating wildcard> /> will still be considered as an Exclude attribute in the warning or error message, since is treated as equivalent to <Foo Include=... Exclude=... />, which still makes the warning or error message slightly unclear for drive enumerating wildcard used in Remove cases. However, the wildcarded value will still be caught and logged/thrown based on whether the environment variable is set.

Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

Does LocationString include both project file and where in that file? And are you planning to account for Remove being interpreted as Exclude in a separate PR? If yes and yes, 👍

@mruxmohan4
Copy link
Contributor Author

LocationString does include the column + line number, in addition to the file name. And right, I wanted Remove to be separate from Exclude in a second PR

@mruxmohan4 mruxmohan4 closed this Apr 20, 2022
@mruxmohan4 mruxmohan4 reopened this Apr 20, 2022
@@ -353,6 +354,7 @@ private static void VerifyDriveEnumerationWarningLoggedUponCreateItemExecution(s
t.Execute().ShouldBeTrue();
engine.Warnings.ShouldBe(1);
engine.AssertLogContains("MSB5029");
engine.AssertLogContains($"file {engine.ProjectFileOfTaskNode}");
Copy link
Member

Choose a reason for hiding this comment

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

This will fail on a non-English machine; we generally prefer to either assert that the localized resource is present or just

Suggested change
engine.AssertLogContains($"file {engine.ProjectFileOfTaskNode}");
engine.AssertLogContains(engine.ProjectFileOfTaskNode);

@@ -279,7 +279,7 @@
<comment>{StrBegin="MSB5028: "}UE: The project filename is provided separately to loggers.</comment>
</data>
<data name="WildcardResultsInDriveEnumeration" xml:space="preserve">
<value>MSB5029: The value "{0}" of the "{1}" attribute in element &lt;{2}&gt; is a wildcard that results in enumerating all files on the drive, which was likely not intended. Check that referenced properties are always defined.</value>
<value>MSB5029: The value "{0}" of the "{1}" attribute in element &lt;{2}&gt; in file {3} is a wildcard that results in enumerating all files on the drive, which was likely not intended. Check that referenced properties are always defined.</value>
Copy link
Member

Choose a reason for hiding this comment

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

nit: quote?

Suggested change
<value>MSB5029: The value "{0}" of the "{1}" attribute in element &lt;{2}&gt; in file {3} is a wildcard that results in enumerating all files on the drive, which was likely not intended. Check that referenced properties are always defined.</value>
<value>MSB5029: The value "{0}" of the "{1}" attribute in element &lt;{2}&gt; in file "{3}" is a wildcard that results in enumerating all files on the drive, which was likely not intended. Check that referenced properties are always defined.</value>

ProjectCollection projectCollection = new ProjectCollection();
MockLogger collectionLogger = new MockLogger();
projectCollection.RegisterLogger(collectionLogger);
Project project = new Project(projectCollection);
Project project = new Project(testProject.ProjectFile, null, null, projectCollection);
Copy link
Member

Choose a reason for hiding this comment

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

What is the behavior on an in-memory project? Is it still reasonable? Should this be a new test instead of a change to the existing one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There didn't seem to be any sort of visible effect on the contents of the in-memory project, so I don't think this test is actually reasonable. Reverting to original

@@ -248,6 +249,7 @@ private static string[] GetFileList
case ILoggingService loggingService:
LogDriveEnumerationWarningWithLoggingService(
loggingService,
includeLocation,
Copy link
Member

Choose a reason for hiding this comment

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

why no exclude here when there is on the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like in Evaluator.cs, only the unevaluated Include attributes are looked at without any mention of Exclude specs, so I excluded it from the logger case that Evaluator uses, which is ILoggingService.

@mruxmohan4 mruxmohan4 force-pushed the dev/mruxmohan/add-location-string branch from 1cd906d to e818da4 Compare May 4, 2022 17:20
Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

Thanks!

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label May 9, 2022
@AR-May AR-May merged commit c9087cf into dotnet:main May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants