diff --git a/bin/BuildTool/Module.cs b/bin/BuildTool/Module.cs index 1c857ca..b8a81a8 100644 --- a/bin/BuildTool/Module.cs +++ b/bin/BuildTool/Module.cs @@ -79,22 +79,7 @@ abstract class Module // Since we don't save anything directory specific in the has, we can skip this check if we already know that we are going to rebuild. if (!needsRebuild) { - foreach (FileSystemInfo dirEntry in dirInfo.EnumerateFileSystemInfos("**", - enumerationOptions: new EnumerationOptions() - { MatchType = MatchType.Win32, RecurseSubdirectories = source.Recursive })) - { - //string relativePath = Path.GetRelativePath(dirInfo.FullName, dirEntry.FullName); - //if (source.ExcludedDirectories.Contains(relativePath, StringComparer.OrdinalIgnoreCase)) - // continue; - - Console.WriteLine("Checking entry: " + dirEntry.FullName); - if (dirEntry.LastWriteTimeUtc > cacheInfo.LastSuccessfulBuild) - { - Console.WriteLine("Needs rebuild"); - needsRebuild = true; - break; - } - } + needsRebuild = DirectoryNeedsRebuild(cacheInfo, dirInfo, source, needsRebuild); } // We really just need any timestamp, to know that the directory existed at some point. @@ -152,6 +137,40 @@ abstract class Module return needsRebuild; } + private static bool DirectoryNeedsRebuild(ModuleInfo cacheInfo, DirectoryInfo dirInfo, WatchedSource source, + bool needsRebuild) + { + Stack directoriesToCheck = new (); + directoriesToCheck.Push(dirInfo); + + while (directoriesToCheck.Count > 0) + { + DirectoryInfo directory = directoriesToCheck.Pop(); + + foreach (FileSystemInfo dirEntry in directory.EnumerateFileSystemInfos()) + { + string relativePath = Path.GetRelativePath(dirInfo.FullName, dirEntry.FullName); + if (source.ExcludedSubpaths.Contains(relativePath, StringComparer.OrdinalIgnoreCase)) + continue; + + if (dirEntry.Attributes.HasFlag(FileAttributes.Directory)) + { + directoriesToCheck.Push(new DirectoryInfo(dirEntry.FullName)); + } + + Console.WriteLine("Checking entry: " + dirEntry.FullName); + if (dirEntry.LastWriteTimeUtc > cacheInfo.LastSuccessfulBuild) + { + Console.WriteLine("Needs rebuild"); + needsRebuild = true; + break; + } + } + } + + return needsRebuild; + } + private static string ComputeFileHash(string filePath) { using var stream = File.OpenRead(filePath); diff --git a/bin/BuildTool/Modules/ScriptCoreModule.cs b/bin/BuildTool/Modules/ScriptCoreModule.cs index 436d612..2366e59 100644 --- a/bin/BuildTool/Modules/ScriptCoreModule.cs +++ b/bin/BuildTool/Modules/ScriptCoreModule.cs @@ -38,7 +38,7 @@ class ScriptCoreModule : Module sources.Add(new WatchedSource("ScriptCore/", WatchMode.Metadata) { Recursive = true, - ExcludedDirectories = + ExcludedSubpaths = [ "bin", "obj" diff --git a/bin/BuildTool/WatchedSource.cs b/bin/BuildTool/WatchedSource.cs index ca2f5fb..9092acb 100644 --- a/bin/BuildTool/WatchedSource.cs +++ b/bin/BuildTool/WatchedSource.cs @@ -27,7 +27,7 @@ internal record WatchedSource(string Path, WatchMode Mode) /// /// Only if Path points to a directory, a list of subdirectories to exclude from change checking. /// - public List ExcludedDirectories { get; init; } = new(); + public List ExcludedSubpaths { get; init; } = new(); /// /// Only if Path points to a directory, whether to check for changes in subdirectories as well. ///