diff --git a/Visual Studio Projects/Pre-Build-Event.cmd b/Visual Studio Projects/Pre-Build-Event.cmd index ff1d069b..143f17cf 100644 --- a/Visual Studio Projects/Pre-Build-Event.cmd +++ b/Visual Studio Projects/Pre-Build-Event.cmd @@ -21,15 +21,8 @@ rem files are available in the directory ..\..\windows-build\ rem rem In addition to the optional activities mentioned above, other activities rem are also performed. These include: -rem - confirming that if the current source is a clone of the simh -rem git repository, then assuring that git hooks which manage making -rem the git commit hash available during builds are properly installed -rem in the repository hooks directory. When the githooks are installed -rem the current commit id is generated if git.exe is available in the -rem current path. If it isn't, then report that fact and suggest how -rem to make sure that it is. -rem - performing the activities which make the git repository commit id -rem available in an include file during compiles. +rem - performing the activities which make confirm or generate the git +rem repository commit id available in an include file during compiles. rem rem @@ -204,10 +197,10 @@ echo error: Review the Output Tab for more details. exit 1 :_done_build -:_GitHooks -if not exist ..\.git goto _done_hooks +:_CheckGit +if not exist ..\.git goto _done_id call :FindGit _GIT_GIT -if "%_GIT_GIT%" neq "" goto _check_hooks +if "%_GIT_GIT%" neq "" goto _SetId echo ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR ** echo ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR ** echo ** ** @@ -231,29 +224,7 @@ echo ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR ** echo ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR ** echo error: Review the Output Tab for more details. exit 1 -:_check_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 in 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\ -:_do_hooks -pushd .. -"%_GIT_GIT%" log -1 --pretty="SIM_GIT_COMMIT_ID %%H%%nSIM_GIT_COMMIT_TIME %%aI" >.git-commit-id -popd -:_done_hooks +:_done_git :_SetId rem @@ -261,25 +232,23 @@ rem A race condition exists while creating the .git-commit-id.h file. 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 ACTUAL_GIT_COMMIT_ID= +SET ACTUAL_GIT_COMMIT_TIME= SET GIT_COMMIT_ID= SET GIT_COMMIT_TIME= -if not exist ..\.git-commit-id goto _do_hooks -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 -rem -rem Some 'git' environments don't honor the installed hooks (Visual -rem Studio 2015 for example), and in this case the initially generated -rem .git-commit-id file won't get updated. We can't be sure of this -rem detail, so perform a manual check now. SET _GIT_COMMIT_ID_TEMP=.git-commit-id-temp-%RANDOM% "%_GIT_GIT%" log -1 --pretty="SIM_GIT_COMMIT_ID %%H%%nSIM_GIT_COMMIT_TIME %%aI" >%_GIT_COMMIT_ID_TEMP% -for /F "usebackq tokens=2" %%i in (`findstr /C:SIM_GIT_COMMIT_ID %_GIT_COMMIT_ID_TEMP%`) do SET CURRENT_GIT_COMMIT_ID=%%i -for /F "usebackq tokens=2" %%i in (`findstr /C:SIM_GIT_COMMIT_TIME %_GIT_COMMIT_ID_TEMP%`) do SET CURRENT_GIT_COMMIT_TIME=%%i -if "%CURRENT_GIT_COMMIT_ID%" neq "%GIT_COMMIT_ID%" move /Y %_GIT_COMMIT_ID_TEMP% ..\.git-commit-id -if "%CURRENT_GIT_COMMIT_ID%" equ "%GIT_COMMIT_ID%" del %_GIT_COMMIT_ID_TEMP% +for /F "usebackq tokens=2" %%i in (`findstr /C:SIM_GIT_COMMIT_ID %_GIT_COMMIT_ID_TEMP%`) do SET ACTUAL_GIT_COMMIT_ID=%%i +for /F "usebackq tokens=2" %%i in (`findstr /C:SIM_GIT_COMMIT_TIME %_GIT_COMMIT_ID_TEMP%`) do SET ACTUAL_GIT_COMMIT_TIME=%%i +if exist ..\.git-commit-id for /F "usebackq tokens=2" %%i in (`findstr /C:SIM_GIT_COMMIT_ID ..\.git-commit-id`) do SET GIT_COMMIT_ID=%%i +if exist ..\.git-commit-id for /F "usebackq tokens=2" %%i in (`findstr /C:SIM_GIT_COMMIT_TIME ..\.git-commit-id`) do SET GIT_COMMIT_TIME=%%i +if "%ACTUAL_GIT_COMMIT_ID%" neq "%GIT_COMMIT_ID%" move /Y %_GIT_COMMIT_ID_TEMP% ..\.git-commit-id +if "%ACTUAL_GIT_COMMIT_ID%" equ "%GIT_COMMIT_ID%" del %_GIT_COMMIT_ID_TEMP% +SET GIT_COMMIT_ID=%ACTUAL_GIT_COMMIT_ID% +SET SIM_GIT_COMMIT_TIME=%ACTUAL_SIM_GIT_COMMIT_TIME% SET _GIT_COMMIT_ID_TEMP= -SET CURRENT_GIT_COMMIT_ID= -SET CURRENT_GIT_COMMIT_TIME= +SET ACTUAL_GIT_COMMIT_ID= +SET ACTUAL_GIT_COMMIT_TIME= :_VerifyGitCommitId.h SET OLD_GIT_COMMIT_ID= if not exist .git-commit-id.h echo.>.git-commit-id.h @@ -292,8 +261,10 @@ if errorlevel 1 echo Retrying... if errorlevel 1 goto _SetId :_IdGood :_done_id +if not exist .git-commit-id.h echo. >.git-commit-id.h goto :EOF + :WhereInPath if "%~$PATH:1" NEQ "" exit /B 0 exit /B 1 diff --git a/Visual Studio Projects/git-hooks/0ReadMe_git-hooks.txt b/Visual Studio Projects/git-hooks/0ReadMe_git-hooks.txt deleted file mode 100644 index 3240f0e2..00000000 --- a/Visual Studio Projects/git-hooks/0ReadMe_git-hooks.txt +++ /dev/null @@ -1,23 +0,0 @@ -This dirctory contains a set of git hook scripts which are useful when -working with this repository to make the git commit id available when -building simulators to uniquely identify the inputs to that build. - -It is ONLY useful for folks who clone this as a repository and build -in the working directory of that repository. - -Folks who download zip or tarball archives of the repository have the -git commit-id automatically inserted into the sim_rev.h file when the -archive is created due to a substitution performed via this repository's -.gitattributes. - -To use these scripts automatically, copy these files to the .git/hooks -directory of the current repository. This can be done with the -following commands: - - $ cd Visual\ Studio\ Projects/git-hooks - $ chmod +x post* - $ cp post* ../../.git/hooks/ - -Note: The makefile AND the Visual Studio Projects automatically - will install these git hooks in the ../../.git/hooks/ directory - if they're not already there and execute them as needed. diff --git a/Visual Studio Projects/git-hooks/post-checkout b/Visual Studio Projects/git-hooks/post-checkout deleted file mode 100755 index 6b0fdb62..00000000 --- a/Visual Studio Projects/git-hooks/post-checkout +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -# -# A hook script that is called after a successful -# checkout to record the commit-id in the working directory. -isodate=$(git log -1 --pretty="%ai"|sed -e 's/ /T/'|sed -e 's/ //') -git log -1 --pretty="SIM_GIT_COMMIT_ID %H%nSIM_GIT_COMMIT_TIME $isodate" >.git-commit-id - diff --git a/Visual Studio Projects/git-hooks/post-commit b/Visual Studio Projects/git-hooks/post-commit deleted file mode 100755 index b3ee1268..00000000 --- a/Visual Studio Projects/git-hooks/post-commit +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# -# A hook script that is called after a successful -# commit is made to record the commit-id in the working directory. -isodate=$(git log -1 --pretty="%ai"|sed -e 's/ /T/'|sed -e 's/ //') -git log -1 --pretty="SIM_GIT_COMMIT_ID %H%nSIM_GIT_COMMIT_TIME $isodate" >.git-commit-id diff --git a/Visual Studio Projects/git-hooks/post-merge b/Visual Studio Projects/git-hooks/post-merge deleted file mode 100755 index 3a383810..00000000 --- a/Visual Studio Projects/git-hooks/post-merge +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -# -# A hook script that is called after a successful merge -# to record the commit-id in the working directory. -isodate=$(git log -1 --pretty="%ai"|sed -e 's/ /T/'|sed -e 's/ //') -git log -1 --pretty="SIM_GIT_COMMIT_ID %H%nSIM_GIT_COMMIT_TIME $isodate" >.git-commit-id - diff --git a/makefile b/makefile index 99000565..1e4fa582 100644 --- a/makefile +++ b/makefile @@ -128,7 +128,7 @@ ifneq ($(findstring Windows,$(OS)),) else # Msys or cygwin ifeq (MINGW,$(findstring MINGW,$(shell uname))) $(info *** This makefile can not be used with the Msys bash shell) - $(error *** Use build_mingw.bat $(MAKECMDGOALS) from a Windows command prompt) + $(error Use build_mingw.bat $(MAKECMDGOALS) from a Windows command prompt) endif endif endif @@ -197,31 +197,22 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin) endif endif ifeq (git-repo,$(shell if $(TEST) -d ./.git; then echo git-repo; 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) + GIT_PATH=$(strip $(shell which git)) + ifeq (,$(GIT_PATH)) + $(error building using a git repository, but git is not available) endif - ifeq (need-hooks,$(NEED_HOOKS)) - $(info *** Installing git hooks in local repository ***) - GIT_HOOKS += $(shell cp './Visual Studio Projects/git-hooks/post-commit' ./.git/hooks/) - GIT_HOOKS += $(shell cp './Visual Studio Projects/git-hooks/post-checkout' ./.git/hooks/) - GIT_HOOKS += $(shell cp './Visual Studio Projects/git-hooks/post-merge' ./.git/hooks/) - GIT_HOOKS += $(shell ./.git/hooks/post-checkout) - ifneq (,$(strip $(GIT_HOOKS))) - $(info *** Warning - Error installing git hooks *** $(GIT_HOOKS)) - else - ifneq (commit-id-exists,$(shell if $(TEST) -e .git-commit-id; then echo commit-id-exists; fi)) - $(shell rm .git-commit-id) - endif + ifeq (commit-id-exists,$(shell if $(TEST) -e .git-commit-id; then echo commit-id-exists; fi)) + CURRENT_GIT_COMMIT_ID=$(strip $(shell grep 'SIM_GIT_COMMIT_ID' .git-commit-id | awk '{ print $$2 }')) + ACTUAL_GIT_COMMIT_ID=$(strip $(shell git log -1 --pretty="%H")) + ifneq ($(CURRENT_GIT_COMMIT_ID),$(ACTUAL_GIT_COMMIT_ID)) + NEED_COMMIT_ID = need-commit-id endif + else + NEED_COMMIT_ID = need-commit-id 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)) - endif - endif + ifeq (need-commit-id,$(NEED_COMMIT_ID)) + $isodate=$(shell git log -1 --pretty="%ai"|sed -e 's/ /T/'|sed -e 's/ //') + $(shell git log -1 --pretty="SIM_GIT_COMMIT_ID %H%nSIM_GIT_COMMIT_TIME $isodate" >.git-commit-id) endif endif LTO_EXCLUDE_VERSIONS =