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

Do not emit ThisAssembly.Git.IsDirty when GitThisAssembly is false #338

Merged
merged 1 commit into from
May 8, 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
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
Loading