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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ private static void CreateProjectInstanceFromFileWithDriveEnumeratingWildcard(Te
// Verify
collectionLogger.WarningCount.ShouldBe(1);
collectionLogger.AssertLogContains("MSB5029");
collectionLogger.AssertLogContains(testProjectFile);
options.ProjectCollection.UnregisterAllLoggers();
}
}
Expand Down
60 changes: 38 additions & 22 deletions src/Build/Utilities/EngineFileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ private static string[] GetFileList
LogDriveEnumerationWarningWithTargetLoggingContext(
targetLoggingContext,
includeLocation,
excludeLocation,
excludeFileSpecIsEmpty,
disableExcludeDriveEnumerationWarning,
fileSpec);
Expand All @@ -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.

buildEventContext,
buildEventFileInfoFullPath,
filespecUnescaped);
Expand All @@ -259,6 +261,8 @@ private static string[] GetFileList
LogDriveEnumerationWarningWithEvaluationLoggingContext(
evaluationLoggingContext,
importLocation,
includeLocation,
excludeLocation,
excludeFileSpecIsEmpty,
filespecUnescaped,
fileSpec);
Expand Down Expand Up @@ -336,7 +340,7 @@ private static string[] GetFileList
return fileList;
}

private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLoggingContext targetLoggingContext, IElementLocation includeLocation, bool excludeFileSpecIsEmpty, bool disableExcludeDriveEnumerationWarning, string fileSpec)
private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLoggingContext targetLoggingContext, IElementLocation includeLocation, IElementLocation excludeLocation, bool excludeFileSpecIsEmpty, bool disableExcludeDriveEnumerationWarning, string fileSpec)
{
// Both condition lines are necessary to skip for the first GetFileListEscaped call
// and reach for the GetFileListUnescaped call when the wildcarded Exclude attribute results
Expand All @@ -345,13 +349,14 @@ private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLog
// Include wildcard attributes for the GetFileListEscaped calls would falsely appear
// with the Exclude attribute in the logged warning.
if (((!excludeFileSpecIsEmpty) && (!disableExcludeDriveEnumerationWarning)) ||
(includeLocation == null))
((includeLocation == null) && (excludeLocation != null)))
{
targetLoggingContext.LogWarning(
DriveEnumeratingWildcardMessageResourceName,
fileSpec,
XMakeAttributes.exclude,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
excludeLocation.LocationString);
}

// Both conditions are necessary to reach for both GetFileListEscaped calls
Expand All @@ -363,13 +368,14 @@ private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLog
DriveEnumeratingWildcardMessageResourceName,
fileSpec,
XMakeAttributes.include,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
includeLocation.LocationString);
}
}

private static void LogDriveEnumerationWarningWithLoggingService(ILoggingService loggingService, BuildEventContext buildEventContext, string buildEventFileInfoFullPath, string filespecUnescaped)
private static void LogDriveEnumerationWarningWithLoggingService(ILoggingService loggingService, IElementLocation includeLocation, BuildEventContext buildEventContext, string buildEventFileInfoFullPath, string filespecUnescaped)
{
if (buildEventContext != null)
if (buildEventContext != null && includeLocation != null)
{
loggingService.LogWarning(
buildEventContext,
Expand All @@ -378,35 +384,39 @@ private static void LogDriveEnumerationWarningWithLoggingService(ILoggingService
DriveEnumeratingWildcardMessageResourceName,
filespecUnescaped,
XMakeAttributes.include,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
includeLocation.LocationString);
}
}

private static void LogDriveEnumerationWarningWithEvaluationLoggingContext(EvaluationLoggingContext evaluationLoggingContext, IElementLocation importLocation, bool excludeFileSpecIsEmpty, string filespecUnescaped, string fileSpec)
private static void LogDriveEnumerationWarningWithEvaluationLoggingContext(EvaluationLoggingContext evaluationLoggingContext, IElementLocation importLocation, IElementLocation includeLocation, IElementLocation excludeLocation, bool excludeFileSpecIsEmpty, string filespecUnescaped, string fileSpec)
{
if (importLocation != null)
{
evaluationLoggingContext.LogWarning(
DriveEnumeratingWildcardMessageResourceName,
filespecUnescaped,
XMakeAttributes.project,
XMakeElements.import);
XMakeElements.import,
importLocation.LocationString);
}
else if (excludeFileSpecIsEmpty)
else if (excludeFileSpecIsEmpty && includeLocation != null)
{
evaluationLoggingContext.LogWarning(
DriveEnumeratingWildcardMessageResourceName,
fileSpec,
XMakeAttributes.include,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
includeLocation.LocationString);
}
else
else if (excludeLocation != null)
{
evaluationLoggingContext.LogWarning(
DriveEnumeratingWildcardMessageResourceName,
fileSpec,
XMakeAttributes.exclude,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
excludeLocation.LocationString);
}
}

