Skip to content

Commit 40ecec8

Browse files
authored
use git hash when possible and denote file hash with "file:" in version
* use git hash when possible and denote file hash with "file:" in version * fix '+' not being appended to hash when different from committed version * only care about git diff-index for same files as used for file hash * fix hash comparison * docker quiet * only hash/get modified time from files if not set by git commit * quiet makefile * show git diff-index * copy to docker * mount instead of copy * rename HASH_ENV to VERSION_HASH * cleanup dockerfile * don't use DCMAKE_QUIET_MAKEFILE=1 * remove extra messages * only show hashes if CMAKE_VERBOSE_MAKEFILE=1 * change to have CMAKE_VERBOSE_OPTIMIZATIONS to turn on -fopt-info-vec-all
1 parent f6a93ec commit 40ecec8

File tree

4 files changed

+64
-41
lines changed

4 files changed

+64
-41
lines changed

.docker/Dockerfile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ RUN vcpkg/vcpkg install
4747
# build and test
4848
FROM vcpkg-installed AS firestarr-build
4949
WORKDIR /appl/firestarr
50-
# vcpkg-installed should update when this file does
51-
# COPY ./vcpkg*.json .
5250
# mount instead of copy to minimize layers
5351
RUN --mount=type=bind,source=./cmake,target=./cmake \
5452
--mount=type=bind,source=./CMakeLists.txt,target=./CMakeLists.txt \
5553
--mount=type=bind,source=./CMakePresets.json,target=./CMakePresets.json \
5654
--mount=type=bind,source=./.clang-format,target=./.clang-format \
5755
--mount=type=bind,source=./.clang-tidy,target=./.clang-tidy \
5856
--mount=type=bind,source=./.env,target=./.env \
57+
--mount=type=bind,source=./.git,target=./.git \
5958
--mount=type=bind,source=./src/cpp,target=./src/cpp \
6059
--mount=type=bind,source=./test/data,target=./test/data \
6160
--mount=type=bind,source=./test/input,target=./test/input \
@@ -64,14 +63,6 @@ RUN --mount=type=bind,source=./cmake,target=./cmake \
6463
cmake --preset Release \
6564
&& cmake --build --parallel --preset Release \
6665
&& ctest --preset Release
67-
# COPY ./cmake cmake/
68-
# COPY ./.env ./CMake* ./.clang-* .
69-
# COPY ./src/cpp src/cpp/
70-
# RUN cmake --preset Release
71-
# RUN cmake --build --parallel --preset Release
72-
# COPY ./test test/
73-
# COPY ./fuel.lut ./settings.ini .
74-
# RUN ctest --preset Release
7566

