Skip to content

Commit

Permalink
Do not emit ThisAssembly.Git.IsDirty when GitThisAssembly is false
Browse files Browse the repository at this point in the history
We missed checking this in the source-generator.

Fixes #337
  • Loading branch information
kzu committed May 8, 2024
1 parent 10d8c91 commit 16be449
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Analyzer/GitInfoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
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
&& dirty == "1" ? true : false,
NoThisAssembly = c.GlobalOptions.TryGetValue("build_property.GitThisAssembly", out var value)
&& bool.TryParse(value, out var thisassembly) && !thisassembly ? true : false
});

context.RegisterSourceOutput(ns,
Expand All @@ -21,6 +23,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
if (!string.IsNullOrEmpty(state.Namespace))
return;

if (state.NoThisAssembly)
return;

c.AddSource("ThisAssembly.Git.IsDirty.g",
$$"""
//------------------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions src/GitInfo/build/GitInfo.ThisAssembly.targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
</GitThisAssemblyDependsOn>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="GitIsDirty" />
<CompilerVisibleProperty Include="GitThisAssembly" />
</ItemGroup>

<Target Name="GitThisAssembly" DependsOnTargets="$(GitThisAssemblyDependsOn)"
BeforeTargets="PrepareConstants;GenerateMSBuildEditorConfigFileShouldRun" Condition="'$(GitThisAssembly)' == 'true'">

<ItemGroup>
<CompilerVisibleProperty Include="GitIsDirty" />

<Constant Include="IsDirtyString" Value="true" Root="Git" Condition="$(GitIsDirty) == '1'" />
<Constant Include="IsDirtyString" Value="false" Root="Git" Condition="$(GitIsDirty) == '0'" />

Expand Down

0 comments on commit 16be449

Please sign in to comment.