From bc56883e308ee2b8189d231a5177cf82c2a59013 Mon Sep 17 00:00:00 2001 From: Lasse Dalegaard Date: Wed, 28 Aug 2019 16:19:36 +0200 Subject: [PATCH] Add automatic version numbering from git tags --- .gitignore | 1 + CastingEssentials/CastingEssentials.vcxproj | 13 ++++++++ .../CastingEssentials.vcxproj.filters | 3 ++ .../PluginBase/CastingPlugin.cpp | 3 -- CastingEssentials/PluginBase/Common.h | 6 ++-- genversion.ps1 | 33 +++++++++++++++++++ 6 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 genversion.ps1 diff --git a/.gitignore b/.gitignore index f7ba16e..f8c5121 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ *.pdb /Release/ /Debug/ +CastingEssentials/build CastingEssentials/Release/ CastingEssentials/Debug/ *.exp diff --git a/CastingEssentials/CastingEssentials.vcxproj b/CastingEssentials/CastingEssentials.vcxproj index 37fd0e5..2b4a89f 100644 --- a/CastingEssentials/CastingEssentials.vcxproj +++ b/CastingEssentials/CastingEssentials.vcxproj @@ -60,6 +60,12 @@ false false + + powershell.exe -ExecutionPolicy ByPass -File $(SolutionDir)\genversion.ps1 $(ProjectDir)build\Version.cpp "-debug" + + + Create version info + @@ -85,10 +91,17 @@ copy "$(TargetPath)" "$(SolutionDir)plugin_folder\addons\$(TargetFileName)" + + powershell.exe -ExecutionPolicy ByPass -File $(SolutionDir)\genversion.ps1 $(ProjectDir)build\Version.cpp + + + Create version info + + diff --git a/CastingEssentials/CastingEssentials.vcxproj.filters b/CastingEssentials/CastingEssentials.vcxproj.filters index dee71a5..bae466e 100644 --- a/CastingEssentials/CastingEssentials.vcxproj.filters +++ b/CastingEssentials/CastingEssentials.vcxproj.filters @@ -177,6 +177,9 @@ Source Files + + Source Files + diff --git a/CastingEssentials/PluginBase/CastingPlugin.cpp b/CastingEssentials/PluginBase/CastingPlugin.cpp index 25d1be0..b4c2a35 100644 --- a/CastingEssentials/PluginBase/CastingPlugin.cpp +++ b/CastingEssentials/PluginBase/CastingPlugin.cpp @@ -8,9 +8,6 @@ #include -const char* const PLUGIN_VERSION_ID = "r21-red02"; -const char* const PLUGIN_FULL_VERSION = strdup(strprintf("%s %s", PLUGIN_NAME, PLUGIN_VERSION_ID).c_str()); - class CastingPlugin final : public Plugin { public: diff --git a/CastingEssentials/PluginBase/Common.h b/CastingEssentials/PluginBase/Common.h index 424db45..e729821 100644 --- a/CastingEssentials/PluginBase/Common.h +++ b/CastingEssentials/PluginBase/Common.h @@ -10,9 +10,7 @@ #pragma warning(disable : 4592) // 'x': symbol will be dynamically initialized (implementation limitation) #pragma warning(disable : 4533) // initialization of 'x' is skipped by 'instruction' -- should only be a warning, but is promoted error for some reason? -//#define PLUGIN_VERSION "r7b1" - -static constexpr const char* PLUGIN_NAME = "CastingEssentialsRed"; +extern const char* const PLUGIN_NAME; extern const char* const PLUGIN_VERSION_ID; extern const char* const PLUGIN_FULL_VERSION; @@ -24,7 +22,7 @@ static constexpr float NDEBUG_PERSIST_TILL_NEXT_FRAME = -1.738f; static constexpr float NDEBUG_PERSIST_TILL_NEXT_FRAME = 0; // NDEBUG_PERSIST_TILL_NEXT_SERVER #endif -#define VPROF_BUDGETGROUP_CE _T("CastingEssentials") +#define VPROF_BUDGETGROUP_CE _T(PLUGIN_NAME) // For passing into strspn or whatever static constexpr const char* WHITESPACE_CHARS = "\t\n\v\f\r "; diff --git a/genversion.ps1 b/genversion.ps1 new file mode 100644 index 0000000..2d72298 --- /dev/null +++ b/genversion.ps1 @@ -0,0 +1,33 @@ +$filename = $args[0] + +$name = "CastingEssentialsRed"; +$shortstat = (git diff --shortstat 2>$null) | Out-String +$version = (git describe --always --tag --match "release-*" 2>$null) | Out-String +$version = $version.Trim().Substring(8) + +$dir = Split-Path -path "$filename" +if(!(Test-Path "$filename" -PathType Any)) { + New-Item -path "$dir" -type directory >$null +} + +if ($shortstat) { + $version = "${version}-dirty"; +} + +$current = ""; +if(Test-Path "$filename" -PathType Leaf) { + $current = Get-Content -Path "$filename" +} + +$suffix = $args[1] +if ($suffix) { + $version = "${version}${suffix}" +} + +$target = "extern const char* const PLUGIN_NAME = ""$name""; +extern const char* const PLUGIN_VERSION_ID = ""$version""; +extern const char* const PLUGIN_FULL_VERSION = ""$name $version"";" + +if ($target -ne $current) { + echo $target | Out-File "$filename" +}