Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
gitfool committed Jun 18, 2024
1 parent 65aaac9 commit c5baa41
Show file tree
Hide file tree
Showing 11 changed files with 601 additions and 784 deletions.
246 changes: 111 additions & 135 deletions readme.md

Large diffs are not rendered by default.

51 changes: 21 additions & 30 deletions src/GitInfo/build/GitInfo.AssemblyInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,26 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
==============================================================
Provides ThisAssembly generation
Provides ThisAssembly generation.
$(GitThisAssembly): set to 'false' to prevent assembly
metadata and constants generation.
$(GitThisAssembly): set to 'false' to prevent assembly metadata and constants generation.
$(ThisAssemblyNamespace): allows overriding the namespace
for the ThisAssembly class.
Defaults to the global namespace.
==============================================================
-->
$(ThisAssemblyNamespace): allows overriding the namespace for the ThisAssembly class. Defaults to the global namespace.
==============================================================
-->

<PropertyGroup>
<GitInfoThisAssemblyFile Condition="'$(GitInfoThisAssemblyFile)' == '' And '$(DefaultLanguageSourceExtension)' != ''">$(IntermediateOutputPath)ThisAssembly.GitInfo.g$(DefaultLanguageSourceExtension)</GitInfoThisAssemblyFile>
<GitThisAssembly Condition="'$(Language)' != 'C#' And '$(Language)' != 'F#' And '$(Language)' != 'VB'">false</GitThisAssembly>
<GitThisAssembly Condition="'$(GitThisAssembly)' == '' And '$(GitInfoThisAssemblyFile)' != ''">true</GitThisAssembly>
<GitInfoThisAssemblyFile Condition="'$(GitInfoThisAssemblyFile)' == '' and '$(DefaultLanguageSourceExtension)' != ''">$(IntermediateOutputPath)ThisAssembly.GitInfo.g$(DefaultLanguageSourceExtension)</GitInfoThisAssemblyFile>
<GitThisAssembly Condition="'$(Language)' != 'C#' and '$(Language)' != 'F#' and '$(Language)' != 'VB'">false</GitThisAssembly>
<GitThisAssembly Condition="'$(GitThisAssembly)' == '' and '$(GitInfoThisAssemblyFile)' != ''">true</GitThisAssembly>
</PropertyGroup>

<!-- Private properties -->
<PropertyGroup>
<CoreCompileDependsOn Condition="'$(GitThisAssembly)' == 'true'">GitThisAssembly;$(CoreCompileDependsOn)</CoreCompileDependsOn>
</PropertyGroup>

<Target Name="GitThisAssembly" DependsOnTargets="GitVersion;_GitGenerateThisAssembly"
BeforeTargets="BuildOnlySettings" Condition="'$(GitThisAssembly)' == 'true'">

<Target Name="GitThisAssembly" DependsOnTargets="GitVersion;_GitGenerateThisAssembly" BeforeTargets="BuildOnlySettings" Condition="'$(GitThisAssembly)' == 'true'">
<ItemGroup Condition="'$(Language)' != 'F#'">
<Compile Remove="$(GitInfoThisAssemblyFile)" />
<Compile Include="$(GitInfoThisAssemblyFile)" />
Expand All @@ -44,9 +38,7 @@
</ItemGroup>
</Target>

<Target Name="_GitGenerateThisAssembly" Condition="'$(GitThisAssembly)' == 'true'"
Inputs="@(_GitInput)" Outputs="$(GitInfoThisAssemblyFile)">

<Target Name="_GitGenerateThisAssembly" Inputs="@(_GitInput)" Outputs="$(GitInfoThisAssemblyFile)" Condition="'$(GitThisAssembly)' == 'true'">
<PropertyGroup>
<_ThisAssemblyContent>$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)GitInfo$(DefaultLanguageSourceExtension).pp'))</_ThisAssemblyContent>

Expand All @@ -61,17 +53,17 @@
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('_RootNamespace_', '$(ThisAssemblyNamespace)'))</_ThisAssemblyContent>

