Some changes

- Changed ModuleInfo to class, save Length for Timestamp-Hashes
- Obey recursive-flag for WatchedSources
- Verbosely skip up-to-date modules
This commit is contained in:
Simon Lübeß
2026-04-13 20:48:21 +02:00
parent 6bec99ab06
commit 1e1ec7aaa9
3 changed files with 27 additions and 28 deletions
+6 -1
View File
@@ -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
{
+16 -19
View File
@@ -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<DirectoryInfo> 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)
+5 -8
View File
@@ -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<SourceHash>
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<SourceHash>
public override bool Equals([NotNullWhen(true)] object? obj)
{
return base.Equals(obj);
return obj is SourceHash other && Equals(other);
}
public bool Equals(SourceHash other)