Expand All @@ -423,21 +433,23 @@ private static void ThrowDriveEnumerationExceptionWithTargetLoggingContext(IElem
DriveEnumeratingWildcardMessageResourceName,
filespecUnescaped,
XMakeAttributes.include,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
includeLocation.LocationString);
}

// The first condition is necessary to reach for both GetFileListEscaped calls
// whenever the wildcarded Exclude attribute results in drive enumeration, and
// the second condition is necessary to reach for the GetFileListUnescaped call
// (also when the wildcarded Exclude attribute results in drive enumeration).
else if ((!excludeFileSpecIsEmpty) || (includeLocation == null))
else if (((!excludeFileSpecIsEmpty) || (includeLocation == null)) && (excludeLocation != null))
{
ProjectErrorUtilities.ThrowInvalidProject(
excludeLocation,
DriveEnumeratingWildcardMessageResourceName,
fileSpec,
XMakeAttributes.exclude,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
excludeLocation.LocationString);
}
}

Expand All @@ -448,7 +460,8 @@ private static void ThrowDriveEnumerationExceptionWithLoggingService(IElementLoc
DriveEnumeratingWildcardMessageResourceName,
filespecUnescaped,
XMakeAttributes.include,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
includeLocation.LocationString);
}

private static void ThrowDriveEnumerationExceptionWithEvaluationLoggingContext(IElementLocation importLocation, IElementLocation includeLocation, IElementLocation excludeLocation, string filespecUnescaped, string fileSpec, bool excludeFileSpecIsEmpty)
Expand All @@ -460,25 +473,28 @@ private static void ThrowDriveEnumerationExceptionWithEvaluationLoggingContext(I
DriveEnumeratingWildcardMessageResourceName,
filespecUnescaped,
XMakeAttributes.project,
XMakeElements.import);
XMakeElements.import,
importLocation.LocationString);
}
else if (excludeFileSpecIsEmpty)
else if (excludeFileSpecIsEmpty && includeLocation != null)
{
ProjectErrorUtilities.ThrowInvalidProject(
includeLocation,
DriveEnumeratingWildcardMessageResourceName,
fileSpec,
XMakeAttributes.include,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
includeLocation.LocationString);
}
else
else if (excludeLocation != null)
{
ProjectErrorUtilities.ThrowInvalidProject(
excludeLocation,
DriveEnumeratingWildcardMessageResourceName,
fileSpec,
XMakeAttributes.exclude,
XMakeElements.itemGroup);
XMakeElements.itemGroup,
excludeLocation.LocationString);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Shared/Resources/Strings.shared.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
<comment>{StrBegin="MSB5029: "}UE: This is a generic message that is displayed when we find a project element that has a drive enumerating wildcard value for one of its
attributes e.g. &lt;Compile Include="$(NotAlwaysDefined)\**\*.cs"&gt; -- if the property is undefined, the value of Include should not result in enumerating all files on drive.</comment>
</data>
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/Resources/xlf/Strings.shared.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Shared/Resources/xlf/Strings.shared.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Shared/Resources/xlf/Strings.shared.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Shared/Resources/xlf/Strings.shared.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Shared/Resources/xlf/Strings.shared.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading