Skip to content

Commit

Permalink
Add version from git
Browse files Browse the repository at this point in the history
Currently only visible in the VERSIONINFO in the executable
Fixes #2
  • Loading branch information
ffes committed Oct 16, 2023
1 parent b8582b1 commit 4004d94
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ indent_style = space

[*.md]
trim_trailing_whitespace = false

[*.sh]
end_of_line = lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Debug/
Release/
x64/
*.user
version-git.h
55 changes: 55 additions & 0 deletions RebootAt.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/////////////////////////////////////////////////////////////////////////////
// //
// RebootAt - Reboot Windows at a given time //
// Copyright (C) 2023 Frank Fesevur //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
// //
/////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include "version-git.h"

/////////////////////////////////////////////////////////////////////////////
// Version Information

VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_NUMBER
PRODUCTVERSION VERSION_NUMBER
FILEFLAGSMASK 0x3fL
FILEFLAGS 0
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
{
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x409, 1200
}
BLOCK "StringFileInfo"
{
BLOCK "040904b0"
{
VALUE "CompanyName", "Frank Fesevur"
VALUE "FileDescription", "Reboot Windows at a given time"
VALUE "FileVersion", VERSION_NUMBER_STR
VALUE "InternalName", "RebootAt.exe"
VALUE "LegalCopyright", COPYRIGHT_STR
VALUE "OriginalFilename", "RebootAt.exe"
VALUE "ProductName", "RebootAt"
VALUE "ProductVersion", VERSION_NUMBER_STR
}
}
}
9 changes: 9 additions & 0 deletions RebootAt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PreBuildEvent>
<Command>call $(SolutionDir)version-git.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -70,10 +73,16 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PreBuildEvent>
<Command>call $(SolutionDir)version-git.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="RebootAt.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="RebootAt.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
7 changes: 6 additions & 1 deletion RebootAt.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="RebootAt.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="RebootAt.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
41 changes: 41 additions & 0 deletions version-git.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@echo off

REM Is Git for Windows x64 installed?
if exist "%ProgramW6432%\Git\bin\bash.exe" (

echo Using bash from Git for Windows x64
setlocal
PATH=%ProgramW6432%\Git\mingw64\bin;%ProgramW6432%\Git\bin
bash version-git.sh
exit /b 0
)

REM Is Cygwin installed?
if exist C:\Cygwin\bin\bash.exe (

echo Using bash from Cygwin
setlocal
PATH=C:\Cygwin\bin
bash version-git.sh
exit /b 0
)

REM Is Cygwin64 installed?
if exist C:\Cygwin64\bin\bash.exe (

echo Using bash from Cygwin64
setlocal
PATH=C:\Cygwin64\bin
bash version-git.sh
exit /b 0
)

REM No Cygwin or Git for Windows installed
REM If there is a file assume if is properly generated
if exist version-git.h (
echo No bash found, but version-git.h exists
exit /b 0
)

echo No bash found
exit /b 1
56 changes: 56 additions & 0 deletions version-git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

function check_if_installed()
{
# Go through all the tools that need to be checked
for i in $*
do
# Is tool installed?
if ! type "$i" >/dev/null 2>&1
then
echo "Required tool \"$i\" not found!"
exit 1
fi
done
}

function create_version_git_h()
{
# Make sure there is a file, but don't touch it if not needed
[[ -f version-git.h ]] || touch version-git.h

# Make sure the locale is set properly
export LANG=en_US.UTF8

# Get the version info from git
echo "Retrieving version information from git..."
GIT_VERSION=$(git describe --tags --match 'v[0-9]*')
echo "Found version $GIT_VERSION"

# Has the version changed?
if grep --quiet $GIT_VERSION version-git.h
then
echo "Latest version info already in version-git.h"
exit 0
fi

# Get additional version info from git
echo "Retrieving additional version information from git..."
VERSION=$(git describe --tags --abbrev=0 | grep -oP '\d+\.\d+\.\d+')
VERSION_NUMBERS=$(echo $VERSION | tr "." ","),0
YEAR=$(date +%Y)

echo "Generating version-git.h..."
echo "#pragma once" > version-git.h
echo "#define VERSION_NUMBER $VERSION_NUMBERS" >> version-git.h
echo "#define VERSION_NUMBER_STR \"$VERSION\"" >> version-git.h
echo "#define VERSION_NUMBER_WSTR L\"$VERSION\"" >> version-git.h
echo "#define COPYRIGHT_STR \"Copyright (c) 2023-$YEAR by Frank Fesevur\"" >> version-git.h
echo "#define VERSION_GIT_STR \"$GIT_VERSION\"" >> version-git.h
echo "#define VERSION_GIT_WSTR L\"$GIT_VERSION\"" >> version-git.h
}

# Check if all the tools we need are installed
check_if_installed git grep tr date

create_version_git_h

0 comments on commit 4004d94

Please sign in to comment.