<!-- no git repository -->
<_ThisAssemblyContent Condition="'$(Language)' == 'C#' And '$(GitRoot)' == ''">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'C#' And '$(GitIsDirty)' != '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'true'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'C#' And '$(GitIsDirty)' == '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'C#' and '$(GitRoot)' == ''">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'C#' and '$(GitIsDirty)' != '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'true'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'C#' and '$(GitIsDirty)' == '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false'))</_ThisAssemblyContent>
<!-- no git repository -->
<_ThisAssemblyContent Condition="'$(Language)' == 'F#' And '$(GitRoot)' == ''">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'F#' And '$(GitIsDirty)' != '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'true'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'F#' And '$(GitIsDirty)' == '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'F#' and '$(GitRoot)' == ''">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'F#' and '$(GitIsDirty)' != '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'true'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'F#' and '$(GitIsDirty)' == '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false'))</_ThisAssemblyContent>
<!-- no git repository -->
<_ThisAssemblyContent Condition="'$(Language)' == 'VB' And '$(GitRoot)' == ''">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'False'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'VB' And '$(GitIsDirty)' != '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'True'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'VB' And '$(GitIsDirty)' == '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'False'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'VB' and '$(GitRoot)' == ''">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'False'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'VB' and '$(GitIsDirty)' != '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'True'))</_ThisAssemblyContent>
<_ThisAssemblyContent Condition="'$(Language)' == 'VB' and '$(GitIsDirty)' == '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'False'))</_ThisAssemblyContent>

<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitRepositoryUrl$', '$(GitRepositoryUrl)'))</_ThisAssemblyContent>
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitBranch$', '$(GitBranch)'))</_ThisAssemblyContent>
Expand Down Expand Up @@ -100,7 +92,6 @@

<MakeDir Directories="$(GitInfoThisAssemblyDir)" Condition="!Exists('$(GitInfoThisAssemblyDir)')" />

<WriteLinesToFile File='$(GitInfoThisAssemblyFile)' Lines='$(_ThisAssemblyContent)' Overwrite='true' />
<WriteLinesToFile File="$(GitInfoThisAssemblyFile)" Lines="$(_ThisAssemblyContent)" Overwrite="true" />
</Target>

</Project>
</Project>
40 changes: 12 additions & 28 deletions src/GitInfo/build/GitInfo.AssemblyMetadata.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,24 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
==============================================================
Provides assembly-level metadata
for Git information.
Provides assembly-level metadata for Git information.
$(GitThisAssemblyMetadata): set to 'false' to prevent assembly
metadata generation. Defaults to 'false'.
==============================================================
-->
$(GitThisAssemblyMetadata): set to 'false' to prevent assembly metadata generation. Defaults to 'false'.
==============================================================
-->

<Target Name="GitAssemblyMetadata" DependsOnTargets="GitVersion" BeforeTargets="BuildOnlySettings">

<ItemGroup Condition="'$(Language)' != 'VB'">
<AssemblyMetadata Include="GitInfo.IsDirty"
Condition="'$(GitRoot)' == ''"
Value="false" />
<AssemblyMetadata Include="GitInfo.IsDirty"
Condition="'$(GitIsDirty)' != '0'"
Value="true" />
<AssemblyMetadata Include="GitInfo.IsDirty"
Condition="'$(GitIsDirty)' == '0'"
Value="false" />
<AssemblyMetadata Include="GitInfo.IsDirty" Value="false" Condition="'$(GitRoot)' == ''" />
<AssemblyMetadata Include="GitInfo.IsDirty" Value="true" Condition="'$(GitIsDirty)' != '0'" />
<AssemblyMetadata Include="GitInfo.IsDirty" Value="false" Condition="'$(GitIsDirty)' == '0'" />
</ItemGroup>

<!-- For backwards-compatibility reasons, we keep the VB casing on these -->
<!-- For backwards-compatibility reasons, we keep the VB casing on these. -->
<ItemGroup Condition="'$(Language)' == 'VB'">
<AssemblyMetadata Include="GitInfo.IsDirty"
Condition="'$(GitRoot)' == ''"
Value="False" />
<AssemblyMetadata Include="GitInfo.IsDirty"
Condition="'$(GitIsDirty)' != '0'"
Value="True" />
<AssemblyMetadata Include="GitInfo.IsDirty"
Condition="'$(GitIsDirty)' == '0'"
Value="False" />
<AssemblyMetadata Include="GitInfo.IsDirty" Value="False" Condition="'$(GitRoot)' == ''" />
<AssemblyMetadata Include="GitInfo.IsDirty" Value="True" Condition="'$(GitIsDirty)' != '0'" />
<AssemblyMetadata Include="GitInfo.IsDirty" Value="False" Condition="'$(GitIsDirty)' == '0'" />
</ItemGroup>

