Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental compile picks up files with errors/warnings #72

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading