From 2fdde6558c75f558ae00c93f76ba45453ed12591 Mon Sep 17 00:00:00 2001
From: Forgind <12969783+Forgind@users.noreply.github.com>
Date: Tue, 7 Feb 2023 09:06:10 -0800
Subject: [PATCH] Fix temp file filtering in FileTracker (#8352)
(Copied from #8351)
Fixes AB#1678521
Context
#8049 broke the temp filtering logic by using the MSBuild-specific temp path instead of the true base temp path. This manifests as an overbuild of some C++ projects.
Changes Made
Reverted the change. Enabled relevant unit tests.
Testing
Existing unit tests and a C++ end-to-end repro.
Notes
The rest of FileTracker tests cannot be enabled without significant work (related to #649).
---
.../TrackedDependencies/FileTrackerTests.cs | 11 ++++-------
src/Utilities/TrackedDependencies/FileTracker.cs | 10 ++++++++--
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/Utilities.UnitTests/TrackedDependencies/FileTrackerTests.cs b/src/Utilities.UnitTests/TrackedDependencies/FileTrackerTests.cs
index 79db28ce138..8e654113ce8 100644
--- a/src/Utilities.UnitTests/TrackedDependencies/FileTrackerTests.cs
+++ b/src/Utilities.UnitTests/TrackedDependencies/FileTrackerTests.cs
@@ -66,11 +66,13 @@ public FileTrackerTests()
Environment.ExpandEnvironmentVariables("%windir%\\system32;%windir%"));
}
+#if ENABLE_TRACKER_TESTS // https://github.com/dotnet/msbuild/issues/649
// Call StopTrackingAndCleanup here, just in case one of the unit tests failed before it called it
// In real code StopTrackingAndCleanup(); would always be in a finally {} block.
FileTracker.StopTrackingAndCleanup();
FileTrackerTestHelper.CleanTlogs();
FileTracker.SetThreadCount(1);
+#endif
}
public void Dispose()
@@ -81,7 +83,6 @@ public void Dispose()
Environment.SetEnvironmentVariable("PATH", s_oldPath);
s_oldPath = null;
}
-
FileTrackerTestHelper.CleanTlogs();
}
@@ -835,11 +836,9 @@ public void FileTrackerFindStrInX86X64ChainRepeatCommand()
FileTrackerTestHelper.AssertFoundStringInTLog(Path.GetFullPath("test.in").ToUpperInvariant(), tlogFiles[0]);
}
- [Fact(Skip = "FileTracker tests require VS2015 Update 3 or a packaged version of Tracker.exe https://github.com/Microsoft/msbuild/issues/649")]
+ [Fact]
public void FileTrackerFileIsUnderPath()
{
- Console.WriteLine("Test: FileTrackerFileIsUnderPath");
-
// YES: Both refer to something under baz, so yes this is on the path
Assert.True(FileTracker.FileIsUnderPath(@"c:\foo\bar\baz\", @"c:\foo\bar\baz\"));
@@ -881,11 +880,9 @@ public void FileTrackerFileIsUnderPath()
Assert.False(FileTracker.FileIsUnderPath(@"c:\foo\rumble.cpp", @"c:\foo\rumble\"));
}
- [Fact(Skip = "FileTracker tests require VS2015 Update 3 or a packaged version of Tracker.exe https://github.com/Microsoft/msbuild/issues/649")]
+ [Fact]
public void FileTrackerFileIsExcludedFromDependencies()
{
- Console.WriteLine("Test: FileTrackerFileIsExcludedFromDependencies");
-
string applicationDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string localApplicationDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string localLowApplicationDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "AppData\\LocalLow");
diff --git a/src/Utilities/TrackedDependencies/FileTracker.cs b/src/Utilities/TrackedDependencies/FileTracker.cs
index 1560c2fd944..21230958156 100644
--- a/src/Utilities/TrackedDependencies/FileTracker.cs
+++ b/src/Utilities/TrackedDependencies/FileTracker.cs
@@ -60,8 +60,14 @@ public static class FileTracker
{
#region Static Member Data
- // The default path to temp, used to create explicitly short and long paths
- private static readonly string s_tempPath = FileUtilities.TempFileDirectory;
+ ///
+ /// The default path to temp, used to create explicitly short and long paths.
+ ///
+ ///
+ /// This must be the base system-wide temp path because we use it to filter out I/O of tools outside of our control.
+ /// Tools running under the tracker may put temp files in the temp base or in a sub-directory of their choosing.
+ ///
+ private static readonly string s_tempPath = Path.GetTempPath();
// The short path to temp
private static readonly string s_tempShortPath = FileUtilities.EnsureTrailingSlash(NativeMethodsShared.GetShortFilePath(s_tempPath).ToUpperInvariant());