7667
FROM --platform=linux/amd64 ${BASE_DISTROLESS} AS distroless-amd64
7768

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ if (WIN32)
7979
add_compile_options(
8080
"$<$<CONFIG:Debug>:/bigobj>")
8181
else()
82-
if(CMAKE_VERBOSE_MAKEFILE)
82+
if(CMAKE_VERBOSE_OPTIMIZATIONS)
8383
add_compile_options(-fopt-info-vec-all)
8484
endif()
8585
add_compile_options(

cmake/Version.cmake

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,59 @@ list(APPEND FILES_USED ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURREN
2626

2727
set(FILE_VERSION_CPP ${CMAKE_BINARY_DIR}/version.cpp)
2828

29-
# calculate hash from files that matter
30-
set(HASHES)
31-
# if modified from committed version then look at file timestamps
32-
foreach(file_path IN LISTS FILES_USED)
33-
file(SHA512 ${file_path} HASH_FILE)
34-
if(NOT CMAKE_QUIET_MAKEFILE)
35-
message("${file_path} ${HASH_FILE}")
29+
set(HASH_PREFIX "")
30+
set(HASH_SUFFIX "")
31+
set(MODIFIED_TIME "")
32+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
33+
if(EXISTS "${FILE_ENV}")
34+
# check when .env last changed - if not this commit then this is version+
35+
execute_process(COMMAND git log -n1 --pretty=%H ${FILE_ENV} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE VERSION_HASH)
3636
endif()
37-
list(APPEND HASHES ${HASH_FILE})
38-
file(TIMESTAMP "${file_path}" LAST_MOD_TIME "${FMT_TIME}")
39-
if ("${LAST_MOD_TIME}" STRGREATER "${MODIFIED_TIME}")
40-
if(NOT CMAKE_QUIET_MAKEFILE)
41-
message("Change in ${file_path}")
42-
endif()
43-
set(MODIFIED_TIME "${LAST_MOD_TIME}")
37+
execute_process(COMMAND git rev-parse --verify HEAD OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE FULL_HASH)
38+
message("VERSION_HASH = ${VERSION_HASH}")
39+
message("FULL_HASH = ${FULL_HASH}")
40+
if (NOT "${VERSION_HASH}" STREQUAL "${FULL_HASH}")
41+
# add + to version if .env isn't from current commit
42+
set(VERSION "${VERSION}+")
43+
endif()
44+
# is anything in git changed?
45+
list(JOIN FILES_USED " " FILES_USED_STRING)
46+
execute_process(COMMAND git diff-index HEAD -- ${FILES_USED_STRING} RESULT_VARIABLE GIT_CHANGED)
47+
message("GIT_CHANGED = ${GIT_CHANGED}")
48+
if ("${GIT_CHANGED}" STREQUAL "0")
49+
# use time from git commit since nothing is different
50+
execute_process(COMMAND git log -1 --pretty=%ad --date=format:%Y-%m-%dT%H:%M:%SZ OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE MODIFIED_TIME)
51+
else()
52+
set(HASH_SUFFIX "+")
4453
endif()
45-
endforeach()
46-
list(JOIN HASHES "" ALL_HASHES)
47-
string(SHA512 FULL_HASH ${ALL_HASHES})
54+
else()
55+
# will never have a '+' for HASH_SUFFIX because it's based on exact files
56+
set(HASH_PREFIX "file:")
57+
list(JOIN HASHES "" ALL_HASHES)
58+
string(SHA512 FULL_HASH ${ALL_HASHES})
59+
endif()
4860

49-
string(TIMESTAMP COMPILE_TIME "${FMT_TIME}" UTC)
61+
if(NOT MODIFIED_TIME)
62+
# calculate hash from files that matter
63+
set(HASHES)
64+
# if modified from committed version then look at file timestamps
65+
foreach(file_path IN LISTS FILES_USED)
66+
file(SHA512 ${file_path} HASH_FILE)
67+
if(CMAKE_VERBOSE_MAKEFILE)
68+
message("${file_path} ${HASH_FILE}")
69+
endif()
70+
list(APPEND HASHES ${HASH_FILE})
71+
file(TIMESTAMP "${file_path}" LAST_MOD_TIME "${FMT_TIME}")
72+
if ("${LAST_MOD_TIME}" STRGREATER "${MODIFIED_TIME}")
73+
set(MODIFIED_TIME "${LAST_MOD_TIME}")
74+
endif()
75+
endforeach()
76+
endif()
5077

51-
string(SUBSTRING ${FULL_HASH} 0 8 HASH)
78+
string(SUBSTRING ${FULL_HASH} 0 10 HASH)
79+
set(HASH "${HASH_PREFIX}${HASH}${HASH_SUFFIX}")
80+
set(FULL_HASH "${HASH_PREFIX}${FULL_HASH}${HASH_SUFFIX}")
81+
string(TIMESTAMP COMPILE_TIME "${FMT_TIME}" UTC)
5282

5383
set(COMPILED_ON "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM}-${CMAKE_CXX_COMPILER_ID}")
5484

src/cpp/firestarr.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,24 @@ int main(const int argc, const char* const argv[])
4444
printf("FireSTARR %s\n\n", SPECIFIC_REVISION);
4545
MainArgumentParser parser{argc, argv};
4646
parser.parse_args();
47-
// HACK: check here so verbosity can affect showing compile info
48-
if (parser.help_requested())
49-
{
50-
show_help_and_exit();
51-
}
5247
auto result = -1;
5348
#ifdef NDEBUG
5449
try
5550
{
5651
#endif
57-
fs::logging::check_fatal(
58-
!Log::openLogFile(parser.log_file.c_str()), "Can't open log file %s", parser.log_file.c_str()
59-
);
60-
fs::logging::note("Specific revision is %s", SPECIFIC_REVISION);
61-
fs::logging::debug("Full hash of all sources is: %s", FULL_HASH);
62-
fs::logging::debug("Compiled on: %s", COMPILED_ON);
52+
const auto opened_log = Log::openLogFile(parser.log_file.c_str());
53+
// HACK: check here so verbosity can affect showing compile info
54+
if (parser.help_requested())
55+
{
56+
fs::logging::note("Specific revision is %s", SPECIFIC_REVISION);
57+
fs::logging::debug("Full hash is: %s", FULL_HASH);
58+
fs::logging::debug("Compiled on: %s", COMPILED_ON);
59+
show_help_and_exit();
60+
}
61+
if (!opened_log)
62+
{
63+
logging::fatal("Can't open log file %s", parser.log_file.c_str());
64+
}
6365
fs::logging::note("Output directory is %s", parser.output_directory.c_str());
6466
fs::logging::note("Output log is %s", parser.log_file.c_str());
6567
// at this point we've parsed positional args and know we're not in test mode

0 commit comments

Comments
 (0)