From a9fb4a653ee2444859fbd78a67da9c62c9b0dc0e Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Wed, 25 Jan 2023 10:14:15 -1000 Subject: [PATCH] makefile: Properly report archive git commit info when building from an archive --- makefile | 12 +++++++----- scp.c | 25 +++++++++++++------------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/makefile b/makefile index 6c80d4f5..84fa242b 100644 --- a/makefile +++ b/makefile @@ -413,6 +413,7 @@ ifeq (${WIN32},) #*nix Environments (&& cygwin) endif endif ifeq (git-repo,$(shell if ${TEST} -e ./.git; then echo git-repo; fi)) + GIT_REPO=1 GIT_PATH=$(strip $(shell which git)) ifeq (,$(GIT_PATH)) $(error building using a git repository, but git is not available) @@ -427,8 +428,9 @@ ifeq (${WIN32},) #*nix Environments (&& cygwin) $(error building using a got repository, but git repository is not available) endif REPO_PATH=-C $(file <.got/repository) + GIT_REPO=1 endif - ifneq (,GIT_PATH) + ifneq (,$(and $(GIT_REPO),$(GIT_PATH))) ifeq (commit-id-exists,$(shell if ${TEST} -e .git-commit-id; then echo commit-id-exists; fi)) CURRENT_FULL_GIT_COMMIT_ID=$(strip $(shell grep 'SIM_GIT_COMMIT_ID' .git-commit-id | awk '{ print $$2 }')) CURRENT_GIT_COMMIT_ID=$(word 1,$(subst +, , $(CURRENT_FULL_GIT_COMMIT_ID))) @@ -1070,10 +1072,10 @@ ifeq (${WIN32},) #*nix Environments (&& cygwin) 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 (,$(shell grep 'define SIM_ARCHIVE_GIT_COMMIT_ID' sim_rev.h | grep 'Format:')) + GIT_COMMIT_ID=$(shell grep 'define SIM_ARCHIVE_GIT_COMMIT_ID' sim_rev.h | awk '{ print $$3 }') + GIT_COMMIT_TIME=$(shell grep 'define SIM_ARCHIVE_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 }') GIT_COMMIT_TIME=$(shell git $(REPO_PATH) --git-dir=$(realpath .)/.git log $(GIT_COMMIT_ID) -1 --pretty="%aI") diff --git a/scp.c b/scp.c index 19be42e5..62769a13 100644 --- a/scp.c +++ b/scp.c @@ -7108,6 +7108,19 @@ if (flag) { strlcpy (os_type, getenv ("OSTYPE"), sizeof (os_type)); setenv ("SIM_OSTYPE", os_type, 1); } +#if defined(SIM_GIT_COMMIT_ID) +if (1) { + const char *extras = strchr (S_xstr(SIM_GIT_COMMIT_ID), '+'); + + fprintf (st, "%sgit commit id: %8.8s%s", flag ? "\n " : " ", S_xstr(SIM_GIT_COMMIT_ID), extras ? extras : ""); + setenv ("SIM_GIT_COMMIT_ID", S_xstr(SIM_GIT_COMMIT_ID), 1); + } +#if defined(SIM_GIT_COMMIT_TIME) +setenv ("SIM_GIT_COMMIT_TIME", S_xstr(SIM_GIT_COMMIT_TIME), 1); +if (flag) + fprintf (st, "%sgit commit time: %s", "\n ", S_xstr(SIM_GIT_COMMIT_TIME)); +#endif +#else #if defined(SIM_ARCHIVE_GIT_COMMIT_ID) if (NULL == strchr (S_xstr(SIM_ARCHIVE_GIT_COMMIT_ID), '$')) { const char *extras = strchr (S_xstr(SIM_ARCHIVE_GIT_COMMIT_ID), '+'); @@ -7123,18 +7136,6 @@ if (NULL == strchr (S_xstr(SIM_ARCHIVE_GIT_COMMIT_TIME), '$')) { } #endif #endif -#if defined(SIM_GIT_COMMIT_ID) -if (1) { - const char *extras = strchr (S_xstr(SIM_GIT_COMMIT_ID), '+'); - - fprintf (st, "%sgit commit id: %8.8s%s", flag ? "\n " : " ", S_xstr(SIM_GIT_COMMIT_ID), extras ? extras : ""); - setenv ("SIM_GIT_COMMIT_ID", S_xstr(SIM_GIT_COMMIT_ID), 1); - } -#if defined(SIM_GIT_COMMIT_TIME) -setenv ("SIM_GIT_COMMIT_TIME", S_xstr(SIM_GIT_COMMIT_TIME), 1); -if (flag) - fprintf (st, "%sgit commit time: %s", "\n ", S_xstr(SIM_GIT_COMMIT_TIME)); -#endif #endif #if defined(SIM_BUILD) fprintf (st, "%sBuild: %s", flag ? "\n " : " ", S_xstr(SIM_BUILD));