From af8e7c38f8228b1f3784babba5be8ed40f1eba94 Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Sun, 24 Apr 2011 20:15:21 +0300 Subject: [PATCH] Change version info scripts to use git instead of SubWCRev svn utility --- .../packaging/winx86/make_header.cmd | 86 ++++++++++++++++++ .../{Makefile.cmd => make_installer.cmd} | 5 -- .../packaging/winx86/openpilotgcs.nsh | 6 +- .../packaging/winx86/openpilotgcs.nsi | 9 +- .../packaging/winx86/openpilotgcs.tpl | 12 --- .../openpilotgcs/packaging/winx86/svninfo.mk | 37 -------- .../openpilotgcs/packaging/winx86/svninfo.tpl | 37 -------- .../openpilotgcs/packaging/winx86/winx86.pro | 89 +++++++------------ 8 files changed, 124 insertions(+), 157 deletions(-) create mode 100644 ground/openpilotgcs/packaging/winx86/make_header.cmd rename ground/openpilotgcs/packaging/winx86/{Makefile.cmd => make_installer.cmd} (64%) delete mode 100644 ground/openpilotgcs/packaging/winx86/openpilotgcs.tpl delete mode 100644 ground/openpilotgcs/packaging/winx86/svninfo.mk delete mode 100644 ground/openpilotgcs/packaging/winx86/svninfo.tpl diff --git a/ground/openpilotgcs/packaging/winx86/make_header.cmd b/ground/openpilotgcs/packaging/winx86/make_header.cmd new file mode 100644 index 000000000..247b17af1 --- /dev/null +++ b/ground/openpilotgcs/packaging/winx86/make_header.cmd @@ -0,0 +1,86 @@ +@echo off +rem +rem make_header - a workaround to build NSIS version info header from +rem Makefile using different environments (Windows cmd or Unix-like sh) +rem still being more or less portable. +rem +rem This script tries to find any git command line utility on the system. +rem First, it looks at the predefined location of git.exe installed by +rem msysgit package available at http://code.google.com/p/msysgit/ +rem If not found, it searches for git executables in the system PATH. +rem If also not found, then it gives up and no commit info will be available. +rem +rem Expected parameters: +rem %1: repository source path +rem %2: header file full path and name +rem + +rem FIXME: we should have product version info somewhere else +set OUT_FILE=OpenPilotGCS-%%%%ad-%%%%h-install.exe +set PRODUCT_VERSION=0.0.0.0 +set FILE_VERSION=%%%%ad %%BRANCH%%:%%%%h +set BUILD_DESCRIPTION=Built using %%ORIGIN%% as origin, branch %%BRANCH%%, commit %%%%H, committed %%%%ci + +set REPO=%1 +set HEADER=%2 +if "%REPO%" == "" goto NoRepo +if "%HEADER%" == "" goto NoHeader +goto OK + +:NoRepo +:NoHeader +echo This script should be called from Makefile only +goto :eof + +:Ok +rem Looking for git command line utility at the predefined msysgit location +rem first, and in the PATH last. Also note that we use call command which is +rem required if we execute a .cmd or .bat file instead of .exe + +set GIT=%ProgramFiles%\Git\bin\git.exe +if exist "%GIT%" goto Found + +for %%G in (git.exe) do set GIT=%%~$PATH:G +if exist "%GIT%" goto Found + +for %%G in (git.cmd) do set GIT=%%~$PATH:G +if exist "%GIT%" goto Found + +for %%G in (git.bat) do set GIT=%%~$PATH:G +if exist "%GIT%" goto Found + +:NotFound +echo git not found, no version info available +goto :eof + +:Found +echo Using "%GIT%" to extract version info from "%REPO%"... + +rem Getting remote origin name +for /F "usebackq tokens=1-3" %%G in (`call "%GIT%" remote -v`) do ( + if "%%G" == "origin" if "%%I" == "(fetch)" set ORIGIN=%%H +) + +rem Getting branch name +for /F "usebackq tokens=1,2" %%G in (`call "%GIT%" branch --no-color`) do ( + if "%%G" == "*" set BRANCH=%%H +) + +rem Getting commit info +set OPTS=-1 --no-color --date=short +set OPTS=%OPTS% "--format=format: +set OPTS=%OPTS%;%%%%n +set OPTS=%OPTS%; AUTOGENERATED HEADER FILE%%%%n +set OPTS=%OPTS%;%%%%n +set OPTS=%OPTS%%%%%n +set OPTS=%OPTS%; Installer file name%%%%n +set OPTS=%OPTS%!define OUT_FILE \"%OUT_FILE%\"%%%%n +set OPTS=%OPTS%%%%%n +set OPTS=%OPTS%; Installer version info%%%%n +set OPTS=%OPTS%!define PRODUCT_VERSION \"%PRODUCT_VERSION%\"%%%%n +set OPTS=%OPTS%!define FILE_VERSION \"%FILE_VERSION%\"%%%%n +set OPTS=%OPTS%!define BUILD_DESCRIPTION \"%BUILD_DESCRIPTION%\"%%%%n" + +pushd "%REPO%" +call "%GIT%" log %OPTS% >%HEADER% +popd diff --git a/ground/openpilotgcs/packaging/winx86/Makefile.cmd b/ground/openpilotgcs/packaging/winx86/make_installer.cmd similarity index 64% rename from ground/openpilotgcs/packaging/winx86/Makefile.cmd rename to ground/openpilotgcs/packaging/winx86/make_installer.cmd index 5127caa79..a487d682e 100644 --- a/ground/openpilotgcs/packaging/winx86/Makefile.cmd +++ b/ground/openpilotgcs/packaging/winx86/make_installer.cmd @@ -1,16 +1,11 @@ @echo off rem -rem Project: OpenPilot rem NSIS installer script file for OpenPilot GCS rem The OpenPilot Team, http://www.openpilot.org, Copyright (C) 2010-2011. rem rem This script requires Unicode NSIS 2.46 or higher: rem http://www.scratchpaper.com/ rem -rem Optional SVN utility to get currently used SVN revision is SubWCRev.exe, -rem it is a part of TortoiseSVN package or is available separately: -rem http://sourceforge.net/projects/tortoisesvn/files/Tools/1.6.7/SubWCRev-1.6.7.18415.msi/download -rem rem Set path to NSIS compiler set NSIS=%ProgramFiles%/NSIS/Unicode diff --git a/ground/openpilotgcs/packaging/winx86/openpilotgcs.nsh b/ground/openpilotgcs/packaging/winx86/openpilotgcs.nsh index cc161bfac..222ed0d68 100644 --- a/ground/openpilotgcs/packaging/winx86/openpilotgcs.nsh +++ b/ground/openpilotgcs/packaging/winx86/openpilotgcs.nsh @@ -1,11 +1,11 @@ # -# SubWCRev not found, default values used instead. +# git not found, default values used instead. # ; Installer file name -!define OUT_FILE "OpenPilotGCS-XXXX-install.exe" +!define OUT_FILE "OpenPilotGCS-unreleased-install.exe" ; Installer version info !define PRODUCT_VERSION "0.0.0.0" !define FILE_VERSION "0.0.0.0" -!define BUILD_DESCRIPTION "Unknown revision." +!define BUILD_DESCRIPTION "Unreleased version." diff --git a/ground/openpilotgcs/packaging/winx86/openpilotgcs.nsi b/ground/openpilotgcs/packaging/winx86/openpilotgcs.nsi index bcd39f81f..5d36ab881 100644 --- a/ground/openpilotgcs/packaging/winx86/openpilotgcs.nsi +++ b/ground/openpilotgcs/packaging/winx86/openpilotgcs.nsi @@ -20,16 +20,9 @@ # This script requires Unicode NSIS 2.46 or higher: # http://www.scratchpaper.com/ -# -# Optionally used SubWCRev utility to extract SVN info from working copy. -# SubWCRev is a part of TortoiseSVN client distribution: -# http://tortoisesvn.net/ -# SubWCRev is also available separately: -# http://sourceforge.net/projects/tortoisesvn/files/Tools/1.6.7/SubWCRev-1.6.7.18415.msi/download # Features: # - Installs to the user local appdata path, no admin rights required. -# - Multilingual, needs translations for custom installer strings. # # TODO: # - optionally install for all users (to Program Files with admin rights on Vista/7). @@ -69,7 +62,7 @@ VIProductVersion ${PRODUCT_VERSION} VIAddVersionKey "ProductName" "${INSTALLER_NAME}" - VIAddVersionKey "FileVersion" ${FILE_VERSION} + VIAddVersionKey "FileVersion" "${FILE_VERSION}" VIAddVersionKey "Comments" "${INSTALLER_NAME}. ${BUILD_DESCRIPTION}" VIAddVersionKey "CompanyName" "The OpenPilot Team, http://www.openpilot.org" VIAddVersionKey "LegalTrademarks" "${PRODUCT_NAME} is a trademark of The OpenPilot Team" diff --git a/ground/openpilotgcs/packaging/winx86/openpilotgcs.tpl b/ground/openpilotgcs/packaging/winx86/openpilotgcs.tpl deleted file mode 100644 index 14c4383e4..000000000 --- a/ground/openpilotgcs/packaging/winx86/openpilotgcs.tpl +++ /dev/null @@ -1,12 +0,0 @@ -# -# SubWCRev autogenerated file, do not modify. -# Generated using nsis.tpl template. -# - -; Installer file name -!define OUT_FILE "OpenPilotGCS-$WCREV$-install.exe" - -; Installer version info -!define PRODUCT_VERSION "0.0.0.$WCREV$" -!define FILE_VERSION "0.0.0.$WCREV$" -!define BUILD_DESCRIPTION "Last committed revision $WCREV$ ($WCDATE$) using$WCMIXED? mixed:$ SVN revision range $WCRANGE$$WCMODS? (locally modified):$. Built from $WCURL$ ($WCNOW$)." diff --git a/ground/openpilotgcs/packaging/winx86/svninfo.mk b/ground/openpilotgcs/packaging/winx86/svninfo.mk deleted file mode 100644 index cec5b81e1..000000000 --- a/ground/openpilotgcs/packaging/winx86/svninfo.mk +++ /dev/null @@ -1,37 +0,0 @@ -# -# SubWCRev not found, default values used instead. -# Generated using svninfo.tpl template. -# - -# Highest committed revision number -WCREV = NA - -# Date of highest committed revision -WCDATE = NA - -# Mixed update revision state and revision range -WCMIXED = 0 -WCMIXED_TXT = NA -WCRANGE = NA - -# Repository URL of the working copy -WCURL = NA - -# Current system date & time -WCNOW = NA - -# Lock status, date, owner, and comment for this item -WCISLOCKED = 0 -WCLOCKDATE = NA -WCLOCKOWNER = NA -WCLOCKCOMMENT = NA - -# True if local modifications found -WCMODS = 0 -WCMODS_TXT = NA - -# True if the item is versioned -WCINSVN = 0 - -# True if the svn:needs-lock property is set -WCNEEDSLOCK = 0 diff --git a/ground/openpilotgcs/packaging/winx86/svninfo.tpl b/ground/openpilotgcs/packaging/winx86/svninfo.tpl deleted file mode 100644 index 86aecde32..000000000 --- a/ground/openpilotgcs/packaging/winx86/svninfo.tpl +++ /dev/null @@ -1,37 +0,0 @@ -# -# SubWCRev autogenerated file, do not modify. -# Generated using svninfo.tpl template. -# - -# Highest committed revision number -WCREV = $WCREV$ - -# Date of highest committed revision -WCDATE = $WCDATE=%Y/%m/%d %H:%M:%S$ - -# Mixed update revision state and revision range -WCMIXED = $WCMIXED?1:0$ -WCMIXED_TXT = $WCMIXED?(mixed):$ -WCRANGE = $WCRANGE$ - -# Repository URL of the working copy -WCURL = $WCURL$ - -# Current system date & time -WCNOW = $WCNOW=%Y/%m/%d %H:%M:%S$ - -# Lock status, date, owner, and comment for this item -WCISLOCKED = $WCISLOCKED?1:0$ -WCLOCKDATE = $WCLOCKDATE=%Y/%m/%d %H:%M:%S$ -WCLOCKOWNER = $WCLOCKOWNER$ -WCLOCKCOMMENT = $WCLOCKCOMMENT$ - -# True if local modifications found -WCMODS = $WCMODS?1:0$ -WCMODS_TXT = $WCMODS?(modified):$ - -# True if the item is versioned -WCINSVN = $WCINSVN?1:0$ - -# True if the svn:needs-lock property is set -WCNEEDSLOCK = $WCNEEDSLOCK?1:0$ diff --git a/ground/openpilotgcs/packaging/winx86/winx86.pro b/ground/openpilotgcs/packaging/winx86/winx86.pro index 001d36e3e..f1364166a 100644 --- a/ground/openpilotgcs/packaging/winx86/winx86.pro +++ b/ground/openpilotgcs/packaging/winx86/winx86.pro @@ -5,67 +5,46 @@ TEMPLATE = subdirs # Some Windows packaging magic (for release build only) equals(copydata, 1):win32:CONFIG(release, debug|release) { - WINX86_PATH = packaging/winx86 - SVN_INFO_TEMPLATE = svninfo.tpl - SVN_INFO_MAKEFILE = svninfo.mk - NSIS_TEMPLATE = openpilotgcs.tpl - NSIS_HEADER = openpilotgcs.nsh - - # Check for SubWCRev.exe executable required to get some useful SVN repository info. - # For example, currently checked out SVN revision (highest for the working copy). - # SubWCRev is a part of TortoiseSVN client distribution: - # http://tortoisesvn.net/ - # SubWCRev is also available separately: - # http://sourceforge.net/projects/tortoisesvn/files/Tools/1.6.7/SubWCRev-1.6.7.18415.msi/download - - # Default location is TortoiseSVN bin folder. - # FIXME: it should try to find in the PATH first, and use hardcoded reference last - SUBWCREV_EXE = $$targetPath(\"$$(ProgramFiles)/TortoiseSVN/bin/SubWCRev.exe\") - - exists($$SUBWCREV_EXE) { - message("SubWCRev found: $${SUBWCREV_EXE}") - svninfo.commands += @echo Copying stubs... $$addNewline() - svninfo.commands += $(COPY_FILE) - svninfo.commands += $$targetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$SVN_INFO_MAKEFILE) - svninfo.commands += $$targetPath($$GCS_BUILD_TREE/$$WINX86_PATH/$$SVN_INFO_MAKEFILE) - svninfo.commands += $$addNewline() - svninfo.commands += $(COPY_FILE) - svninfo.commands += $$targetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$NSIS_HEADER) - svninfo.commands += $$targetPath($$GCS_BUILD_TREE/$$WINX86_PATH/$$NSIS_HEADER) - svninfo.commands += $$addNewline() - svninfo.commands += @echo Executing $${SUBWCREV_EXE} $$SVN_INFO_TEMPLATE $$SVN_INFO_MAKEFILE $$addNewline() - svninfo.commands += -@$$SUBWCREV_EXE $$targetPath($$GCS_SOURCE_TREE) - svninfo.commands += $$targetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$SVN_INFO_TEMPLATE) - svninfo.commands += $$targetPath($$GCS_BUILD_TREE/$$WINX86_PATH/$$SVN_INFO_MAKEFILE) - svninfo.commands += $$addNewline() - svninfo.commands += @echo Executing $${SUBWCREV_EXE} $$NSIS_TEMPLATE $$NSIS_HEADER $$addNewline() - svninfo.commands += -@$$SUBWCREV_EXE $$targetPath($$GCS_SOURCE_TREE) - svninfo.commands += $$targetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$NSIS_TEMPLATE) - svninfo.commands += $$targetPath($$GCS_BUILD_TREE/$$WINX86_PATH/$$NSIS_HEADER) - svninfo.commands += $$addNewline() - } else { - message("SubWCRev not found, SVN info is not available") - svninfo.commands += $(COPY_FILE) - svninfo.commands += $$targetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$SVN_INFO_MAKEFILE) - svninfo.commands += $$targetPath($$GCS_BUILD_TREE/$$WINX86_PATH/$$SVN_INFO_MAKEFILE) - svninfo.commands += $$addNewline() - svninfo.commands += $(COPY_FILE) - svninfo.commands += $$targetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$NSIS_HEADER) - svninfo.commands += $$targetPath($$GCS_BUILD_TREE/$$WINX86_PATH/$$NSIS_HEADER) - svninfo.commands += $$addNewline() + # We need this Windows macro since building under Unix-like shell the top level + # targetPath macro will use forward slashes which don't work for such Windows + # commands like pushd, etc. But note that we still use targetPath for $(COPY_FILE) + # parameters because this command is different under native Windows and Unix-like + # build environments. + defineReplace(winTargetPath) { + return($$replace(1, /, \\)) } - svninfo.target = svninfo.dummy - QMAKE_EXTRA_TARGETS += svninfo - force.depends += svninfo + + # Some file locations + WINX86_PATH = packaging/winx86 + NSIS_HEADER = openpilotgcs.nsh + HEADER_MAKER = make_header.cmd + INSTALLER_MAKER = make_installer.cmd + + # copy defaults first (will be used if no git available) + git.commands += @echo Copying default version info... $$addNewline() + git.commands += $(COPY_FILE) + git.commands += $$targetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$NSIS_HEADER) + git.commands += $$targetPath($$GCS_BUILD_TREE/$$WINX86_PATH/$$NSIS_HEADER) + git.commands += $$addNewline() + + # extract repository info if command line git is available + git.commands += $$winTargetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$HEADER_MAKER) + git.commands += $$winTargetPath($$GCS_SOURCE_TREE) + git.commands += $$winTargetPath($$GCS_BUILD_TREE/$$WINX86_PATH/$$NSIS_HEADER) + git.commands += $$addNewline() + + git.target = git.dummy + QMAKE_EXTRA_TARGETS += git + force.depends += git # Redefine FORCE target to collect data every time force.target = FORCE QMAKE_EXTRA_TARGETS += force # Create installer build target - this WILL NOT run during build, run it by hand - message("Run \"make installer\" in $$GCS_BUILD_TREE/$$WINX86_PATH to build Windows installer (Unicode NSIS 2.46+ required)") - nsis.target = installer - nsis.depends = svninfo - nsis.commands += @$$targetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/Makefile.cmd) + message("Run \"make gcs_installer\" in $$GCS_BUILD_TREE/$$WINX86_PATH to build Windows installer (Unicode NSIS 2.46+ required)") + nsis.target = gcs_installer + nsis.depends = git + nsis.commands += @$$winTargetPath($$GCS_SOURCE_TREE/$$WINX86_PATH/$$INSTALLER_MAKER) QMAKE_EXTRA_TARGETS += nsis }