Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Add automatic version numbering from git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dalegaard committed Aug 28, 2019
1 parent d05efc9 commit bc56883
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*.pdb
/Release/
/Debug/
CastingEssentials/build
CastingEssentials/Release/
CastingEssentials/Debug/
*.exp
Expand Down
13 changes: 13 additions & 0 deletions CastingEssentials/CastingEssentials.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
<EnableCOMDATFolding>false</EnableCOMDATFolding>
<OptimizeReferences>false</OptimizeReferences>
</Link>
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy ByPass -File $(SolutionDir)\genversion.ps1 $(ProjectDir)build\Version.cpp "-debug"</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Create version info</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -85,10 +91,17 @@
<PostBuildEvent>
<Command>copy "$(TargetPath)" "$(SolutionDir)plugin_folder\addons\$(TargetFileName)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy ByPass -File $(SolutionDir)\genversion.ps1 $(ProjectDir)build\Version.cpp</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Create version info</Message>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(SolutionDir)\sdk2013\mp\src\public\tier0\memoverride.cpp" />
<ClCompile Include="..\sdk2013\mp\src\public\vgui_controls\vgui_controls.cpp" />
<ClCompile Include="build\Version.cpp" />
<ClCompile Include="Controls\ImageProgressBar.cpp" />
<ClCompile Include="Controls\VariableLabel.cpp" />
<ClCompile Include="Hooking\IBaseHook.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions CastingEssentials/CastingEssentials.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
<ClCompile Include="Modules\SrcTVPlus.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="build\Version.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="PluginBase\Plugin.h">
Expand Down
3 changes: 0 additions & 3 deletions CastingEssentials/PluginBase/CastingPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

#include <convar.h>

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:
Expand Down
6 changes: 2 additions & 4 deletions CastingEssentials/PluginBase/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 ";
Expand Down
33 changes: 33 additions & 0 deletions genversion.ps1
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit bc56883

Please sign in to comment.