diff --git a/bin/BuildTool/BuildTool.cs b/bin/BuildTool/BuildTool.cs index ae2c870..6d51cdd 100644 --- a/bin/BuildTool/BuildTool.cs +++ b/bin/BuildTool/BuildTool.cs @@ -1,6 +1,5 @@ using System.CommandLine; using System.Diagnostics; -using System.Net; using SimpleExec; using Spectre.Console; using BuildTool.Modules; @@ -273,6 +272,12 @@ class Program // create a copy of the build info updated with the module's watched sources and cache info (last build time etc.) BuildInfo moduleBuildInfo = module.GetBuildInfo(buildInfo, moduleCache); + + if (!moduleBuildInfo.BuildDebug && !moduleBuildInfo.BuildRelease) + { + AnsiConsole.MarkupLine($"\n[green]Module [bold italic]{module.Name}[/] is up to date, skipping.[/]\n"); + continue; + } try { diff --git a/bin/BuildTool/Module.cs b/bin/BuildTool/Module.cs index b8a81a8..d2dfb09 100644 --- a/bin/BuildTool/Module.cs +++ b/bin/BuildTool/Module.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.Security.Cryptography; -using System.Text; namespace BuildTool; @@ -60,34 +59,35 @@ abstract class Module foreach (WatchedSource source in watchedSources) { - bool cacheEntryFound = cacheInfo.TryGetCachedHash(source.Path, out SourceHash cachedHash); + string fullSourcePath = Path.Combine(buildInfo.WorkingDirectory.WorkspaceRoot, source.Path); + + bool cacheEntryFound = cacheInfo.TryGetCachedHash(fullSourcePath, out SourceHash cachedHash); SourceHash newHash; - - if (Directory.Exists(source.Path)) + + if (Directory.Exists(fullSourcePath)) { Debug.Assert(source.Mode == WatchMode.Metadata, "Directory watching is only supported in Metadata mode."); - DirectoryInfo dirInfo = new (source.Path); + DirectoryInfo dirInfo = new (fullSourcePath); if (dirInfo.LastWriteTimeUtc > cacheInfo.LastSuccessfulBuild) { - Console.WriteLine("Needs rebuild"); needsRebuild = true; } // 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) { - needsRebuild = DirectoryNeedsRebuild(cacheInfo, dirInfo, source, needsRebuild); + needsRebuild = DirectoryNeedsRebuild(cacheInfo, dirInfo, source); } // We really just need any timestamp, to know that the directory existed at some point. newHash = SourceHash.CreateTimeStamp(DateTime.UtcNow, 1); } - else if (File.Exists(source.Path)) + else if (File.Exists(fullSourcePath)) { - FileInfo fileInfo = new (source.Path); + FileInfo fileInfo = new (fullSourcePath); if (source.Mode == WatchMode.Metadata) { @@ -103,7 +103,6 @@ abstract class Module if (newHash != cachedHash) { - Console.WriteLine("Needs rebuild"); needsRebuild = true; } } @@ -131,15 +130,16 @@ abstract class Module } } - cacheInfo.SetNewHash(source.Path, newHash); + cacheInfo.SetNewHash(fullSourcePath, newHash); } return needsRebuild; } - private static bool DirectoryNeedsRebuild(ModuleInfo cacheInfo, DirectoryInfo dirInfo, WatchedSource source, - bool needsRebuild) + private static bool DirectoryNeedsRebuild(ModuleInfo cacheInfo, DirectoryInfo dirInfo, WatchedSource source) { + bool needsRebuild = false; + Stack directoriesToCheck = new (); directoriesToCheck.Push(dirInfo); @@ -153,22 +153,19 @@ abstract class Module if (source.ExcludedSubpaths.Contains(relativePath, StringComparer.OrdinalIgnoreCase)) continue; - if (dirEntry.Attributes.HasFlag(FileAttributes.Directory)) + if (source.Recursive && 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 true; } } } - return needsRebuild; + return false; } private static string ComputeFileHash(string filePath) diff --git a/bin/BuildTool/ModuleCache.cs b/bin/BuildTool/ModuleCache.cs index 049e8e0..90c2800 100644 --- a/bin/BuildTool/ModuleCache.cs +++ b/bin/BuildTool/ModuleCache.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Numerics; -using System.Text; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; @@ -74,7 +70,7 @@ public enum BuildConfig Release } -public record ModuleInfo +public class ModuleInfo { public string Name { get; set; } public BuildConfig Configuration { get; set; } @@ -142,7 +138,8 @@ public struct SourceHash : IEquatable return new SourceHash() { Type = HashType.Date, - Hash = timeStamp.ToString("o") // ISO 8601 format + Hash = timeStamp.ToString("o"), // ISO 8601 format + Length = length }; } @@ -151,7 +148,7 @@ public struct SourceHash : IEquatable public override bool Equals([NotNullWhen(true)] object? obj) { - return base.Equals(obj); + return obj is SourceHash other && Equals(other); } public bool Equals(SourceHash other)