<ItemGroup>
Expand All @@ -58,5 +43,4 @@
<AssemblyMetadata Include="GitInfo.SemVer.Source" Value="$(GitSemVerSource)" />
</ItemGroup>
</Target>

</Project>
</Project>
19 changes: 6 additions & 13 deletions src/GitInfo/build/GitInfo.ThisAssembly.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
==============================================================
Leverages ThisAssembly.Constants generator
to expose assembly info constants
Leverages ThisAssembly.Constants generator to expose assembly info constants.
$(GitThisAssembly): set to 'false' to prevent assembly
metadata and constants generation.
==============================================================
-->
$(GitThisAssembly): set to 'false' to prevent assembly metadata and constants generation.
==============================================================
-->

<PropertyGroup>
<GitThisAssembly Condition="'$(GitThisAssembly)' == ''">true</GitThisAssembly>
Expand All @@ -25,9 +22,7 @@
<CompilerVisibleProperty Include="GitThisAssembly" />
</ItemGroup>

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

<Target Name="GitThisAssembly" DependsOnTargets="GitVersion" BeforeTargets="PrepareConstants;GenerateMSBuildEditorConfigFileShouldRun" Condition="'$(GitThisAssembly)' == 'true'">
<ItemGroup>
<Constant Include="IsDirtyString" Value="true" Root="Git" Condition="$(GitIsDirty) == '1'" />
<Constant Include="IsDirtyString" Value="false" Root="Git" Condition="$(GitIsDirty) == '0'" />
Expand All @@ -52,7 +47,5 @@
<Constant Include="SemVer.DashLabel" Value="$(GitSemVerDashLabel)" Root="Git" />
<Constant Include="SemVer.Source" Value="$(GitSemVerSource)" Root="Git" />
</ItemGroup>

</Target>

