From 6e2383f70d2ac319276f0442fe60589ff30afd24 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Mon, 5 Jun 2023 17:33:28 -0300 Subject: [PATCH] Ensure IsDirty is a constant Fixes the regression reported in #287. Fixes #285. --- src/Analyzer/GitInfoGenerator.cs | 15 ++++++++++----- src/GitInfo/build/GitInfo.ThisAssembly.targets | 8 ++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Analyzer/GitInfoGenerator.cs b/src/Analyzer/GitInfoGenerator.cs index bd29b24..be188a7 100644 --- a/src/Analyzer/GitInfoGenerator.cs +++ b/src/Analyzer/GitInfoGenerator.cs @@ -6,14 +6,19 @@ class GitInfoGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { var ns = context.AnalyzerConfigOptionsProvider - .Select((c, _) => c.GlobalOptions.TryGetValue("build_property.ThisAssemblyNamespace", out var ns) - && !string.IsNullOrEmpty(ns) ? ns : null); + .Select((c, _) => new + { + Namespace = c.GlobalOptions.TryGetValue("build_property.ThisAssemblyNamespace", out var ns) + && !string.IsNullOrEmpty(ns) ? ns : null, + IsDirty = c.GlobalOptions.TryGetValue("build_property.GitIsDirty", out var dirty) + && dirty == "1" ? true : false + }); context.RegisterSourceOutput(ns, - (c, ns) => + (c, state) => { // Legacy codegen used for this scenario, emit nothing. - if (!string.IsNullOrEmpty(ns)) + if (!string.IsNullOrEmpty(state.Namespace)) return; c.AddSource("ThisAssembly.Git.IsDirty.g", @@ -36,7 +41,7 @@ partial class Git /// /// Gets whether the current repository is dirty. /// - public static bool IsDirty => bool.TryParse(IsDirtyString, out var dirty) && dirty; + public const bool IsDirty = {{(state.IsDirty ? "true" : "false")}}; } } """); diff --git a/src/GitInfo/build/GitInfo.ThisAssembly.targets b/src/GitInfo/build/GitInfo.ThisAssembly.targets index 4cb585b..ae4f7b1 100644 --- a/src/GitInfo/build/GitInfo.ThisAssembly.targets +++ b/src/GitInfo/build/GitInfo.ThisAssembly.targets @@ -34,10 +34,14 @@ + BeforeTargets="PrepareConstants;GenerateMSBuildEditorConfigFileShouldRun" Condition="'$(GitThisAssembly)' == 'true'"> - + + + + +