mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
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:
@@ -1,6 +1,5 @@
|
|||||||
using System.CommandLine;
|
using System.CommandLine;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
|
||||||
using SimpleExec;
|
using SimpleExec;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using BuildTool.Modules;
|
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.)
|
// 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);
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
+16
-19
@@ -1,6 +1,5 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace BuildTool;
|
namespace BuildTool;
|
||||||
|
|
||||||
@@ -60,34 +59,35 @@ abstract class Module
|
|||||||
|
|
||||||
foreach (WatchedSource source in watchedSources)
|
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;
|
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.");
|
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)
|
if (dirInfo.LastWriteTimeUtc > cacheInfo.LastSuccessfulBuild)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Needs rebuild");
|
|
||||||
needsRebuild = true;
|
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.
|
// 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)
|
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.
|
// We really just need any timestamp, to know that the directory existed at some point.
|
||||||
newHash = SourceHash.CreateTimeStamp(DateTime.UtcNow, 1);
|
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)
|
if (source.Mode == WatchMode.Metadata)
|
||||||
{
|
{
|
||||||
@@ -103,7 +103,6 @@ abstract class Module
|
|||||||
|
|
||||||
if (newHash != cachedHash)
|
if (newHash != cachedHash)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Needs rebuild");
|
|
||||||
needsRebuild = true;
|
needsRebuild = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,15 +130,16 @@ abstract class Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheInfo.SetNewHash(source.Path, newHash);
|
cacheInfo.SetNewHash(fullSourcePath, newHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
return needsRebuild;
|
return needsRebuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool DirectoryNeedsRebuild(ModuleInfo cacheInfo, DirectoryInfo dirInfo, WatchedSource source,
|
private static bool DirectoryNeedsRebuild(ModuleInfo cacheInfo, DirectoryInfo dirInfo, WatchedSource source)
|
||||||
bool needsRebuild)
|
|
||||||
{
|
{
|
||||||
|
bool needsRebuild = false;
|
||||||
|
|
||||||
Stack<DirectoryInfo> directoriesToCheck = new ();
|
Stack<DirectoryInfo> directoriesToCheck = new ();
|
||||||
directoriesToCheck.Push(dirInfo);
|
directoriesToCheck.Push(dirInfo);
|
||||||
|
|
||||||
@@ -153,22 +153,19 @@ abstract class Module
|
|||||||
if (source.ExcludedSubpaths.Contains(relativePath, StringComparer.OrdinalIgnoreCase))
|
if (source.ExcludedSubpaths.Contains(relativePath, StringComparer.OrdinalIgnoreCase))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (dirEntry.Attributes.HasFlag(FileAttributes.Directory))
|
if (source.Recursive && dirEntry.Attributes.HasFlag(FileAttributes.Directory))
|
||||||
{
|
{
|
||||||
directoriesToCheck.Push(new DirectoryInfo(dirEntry.FullName));
|
directoriesToCheck.Push(new DirectoryInfo(dirEntry.FullName));
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Checking entry: " + dirEntry.FullName);
|
|
||||||
if (dirEntry.LastWriteTimeUtc > cacheInfo.LastSuccessfulBuild)
|
if (dirEntry.LastWriteTimeUtc > cacheInfo.LastSuccessfulBuild)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Needs rebuild");
|
return true;
|
||||||
needsRebuild = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return needsRebuild;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ComputeFileHash(string filePath)
|
private static string ComputeFileHash(string filePath)
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Numerics;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
@@ -74,7 +70,7 @@ public enum BuildConfig
|
|||||||
Release
|
Release
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ModuleInfo
|
public class ModuleInfo
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public BuildConfig Configuration { get; set; }
|
public BuildConfig Configuration { get; set; }
|
||||||
@@ -142,7 +138,8 @@ public struct SourceHash : IEquatable<SourceHash>
|
|||||||
return new SourceHash()
|
return new SourceHash()
|
||||||
{
|
{
|
||||||
Type = HashType.Date,
|
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)
|
public override bool Equals([NotNullWhen(true)] object? obj)
|
||||||
{
|
{
|
||||||
return base.Equals(obj);
|
return obj is SourceHash other && Equals(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(SourceHash other)
|
public bool Equals(SourceHash other)
|
||||||
|
|||||||
Reference in New Issue
Block a user