Skip to content

Commit

Permalink
Incremental compile picks up files with errors/warnings (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Nov 14, 2024
1 parent 0544dab commit b04f097
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/Elastic.Markdown/Diagnostics/DiagnosticsChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class DiagnosticsCollector(ILoggerFactory loggerFactory, IReadOnlyCollect
public long Warnings => _warnings;
public long Errors => _errors;

public HashSet<string> OffendingFiles { get; } = new();

public async Task StartAsync(Cancel ctx)
{
await Channel.WaitToWrite();
Expand All @@ -107,6 +109,7 @@ void Drain()
{
IncrementSeverityCount(item);
HandleItem(item);
OffendingFiles.Add(item.File);
foreach (var output in _outputs)
output.Write(item);
}
Expand Down
28 changes: 22 additions & 6 deletions src/Elastic.Markdown/DocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace Elastic.Markdown;

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(OutputState))]
internal partial class SourceGenerationContext : JsonSerializerContext
{
}
internal partial class SourceGenerationContext : JsonSerializerContext;

public class OutputState
{
public DateTimeOffset LastSeenChanges { get; set; }
public string[] Conflict { get; set; } = [];
}

public class DocumentationGenerator
Expand Down Expand Up @@ -87,8 +87,15 @@ public async Task GenerateAll(Cancel ctx)
DocumentationSet.ClearOutputDirectory();

_logger.LogInformation($"Last write source: {DocumentationSet.LastWrite}, output observed: {OutputState?.LastSeenChanges}");

var offendingFiles = new HashSet<string>(OutputState?.Conflict ?? []);
var outputSeenChanges = OutputState?.LastSeenChanges ?? DateTimeOffset.MinValue;
if (DocumentationSet.LastWrite > outputSeenChanges && OutputState != null)
if (offendingFiles.Count > 0)
{
_logger.LogInformation($"Reapplying changes since {DocumentationSet.LastWrite}");
_logger.LogInformation($"Reapplying for {offendingFiles.Count} files with errors/warnings");
}
else if (DocumentationSet.LastWrite > outputSeenChanges && OutputState != null)
_logger.LogInformation($"Using incremental build picking up changes since: {OutputState.LastSeenChanges}");
else if (DocumentationSet.LastWrite <= outputSeenChanges && OutputState != null)
{
Expand All @@ -108,8 +115,11 @@ public async Task GenerateAll(Cancel ctx)

await Parallel.ForEachAsync(DocumentationSet.Files, ctx, async (file, token) =>
{
if (file.SourceFile.LastWriteTimeUtc <= outputSeenChanges)
if (offendingFiles.Contains(file.SourceFile.FullName))
_logger.LogInformation($"Re-evaluating {file.SourceFile.FullName}");
else if (file.SourceFile.LastWriteTimeUtc <= outputSeenChanges)
return;
var item = Interlocked.Increment(ref handledItems);
var outputFile = OutputFile(file.RelativePath);
if (file is MarkdownFile markdown)
Expand Down Expand Up @@ -147,7 +157,13 @@ private async Task GenerateDocumentationState(Cancel ctx)
{
var stateFile = DocumentationSet.OutputStateFile;
_logger.LogInformation($"Writing documentation state {DocumentationSet.LastWrite} to {stateFile.FullName}");
var state = new OutputState { LastSeenChanges = DocumentationSet.LastWrite };
var badFiles = Context.Collector.OffendingFiles.ToArray();
var state = new OutputState
{
LastSeenChanges = DocumentationSet.LastWrite,
Conflict = badFiles

};
var bytes = JsonSerializer.SerializeToUtf8Bytes(state, SourceGenerationContext.Default.OutputState);
await DocumentationSet.OutputPath.FileSystem.File.WriteAllBytesAsync(stateFile.FullName, bytes, ctx);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Elastic.Markdown/IO/DocumentationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class DocumentationSet
public string Name { get; }
public IDirectoryInfo SourcePath { get; }
public IDirectoryInfo OutputPath { get; }
public DateTimeOffset LastWrite { get; }
public IFileInfo OutputStateFile { get; }

public DateTimeOffset LastWrite { get; }

public ConfigurationFile Configuration { get; }

private MarkdownParser MarkdownParser { get; }
Expand Down

0 comments on commit b04f097

Please sign in to comment.