forked from LostRuins/koboldcpp
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add git-based build information for better issue tracking (ggerganov#…
…1232) * Add git-based build information for better issue tracking * macOS fix * "build (hash)" and "CMAKE_SOURCE_DIR" changes * Redo "CMAKE_CURRENT_SOURCE_DIR" and clearer build messages * Fix conditional dependency on missing target * Broke out build-info.cmake, added find_package fallback, and added build into to all examples, added dependencies to Makefile * 4 space indenting for cmake, attempt to clean up my mess in Makefile * Short hash, less fancy Makefile, and don't modify build-info.h if it wouldn't change it
- Loading branch information
1 parent
58b367c
commit f4cef87
Showing
18 changed files
with
185 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ models/* | |
/vdot | ||
/Pipfile | ||
|
||
build-info.h | ||
arm_neon.h | ||
compile_commands.json | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
set(TEMPLATE_FILE "${CMAKE_BINARY_DIR}/BUILD_INFO.h.in") | ||
set(HEADER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h") | ||
set(BUILD_NUMBER 0) | ||
set(BUILD_COMMIT "unknown") | ||
|
||
# Look for git | ||
find_package(Git) | ||
if(NOT Git_FOUND) | ||
execute_process( | ||
COMMAND which git | ||
OUTPUT_VARIABLE GIT_EXECUTABLE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
if(NOT GIT_EXECUTABLE STREQUAL "") | ||
set(Git_FOUND TRUE) | ||
message(STATUS "Found Git using 'which': ${GIT_EXECUTABLE}") | ||
else() | ||
message(WARNING "Git not found using 'find_package' or 'which'. Build info will not be accurate. Consider installing Git or ensuring it is in the PATH.") | ||
endif() | ||
endif() | ||
|
||
# Get the commit count and hash | ||
if(Git_FOUND) | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE HEAD | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
RESULT_VARIABLE GIT_HEAD_RESULT | ||
) | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE COUNT | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
RESULT_VARIABLE GIT_COUNT_RESULT | ||
) | ||
if(GIT_HEAD_RESULT EQUAL 0 AND GIT_COUNT_RESULT EQUAL 0) | ||
set(BUILD_COMMIT ${HEAD}) | ||
set(BUILD_NUMBER ${COUNT}) | ||
endif() | ||
endif() | ||
|
||
# Only write the header if it's changed to prevent unnecessary recompilation | ||
if(EXISTS ${HEADER_FILE}) | ||
file(STRINGS ${HEADER_FILE} CONTENTS REGEX "BUILD_COMMIT \"([^\"]*)\"") | ||
list(GET CONTENTS 0 EXISTING) | ||
if(NOT EXISTING STREQUAL "#define BUILD_COMMIT \"${BUILD_COMMIT}\"") | ||
configure_file(${TEMPLATE_FILE} ${HEADER_FILE}) | ||
endif() | ||
else() | ||
configure_file(${TEMPLATE_FILE} ${HEADER_FILE}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
BUILD_NUMBER="0" | ||
BUILD_COMMIT="unknown" | ||
|
||
REV_LIST=$(git rev-list --count HEAD) | ||
if [ $? -eq 0 ]; then | ||
BUILD_NUMBER=$REV_LIST | ||
fi | ||
|
||
REV_PARSE=$(git rev-parse --short HEAD) | ||
if [ $? -eq 0 ]; then | ||
BUILD_COMMIT=$REV_PARSE | ||
fi | ||
|
||
echo "#ifndef BUILD_INFO_H" | ||
echo "#define BUILD_INFO_H" | ||
echo "" | ||
echo "#define BUILD_NUMBER $BUILD_NUMBER" | ||
echo "#define BUILD_COMMIT \"$BUILD_COMMIT\"" | ||
echo "" | ||
echo "#endif // BUILD_INFO_H" |