SCP: Add git commit time to commit id version information
This commit is contained in:
parent
4cbf4e4144
commit
c8ca4161fa
7 changed files with 52 additions and 14 deletions
|
@ -247,17 +247,27 @@ exit 1
|
|||
|
||||
:_GitHooks
|
||||
if not exist ..\.git goto _done_hooks
|
||||
if exist ..\.git\hooks\post-commit goto _done_hooks
|
||||
if not exist ..\.git\hooks\post-commit goto _initial_hooks
|
||||
fc /b ..\.git\hooks\post-commit git-hooks\post-commit >nul
|
||||
if %ERRORLEVEL% equ 0 goto _done_hooks
|
||||
echo *****************************************************
|
||||
echo *****************************************************
|
||||
echo ** Installing updated git hooks repository **
|
||||
echo *****************************************************
|
||||
echo *****************************************************
|
||||
goto _install_hooks
|
||||
:_initial_hooks
|
||||
echo *****************************************************
|
||||
echo *****************************************************
|
||||
echo ** Installing git hooks in newly cloned repository **
|
||||
echo *****************************************************
|
||||
echo *****************************************************
|
||||
:_install_hooks
|
||||
copy /y git-hooks\post* ..\.git\hooks\
|
||||
call :WhereInPath git.exe > NUL 2>&1
|
||||
if %ERRORLEVEL% neq 0 goto _done_hooks
|
||||
pushd ..
|
||||
git log -1 "--pretty=%%H" >.git-commit-id
|
||||
git log -1 --pretty="SIM_GIT_COMMIT_ID %H%nSIM_GIT_COMMIT_TIME %aI" >.git-commit-id
|
||||
popd
|
||||
:_done_hooks
|
||||
|
||||
|
@ -268,15 +278,18 @@ rem This race can happen at the beginning of a parallel build where
|
|||
rem several projects can start execution at almost the same time.
|
||||
rem
|
||||
SET GIT_COMMIT_ID=
|
||||
SET GIT_COMMIT_TIME=
|
||||
if not exist ..\.git-commit-id goto _NoId
|
||||
for /F %%i in (..\.git-commit-id) do SET GIT_COMMIT_ID=%%i
|
||||
for /F "usebackq tokens=2" %%i in (`findstr /C:SIM_GIT_COMMIT_ID ..\.git-commit-id`) do SET GIT_COMMIT_ID=%%i
|
||||
for /F "usebackq tokens=2" %%i in (`findstr /C:SIM_GIT_COMMIT_TIME ..\.git-commit-id`) do SET GIT_COMMIT_TIME=%%i
|
||||
:_NoId
|
||||
SET OLD_GIT_COMMIT_ID=
|
||||
if not exist .git-commit-id.h echo.>.git-commit-id.h
|
||||
for /F "tokens=3" %%i in (.git-commit-id.h) do SET OLD_GIT_COMMIT_ID=%%i
|
||||
for /F "usebackq tokens=3" %%i in (`findstr /C:SIM_GIT_COMMIT_ID ..\.git-commit-id`) do SET OLD_GIT_COMMIT_ID=%%i
|
||||
if "%GIT_COMMIT_ID%" equ "%OLD_GIT_COMMIT_ID%" goto _IdGood
|
||||
echo Generating updated .git-commit-id.h containing id %GIT_COMMIT_ID%
|
||||
echo #define SIM_GIT_COMMIT_ID %GIT_COMMIT_ID% >.git-commit-id.h
|
||||
echo #define SIM_GIT_COMMIT_TIME %GIT_COMMIT_TIME% >>.git-commit-id.h
|
||||
if errorlevel 1 echo Retrying...
|
||||
if errorlevel 1 goto _SetId
|
||||
:_IdGood
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
#
|
||||
# A hook script that is called after a successful
|
||||
# checkout to record the commit-id in the working directory.
|
||||
git log -1 --pretty="%H" >.git-commit-id
|
||||
git log -1 --pretty="SIM_GIT_COMMIT_ID %H%nSIM_GIT_COMMIT_TIME %aI" >.git-commit-id
|
||||
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
#
|
||||
# A hook script that is called after a successful
|
||||
# commit is made to record the commit-id in the working directory.
|
||||
git log -1 --pretty="%H" >.git-commit-id
|
||||
git log -1 --pretty="SIM_GIT_COMMIT_ID %H%nSIM_GIT_COMMIT_TIME %aI" >.git-commit-id
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
#
|
||||
# A hook script that is called after a successful merge
|
||||
# to record the commit-id in the working directory.
|
||||
git log -1 --pretty="%H" >.git-commit-id
|
||||
git log -1 --pretty="SIM_GIT_COMMIT_ID %H%nSIM_GIT_COMMIT_TIME %aI" >.git-commit-id
|
||||
|
||||
|
|
30
makefile
30
makefile
|
@ -195,7 +195,11 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin)
|
|||
endif
|
||||
endif
|
||||
ifeq (git-repo,$(shell if $(TEST) -d ./.git; then echo git-repo; fi))
|
||||
ifeq (need-hooks,$(shell if $(TEST) ! -e ./.git/hooks/post-checkout; then echo need-hooks; fi))
|
||||
NEED_HOOKS = $(shell if $(TEST) ! -e ./.git/hooks/post-checkout; then echo need-hooks; fi)
|
||||
ifeq (,$(NEED_HOOKS))
|
||||
NEED_HOOKS = $(shell if ! `diff ./.git/hooks/post-checkout ./Visual\ Studio\ Projects/git-hooks/post-checkout >/dev/null`; then echo need-hooks; fi)
|
||||
endif
|
||||
ifeq (need-hooks,$(NEED_HOOKS))
|
||||
$(info *** Installing git hooks in local repository ***)
|
||||
GIT_HOOKS += $(shell /bin/cp './Visual Studio Projects/git-hooks/post-commit' ./.git/hooks/)
|
||||
GIT_HOOKS += $(shell /bin/cp './Visual Studio Projects/git-hooks/post-checkout' ./.git/hooks/)
|
||||
|
@ -203,9 +207,14 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin)
|
|||
GIT_HOOKS += $(shell ./.git/hooks/post-checkout)
|
||||
ifneq (,$(strip $(GIT_HOOKS)))
|
||||
$(info *** Warning - Error installing git hooks *** $(GIT_HOOKS))
|
||||
endif
|
||||
else
|
||||
ifneq (commit-id-exists,$(shell if $(TEST) -e .git-commit-id; then echo commit-id-exists; fi))
|
||||
$(shell /bin/rm .git-commit-id)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifneq (commit-id-exists,$(shell if $(TEST) -e .git-commit-id; then echo commit-id-exists; fi))
|
||||
ifeq (,$(strip $(GIT_HOOKS)))
|
||||
GIT_HOOKS = $(shell ./.git/hooks/post-checkout)
|
||||
ifneq (,$(strip $(GIT_HOOKS)))
|
||||
$(info *** Warning - Error executing git hooks *** $(GIT_HOOKS))
|
||||
|
@ -828,15 +837,18 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin)
|
|||
MKDIRBIN = mkdir -p BIN
|
||||
endif
|
||||
ifeq (commit-id-exists,$(shell if $(TEST) -e .git-commit-id; then echo commit-id-exists; fi))
|
||||
GIT_COMMIT_ID=$(shell cat .git-commit-id)
|
||||
GIT_COMMIT_ID=$(shell grep 'SIM_GIT_COMMIT_ID' .git-commit-id | awk '{ print $$2 }')
|
||||
GIT_COMMIT_TIME=$(shell grep 'SIM_GIT_COMMIT_TIME' .git-commit-id | awk '{ print $$2 }')
|
||||
else
|
||||
ifeq (,$(shell grep 'define SIM_GIT_COMMIT_ID' sim_rev.h | grep 'Format:'))
|
||||
GIT_COMMIT_ID=$(shell grep 'define SIM_GIT_COMMIT_ID' sim_rev.h | awk '{ print $$3 }')
|
||||
GIT_COMMIT_TIME=$(shell grep 'define SIM_GIT_COMMIT_TIME' sim_rev.h | awk '{ print $$3 }')
|
||||
else
|
||||
ifeq (git-submodule,$(if $(shell cd .. ; git rev-parse --git-dir 2>/dev/null),git-submodule))
|
||||
GIT_COMMIT_ID=$(shell cd .. ; git submodule status | grep "$(notdir $(realpath .))" | awk '{ print $$1 }')
|
||||
else
|
||||
GIT_COMMIT_ID=undetermined-git-id
|
||||
GIT_COMMIT_TIME=undetermined-commit-time
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
@ -921,11 +933,13 @@ else
|
|||
ifneq ($(USE_NETWORK),)
|
||||
NETWORK_OPT += -DUSE_SHARED
|
||||
endif
|
||||
ifneq (,$(shell if exist .git-commit-id type .git-commit-id))
|
||||
GIT_COMMIT_ID=$(shell if exist .git-commit-id type .git-commit-id)
|
||||
ifneq (,$(shell if exist .git-commit-id echo git-commit-id))
|
||||
GIT_COMMIT_ID=$(shell for /F "tokens=2" %%i in ("$(shell findstr /C:"SIM_GIT_COMMIT_ID" .git-commit-id)") do echo %%i)
|
||||
GIT_COMMIT_TIME=$(shell for /F "tokens=2" %%i in ("$(shell findstr /C:"SIM_GIT_COMMIT_TIME" .git-commit-id)") do echo %%i)
|
||||
else
|
||||
ifeq (,$(shell findstr /C:"define SIM_GIT_COMMIT_ID" sim_rev.h | findstr Format))
|
||||
GIT_COMMIT_ID=$(shell for /F "tokens=3" %%i in ("$(shell findstr /C:"define SIM_GIT_COMMIT_ID" sim_rev.h)") do echo %%i)
|
||||
GIT_COMMIT_TIME=$(shell for /F "tokens=3" %%i in ("$(shell findstr /C:"define SIM_GIT_COMMIT_TIME" sim_rev.h)") do echo %%i)
|
||||
endif
|
||||
endif
|
||||
ifneq (windows-build,$(shell if exist ..\windows-build\README.md echo windows-build))
|
||||
|
@ -978,7 +992,10 @@ else
|
|||
endif
|
||||
endif # Win32 (via MinGW)
|
||||
ifneq (,$(GIT_COMMIT_ID))
|
||||
CFLAGS_GIT = -DSIM_GIT_COMMIT_ID=$(GIT_COMMIT_ID)
|
||||
CFLAGS_GIT = -DSIM_GIT_COMMIT_ID=$(GIT_COMMIT_ID) -DSIM_GIT_COMMIT_TIME=$(GIT_COMMIT_TIME)
|
||||
endif
|
||||
ifneq (,$(GIT_COMMIT_TIME))
|
||||
CFLAGS_GIT += -DSIM_GIT_COMMIT_TIME=$(GIT_COMMIT_TIME)
|
||||
endif
|
||||
ifneq (,$(UNSUPPORTED_BUILD))
|
||||
CFLAGS_GIT += -DSIM_BUILD=Unsupported=$(UNSUPPORTED_BUILD)
|
||||
|
@ -1063,6 +1080,7 @@ ifneq (clean,$(MAKECMDGOALS))
|
|||
ifneq (,$(GIT_COMMIT_ID))
|
||||
$(info ***)
|
||||
$(info *** git commit id is $(GIT_COMMIT_ID).)
|
||||
$(info *** git commit time is $(GIT_COMMIT_TIME).)
|
||||
endif
|
||||
$(info ***)
|
||||
endif
|
||||
|
|
4
scp.c
4
scp.c
|
@ -5215,6 +5215,10 @@ if (flag) {
|
|||
#define S_xstr(a) S_str(a)
|
||||
#define S_str(a) #a
|
||||
fprintf (st, "%sgit commit id: %8.8s", flag ? "\n " : " ", S_xstr(SIM_GIT_COMMIT_ID));
|
||||
#if defined(SIM_GIT_COMMIT_TIME)
|
||||
if (flag)
|
||||
fprintf (st, "%sgit commit time: %s", "\n ", S_xstr(SIM_GIT_COMMIT_TIME));
|
||||
#endif
|
||||
#undef S_str
|
||||
#undef S_xstr
|
||||
#endif
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
|
||||
#if !defined(SIM_GIT_COMMIT_ID)
|
||||
#define SIM_GIT_COMMIT_ID $Format:%H$
|
||||
#define SIM_GIT_COMMIT_TIME $Format:%aI$
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue