From e4562205ba38c2832a9dff8138ed9aa6f0cd769a Mon Sep 17 00:00:00 2001 From: Marc Cannon Date: Sat, 19 Jan 2013 10:31:25 -0500 Subject: [PATCH] Add shell script to pull versioning info from Git on Windows and generate a "verinfo" header, then pull it into ProductInfo. This will cause Windows builds to fail until a call to this script is added. --- src/ProductInfo.cpp | 14 ++++++---- src/archutils/Win32/gen-git-verinfo.bat | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/archutils/Win32/gen-git-verinfo.bat diff --git a/src/ProductInfo.cpp b/src/ProductInfo.cpp index 954981d9..eb5f7145 100644 --- a/src/ProductInfo.cpp +++ b/src/ProductInfo.cpp @@ -1,11 +1,15 @@ #include "global.h" // also pulls in config.h #include "ProductInfo.h" -/* XXX: workaround until the Windows build can pull Git versioning. */ -#if !defined(HAVE_CONFIG_H) - #define BUILD_VERSION "beta3 DEV" - #define BUILD_DATE "unknown date" - #define BUILD_REVISION_TAG "unknown revision" +#if defined(HAVE_CONFIG_H) + /* included in global.h */ +#elif defined(WIN32) +#include "verinfo.h" +#else +#define BUILD_VERSION "unknown version" +#define BUILD_REV_DATE "unknown date" +#define BUILD_REV_TAG "unknown revision" +#warning No build information is available. #endif /* diff --git a/src/archutils/Win32/gen-git-verinfo.bat b/src/archutils/Win32/gen-git-verinfo.bat new file mode 100644 index 00000000..74203b73 --- /dev/null +++ b/src/archutils/Win32/gen-git-verinfo.bat @@ -0,0 +1,48 @@ +@echo off + +:: Written by vyhd for OpenITG +:: Do whatever you'd like with this! I just hacked it together. +:: Appropriately, I make no guarantees to it functioning properly. + +:: This is required to at least output a header with versioning info. +:: If it doesn't, the build will (correctly) fail to complete. + +set BUILD_VERSION=unknown version +set BUILD_REV_DATE=unknown date +set BUILD_REV_TAG=unknown revision + +:: Why I hate Windows, part 1: we have to use this incredibly ugly +:: and, frankly, nonsensical 'for' hack to assign output to variables +:: without using an intermediate temp file. + +:: Why I hate Windows, part 2: we don't know if 'git' is an exe or +:: a bat, and if it's a bat, we'll never return from the initial call +:: unless we invoke it through 'call'. Compatibility! + +:: Why I hate Windows, part 3: it's silently stripping out the = signs +:: in each invocation, so I spent at least half an hour trying to find +:: an alternative way to call --pretty="format:%ad" in a way that it +:: would accept. It turns out, if you use "--format=%%ad", the sign is +:: preserved. Go figure. + +for /f %%i in ('call git tag') do set BUILD_VERSION=%%i +for /f %%i in ('call git log -1 "--format=%%ad" --date=short') do set BUILD_REV_DATE=%%i +for /f %%i in ('call git describe') do set BUILD_REV_TAG=%%i + +if NOT "%BUILD_VERSION%" == "unknown version" ( + if NOT "%BUILD_VERSION%" == "%BUILD_REV_TAG%" ( + set BUILD_VERSION=%BUILD_VERSION% DEV + ) +) + +echo Build version: %BUILD_VERSION% +echo Build revision date: %BUILD_REV_DATE% +echo Build revision tag: %BUILD_REV_TAG% + +( +echo /* Autogenerated by src/archutils/Win32/gen-git-verinfo.bat */ +echo. +echo #define BUILD_VERSION "%BUILD_VERSION%" +echo #define BUILD_DATE "%BUILD_REV_DATE%" +echo #define BUILD_REVISION_TAG "%BUILD_REV_TAG%" +) > verinfo.h \ No newline at end of file -- 2.11.0