From 8bc7880b1912d777adf0d297b3b9cef8d2b5730c Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 26 Sep 2016 13:26:37 +0200 Subject: [PATCH] Improve gitrev handling. --- src/Makefile | 3 ++- src/conf.h | 1 + src/help.cpp | 18 +++++++++++++++--- src/main.cpp | 14 +++++++------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/Makefile b/src/Makefile index 9868a4bd..d4577c51 100644 --- a/src/Makefile +++ b/src/Makefile @@ -47,7 +47,7 @@ upx_SOURCES := $(sort $(wildcard $(srcdir)/*.cpp)) upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext))) ifneq ($(wildcard $(top_srcdir)/.git/.),) -UPX_VERSION_GITREV := $(strip $(shell cd '$(top_srcdir)' && git rev-parse --short=6 HEAD || echo 'ERROR')) +UPX_VERSION_GITREV := $(strip $(shell cd '$(top_srcdir)' && git rev-parse --short=12 HEAD || echo 'ERROR')) ifneq ($(UPX_VERSION_GITREV),) x := $(strip $(shell cd '$(top_srcdir)' && git diff --exit-code HEAD >/dev/null && echo '' || echo '+')) DEFS += '-DUPX_VERSION_GITREV="$(UPX_VERSION_GITREV)$(x)"' @@ -128,6 +128,7 @@ else ifeq ($(MAKECMDGOALS),maintainer-clean) else ifeq ($(MAKECMDGOALS),clang-format) else -include .depend +help$(objext): $(MAKEFILE_LIST) endif diff --git a/src/conf.h b/src/conf.h index 99ff7cc7..964648de 100644 --- a/src/conf.h +++ b/src/conf.h @@ -670,6 +670,7 @@ void do_files(int i, int argc, char *argv[]); // help.cpp +extern const char gitrev[]; void show_head(void); void show_help(int verbose=0); void show_license(void); diff --git a/src/help.cpp b/src/help.cpp index 743fbbf9..d4f2f2d8 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -38,6 +38,12 @@ static bool head_done = 0; +#if defined(UPX_VERSION_GITREV) +const char gitrev[] = UPX_VERSION_GITREV; +#else +const char gitrev[1] = { 0 }; +#endif + void show_head(void) { FILE *f = con_term; @@ -52,9 +58,15 @@ void show_head(void) con_fprintf(f, " Ultimate Packer for eXecutables\n" " Copyright (C) 1996 - " UPX_VERSION_YEAR "\n" - "UPX %-11s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n", #if defined(UPX_VERSION_GITREV) - "git-" UPX_VERSION_GITREV, + "UPX git-%6.6s%c" +#else + "UPX %-11s" +#endif + " Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n", +#if defined(UPX_VERSION_GITREV) + gitrev, + (sizeof(gitrev)-1 > 6 && gitrev[sizeof(gitrev)-2] == '+') ? '+' : ' ', #elif (ACC_OS_DOS16 || ACC_OS_DOS32) V("d"), #elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64) @@ -386,7 +398,7 @@ void show_version(int x) fprintf(fp, "upx %s\n", UPX_VERSION_STRING #if defined(UPX_VERSION_GITREV) - "-" UPX_VERSION_GITREV + "-git-" UPX_VERSION_GITREV #endif ); #if (WITH_NRV) diff --git a/src/main.cpp b/src/main.cpp index 82eca5f3..29aaf8cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1352,11 +1352,12 @@ __acc_static_noinline void upx_sanity_check(void) assert(strlen(UPX_VERSION_YEAR) == 4); assert(memcmp(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4) == 0); assert(memcmp(&UPX_VERSION_DATE[sizeof(UPX_VERSION_DATE)-1 - 4], UPX_VERSION_YEAR, 4) == 0); -#if defined(UPX_VERSION_GITREV) - COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_GITREV) <= 7 + 1) - assert(strlen(UPX_VERSION_GITREV) >= 5); - assert(strlen(UPX_VERSION_GITREV) <= 7); -#endif + if (gitrev[0]) { + size_t revlen = strlen(gitrev); + if (strncmp(gitrev, "ERROR", 5) == 0) { assert(revlen == 5 || revlen == 6); } + else { assert(revlen == 12 || revlen == 13); } + if (revlen == 6 || revlen == 13) { assert(gitrev[revlen-1] == '+'); } + } #if 1 assert(TestBELE::test()); @@ -1553,7 +1554,7 @@ int __acc_cdecl_main main(int argc, char *argv[]) set_term(stdout); do_files(i,argc,argv); -#if 1 && defined(UPX_VERSION_GITREV) + if (gitrev[0]) { FILE *f = stdout; int fg = con_fg(f,FG_RED); @@ -1561,7 +1562,6 @@ int __acc_cdecl_main main(int argc, char *argv[]) fg = con_fg(f,fg); UNUSED(fg); } -#endif #if 0 && defined(__GLIBC__) //malloc_stats();