Add Git repository branch name and commit hash injection into generated code module metadata
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
//#define USE_AUTODESK_FBX_SDK
|
//#define USE_AUTODESK_FBX_SDK
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using FlaxEditor.GUI.Dialogs;
|
using FlaxEditor.GUI.Dialogs;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
@@ -45,9 +46,16 @@ namespace FlaxEditor.Windows
|
|||||||
VerticalAlignment = TextAlignment.Center,
|
VerticalAlignment = TextAlignment.Center,
|
||||||
Parent = this
|
Parent = this
|
||||||
};
|
};
|
||||||
|
var assembly = typeof(Editor).Assembly;
|
||||||
|
var assemblyCopyright = assembly.GetCustomAttribute<AssemblyCopyrightAttribute>();
|
||||||
|
var assemblyInformationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||||
|
var versionParts = assemblyInformationalVersion.InformationalVersion.Split('+');
|
||||||
|
string versionInfo = string.Empty;
|
||||||
|
if (versionParts.Length == 3)
|
||||||
|
versionInfo = $"\nBranch: {versionParts[1]}+{(versionParts[2].Length == 40 ? versionParts[2].Substring(0, 8) : versionParts[2])}";
|
||||||
new Label(nameLabel.Left, nameLabel.Bottom + 4, nameLabel.Width, 50)
|
new Label(nameLabel.Left, nameLabel.Bottom + 4, nameLabel.Width, 50)
|
||||||
{
|
{
|
||||||
Text = string.Format("Version: {0}\nCopyright (c) 2012-2025 Wojciech Figat.\nAll rights reserved.", Globals.EngineVersion),
|
Text = $"Version: {Globals.EngineVersion}{versionInfo}\n{assemblyCopyright.Copyright.Replace(". ", ".\n")}",
|
||||||
HorizontalAlignment = TextAlignment.Near,
|
HorizontalAlignment = TextAlignment.Near,
|
||||||
VerticalAlignment = TextAlignment.Near,
|
VerticalAlignment = TextAlignment.Near,
|
||||||
Parent = this
|
Parent = this
|
||||||
|
|||||||
@@ -595,7 +595,11 @@ void EngineImpl::InitLog()
|
|||||||
#if COMPILE_WITH_DEV_ENV
|
#if COMPILE_WITH_DEV_ENV
|
||||||
LOG(Info, "Compiled for Dev Environment");
|
LOG(Info, "Compiled for Dev Environment");
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(FLAXENGINE_BRANCH) && defined(FLAXENGINE_COMMIT)
|
||||||
|
LOG(Info, "Version " FLAXENGINE_VERSION_TEXT ", " FLAXENGINE_BRANCH ", " FLAXENGINE_COMMIT);
|
||||||
|
#else
|
||||||
LOG(Info, "Version " FLAXENGINE_VERSION_TEXT);
|
LOG(Info, "Version " FLAXENGINE_VERSION_TEXT);
|
||||||
|
#endif
|
||||||
const Char* cpp = TEXT("?");
|
const Char* cpp = TEXT("?");
|
||||||
if (__cplusplus == 202101L) cpp = TEXT("C++23");
|
if (__cplusplus == 202101L) cpp = TEXT("C++23");
|
||||||
else if (__cplusplus == 202002L) cpp = TEXT("C++20");
|
else if (__cplusplus == 202002L) cpp = TEXT("C++20");
|
||||||
|
|||||||
@@ -2429,7 +2429,7 @@ namespace Flax.Build.Bindings
|
|||||||
contents.AppendLine();
|
contents.AppendLine();
|
||||||
contents.AppendLine($"[assembly: AssemblyTitle(\"{binaryModuleName}\")]");
|
contents.AppendLine($"[assembly: AssemblyTitle(\"{binaryModuleName}\")]");
|
||||||
contents.AppendLine("[assembly: AssemblyDescription(\"\")]");
|
contents.AppendLine("[assembly: AssemblyDescription(\"\")]");
|
||||||
contents.AppendLine("[assembly: AssemblyConfiguration(\"\")]");
|
contents.AppendLine($"[assembly: AssemblyConfiguration(\"{buildData.Configuration}\")]");
|
||||||
contents.AppendLine($"[assembly: AssemblyCompany(\"{project.Company}\")]");
|
contents.AppendLine($"[assembly: AssemblyCompany(\"{project.Company}\")]");
|
||||||
contents.AppendLine("[assembly: AssemblyProduct(\"FlaxEngine\")]");
|
contents.AppendLine("[assembly: AssemblyProduct(\"FlaxEngine\")]");
|
||||||
contents.AppendLine($"[assembly: AssemblyCopyright(\"{project.Copyright}\")]");
|
contents.AppendLine($"[assembly: AssemblyCopyright(\"{project.Copyright}\")]");
|
||||||
@@ -2439,6 +2439,7 @@ namespace Flax.Build.Bindings
|
|||||||
contents.AppendLine($"[assembly: Guid(\"{id:d}\")]");
|
contents.AppendLine($"[assembly: Guid(\"{id:d}\")]");
|
||||||
contents.AppendLine($"[assembly: AssemblyVersion(\"{project.Version}\")]");
|
contents.AppendLine($"[assembly: AssemblyVersion(\"{project.Version}\")]");
|
||||||
contents.AppendLine($"[assembly: AssemblyFileVersion(\"{project.Version}\")]");
|
contents.AppendLine($"[assembly: AssemblyFileVersion(\"{project.Version}\")]");
|
||||||
|
contents.AppendLine($"[assembly: AssemblyInformationalVersion(\"{project.VersionControlInfo}\")]");
|
||||||
#if USE_NETCORE
|
#if USE_NETCORE
|
||||||
contents.AppendLine("[assembly: DisableRuntimeMarshalling]");
|
contents.AppendLine("[assembly: DisableRuntimeMarshalling]");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3289,6 +3289,10 @@ namespace Flax.Build.Bindings
|
|||||||
contents.AppendLine($"#define {binaryModuleNameUpper}_VERSION_REVISION {version.Revision}");
|
contents.AppendLine($"#define {binaryModuleNameUpper}_VERSION_REVISION {version.Revision}");
|
||||||
contents.AppendLine($"#define {binaryModuleNameUpper}_COMPANY \"{project.Company}\"");
|
contents.AppendLine($"#define {binaryModuleNameUpper}_COMPANY \"{project.Company}\"");
|
||||||
contents.AppendLine($"#define {binaryModuleNameUpper}_COPYRIGHT \"{project.Copyright}\"");
|
contents.AppendLine($"#define {binaryModuleNameUpper}_COPYRIGHT \"{project.Copyright}\"");
|
||||||
|
if (project.VersionControlBranch.Length != 0)
|
||||||
|
contents.AppendLine($"#define {binaryModuleNameUpper}_BRANCH \"{project.VersionControlBranch}\"");
|
||||||
|
if (project.VersionControlCommit.Length != 0)
|
||||||
|
contents.AppendLine($"#define {binaryModuleNameUpper}_COMMIT \"{project.VersionControlCommit}\"");
|
||||||
contents.AppendLine();
|
contents.AppendLine();
|
||||||
contents.AppendLine("class BinaryModule;");
|
contents.AppendLine("class BinaryModule;");
|
||||||
contents.AppendLine($"extern \"C\" {binaryModuleNameUpper}_API BinaryModule* GetBinaryModule{binaryModuleName}();");
|
contents.AppendLine($"extern \"C\" {binaryModuleNameUpper}_API BinaryModule* GetBinaryModule{binaryModuleName}();");
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ namespace Flax.Build
|
|||||||
public sealed class ProjectInfo
|
public sealed class ProjectInfo
|
||||||
{
|
{
|
||||||
private static List<ProjectInfo> _projectsCache;
|
private static List<ProjectInfo> _projectsCache;
|
||||||
|
private string _versionControlCommit, _versionControlBranch;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The project reference.
|
/// The project reference.
|
||||||
@@ -232,6 +233,51 @@ namespace Flax.Build
|
|||||||
[System.Text.Json.Serialization.JsonConverter(typeof(ConfigurationDictionaryConverter))]
|
[System.Text.Json.Serialization.JsonConverter(typeof(ConfigurationDictionaryConverter))]
|
||||||
public Dictionary<string, string> Configuration;
|
public Dictionary<string, string> Configuration;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the branch from Version Control System (VCS) used by the project. Empty when unused.
|
||||||
|
/// </summary>
|
||||||
|
public string VersionControlBranch
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_versionControlBranch == null)
|
||||||
|
InitVersionControlInfo();
|
||||||
|
return _versionControlBranch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the commit hash/changeset identifier from Version Control System (VCS) used by the project. Empty when unused.
|
||||||
|
/// </summary>
|
||||||
|
public string VersionControlCommit
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_versionControlCommit == null)
|
||||||
|
InitVersionControlInfo();
|
||||||
|
return _versionControlCommit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the informative version of the project including any Version Control System (VCS) information such as branch name, commit hash or changeset identifier.
|
||||||
|
/// </summary>
|
||||||
|
public string VersionControlInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_versionControlCommit == null)
|
||||||
|
InitVersionControlInfo();
|
||||||
|
var version = Version.ToString();
|
||||||
|
if (_versionControlBranch.Length != 0)
|
||||||
|
version += "+" + _versionControlBranch;
|
||||||
|
if (_versionControlCommit.Length != 0)
|
||||||
|
version += "+" + _versionControlCommit;
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True if project is using C#-only and no native toolsets is required to build and use scripts.
|
/// True if project is using C#-only and no native toolsets is required to build and use scripts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -267,6 +313,26 @@ namespace Flax.Build
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InitVersionControlInfo()
|
||||||
|
{
|
||||||
|
_versionControlBranch = string.Empty;
|
||||||
|
_versionControlCommit = string.Empty;
|
||||||
|
|
||||||
|
// Git
|
||||||
|
if (Directory.Exists(Path.Combine(ProjectFolderPath, ".git")))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_versionControlBranch = Utilities.ReadProcessOutput("git", "rev-parse --abbrev-ref HEAD", ProjectFolderPath);
|
||||||
|
_versionControlCommit = Utilities.ReadProcessOutput("git", "rev-parse HEAD", ProjectFolderPath);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all projects including this project, it's references and their references (any deep level of references).
|
/// Gets all projects including this project, it's references and their references (any deep level of references).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -587,8 +587,9 @@ namespace Flax.Build
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The executable file path.</param>
|
/// <param name="filename">The executable file path.</param>
|
||||||
/// <param name="args">The custom arguments.</param>
|
/// <param name="args">The custom arguments.</param>
|
||||||
|
/// <param name="workspace">The custom folder to run program in it.</param>
|
||||||
/// <returns>Returned process output.</returns>
|
/// <returns>Returned process output.</returns>
|
||||||
public static string ReadProcessOutput(string filename, string args = null)
|
public static string ReadProcessOutput(string filename, string args = null, string workspace = null)
|
||||||
{
|
{
|
||||||
Process p = new Process
|
Process p = new Process
|
||||||
{
|
{
|
||||||
@@ -599,6 +600,7 @@ namespace Flax.Build
|
|||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
|
WorkingDirectory = workspace,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
p.Start();
|
p.Start();
|
||||||
|
|||||||
Reference in New Issue
Block a user