</Project>
</Project>
2 changes: 1 addition & 1 deletion src/GitInfo/build/GitInfo.cache.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
GitSemVerPatch=$GitSemVerPatch$;
GitSemVerLabel=$GitSemVerLabel$;
GitSemVerDashLabel=$GitSemVerDashLabel$;
GitSemVerSource=$GitSemVerSource$
GitSemVerSource=$GitSemVerSource$
104 changes: 52 additions & 52 deletions src/GitInfo/build/GitInfo.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,78 @@
namespace _RootNamespace_
{
#endif
/// <summary>Provides access to the current assembly information.</summary>
partial class ThisAssembly
{
/// <summary>Provides access to the git information for the current assembly.</summary>
public partial class Git
/// <summary>Provides access to the current assembly information.</summary>
partial class ThisAssembly
{
/// <summary>IsDirty: $GitIsDirty$</summary>
public const bool IsDirty = $GitIsDirty$;
/// <summary>Provides access to the git information for the current assembly.</summary>
public partial class Git
{
/// <summary>IsDirty: $GitIsDirty$</summary>
public const bool IsDirty = $GitIsDirty$;

/// <summary>IsDirtyString: $GitIsDirty$</summary>
public const string IsDirtyString = @"$GitIsDirty$";
/// <summary>IsDirtyString: $GitIsDirty$</summary>
public const string IsDirtyString = @"$GitIsDirty$";

/// <summary>Repository URL: $GitRepositoryUrl$</summary>
public const string RepositoryUrl = @"$GitRepositoryUrl$";
/// <summary>Repository URL: $GitRepositoryUrl$</summary>
public const string RepositoryUrl = @"$GitRepositoryUrl$";

/// <summary>Branch: $GitBranch$</summary>
public const string Branch = @"$GitBranch$";
/// <summary>Branch: $GitBranch$</summary>
public const string Branch = @"$GitBranch$";

/// <summary>Commit: $GitCommit$</summary>
public const string Commit = @"$GitCommit$";
/// <summary>Commit: $GitCommit$</summary>
public const string Commit = @"$GitCommit$";

/// <summary>Sha: $GitSha$</summary>
public const string Sha = @"$GitSha$";
/// <summary>Sha: $GitSha$</summary>
public const string Sha = @"$GitSha$";

/// <summary>Commit date: $GitCommitDate$</summary>
public const string CommitDate = @"$GitCommitDate$";
/// <summary>Commit date: $GitCommitDate$</summary>
public const string CommitDate = @"$GitCommitDate$";

/// <summary>Commits on top of base version: $GitCommits$</summary>
public const string Commits = @"$GitCommits$";
/// <summary>Commits on top of base version: $GitCommits$</summary>
public const string Commits = @"$GitCommits$";

/// <summary>Tag: $GitTag$</summary>
public const string Tag = @"$GitTag$";
/// <summary>Tag: $GitTag$</summary>
public const string Tag = @"$GitTag$";

/// <summary>Base tag: $GitBaseTag$</summary>
public const string BaseTag = @"$GitBaseTag$";
/// <summary>Base tag: $GitBaseTag$</summary>
public const string BaseTag = @"$GitBaseTag$";

/// <summary>Provides access to the base version information used to determine the <see cref="SemVer" />.</summary>
public partial class BaseVersion
{
/// <summary>Major: $GitBaseVersionMajor$</summary>
public const string Major = @"$GitBaseVersionMajor$";
/// <summary>Provides access to the base version information used to determine the <see cref="SemVer" />.</summary>
public partial class BaseVersion
{
/// <summary>Major: $GitBaseVersionMajor$</summary>
public const string Major = @"$GitBaseVersionMajor$";

/// <summary>Minor: $GitBaseVersionMinor$</summary>
public const string Minor = @"$GitBaseVersionMinor$";
/// <summary>Minor: $GitBaseVersionMinor$</summary>
public const string Minor = @"$GitBaseVersionMinor$";

/// <summary>Patch: $GitBaseVersionPatch$</summary>
public const string Patch = @"$GitBaseVersionPatch$";
}
/// <summary>Patch: $GitBaseVersionPatch$</summary>
public const string Patch = @"$GitBaseVersionPatch$";
}

/// <summary>Provides access to SemVer information for the current assembly.</summary>
public partial class SemVer
{
/// <summary>Major: $GitSemVerMajor$</summary>
public const string Major = @"$GitSemVerMajor$";
/// <summary>Provides access to SemVer information for the current assembly.</summary>
public partial class SemVer
{
/// <summary>Major: $GitSemVerMajor$</summary>
public const string Major = @"$GitSemVerMajor$";

/// <summary>Minor: $GitSemVerMinor$</summary>
public const string Minor = @"$GitSemVerMinor$";
/// <summary>Minor: $GitSemVerMinor$</summary>
public const string Minor = @"$GitSemVerMinor$";

/// <summary>Patch: $GitSemVerPatch$</summary>
public const string Patch = @"$GitSemVerPatch$";
/// <summary>Patch: $GitSemVerPatch$</summary>
public const string Patch = @"$GitSemVerPatch$";

/// <summary>Label: $GitSemVerLabel$</summary>
public const string Label = @"$GitSemVerLabel$";
/// <summary>Label: $GitSemVerLabel$</summary>
public const string Label = @"$GitSemVerLabel$";

/// <summary>Label with dash prefix: $GitSemVerDashLabel$</summary>
public const string DashLabel = @"$GitSemVerDashLabel$";
/// <summary>Label with dash prefix: $GitSemVerDashLabel$</summary>
public const string DashLabel = @"$GitSemVerDashLabel$";

/// <summary>Source: $GitSemVerSource$</summary>
public const string Source = @"$GitSemVerSource$";
}
/// <summary>Source: $GitSemVerSource$</summary>
public const string Source = @"$GitSemVerSource$";
}
}
}
}
#if LOCALNAMESPACE
}
#endif
Expand Down
5 changes: 2 additions & 3 deletions src/GitInfo/build/GitInfo.fs.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// <auto-generated />
/// <summary>Provides access to the current assembly information.</summary>
module ThisAssembly
module ThisAssembly

/// <summary>Provides access to the git information for the current assembly.</summary>
module Git =
Expand Down Expand Up @@ -34,7 +34,7 @@
/// <summary>Base tag: $GitBaseTag$</summary>
let [<Literal>] BaseTag = @"$GitBaseTag$"

/// <summary>Provides access to the base version information used to determine the <see cref="SemVer" />.</summary>
/// <summary>Provides access to the base version information used to determine the <see cref="SemVer" />.</summary>
module BaseVersion =
/// <summary>Major: $GitBaseVersionMajor$</summary>
let [<Literal>] Major = @"$GitBaseVersionMajor$"
Expand All @@ -45,7 +45,6 @@
/// <summary>Patch: $GitBaseVersionPatch$</summary>
let [<Literal>] Patch = @"$GitBaseVersionPatch$"


/// <summary>Provides access to SemVer information for the current assembly.</summary>
module SemVer =
/// <summary>Major: $GitSemVerMajor$</summary>
Expand Down
Loading

0 comments on commit c5baa41

Please sign in to comment.