forked from ad-freiburg/qlever
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store and display git hash used to compile QLever (ad-freiburg#734)
Use CMake magic to let the QLever server and index builder know about the git hash of the compiled code. Show this git hash in the first line of the log when starting the server or the index builder. When building an index, store this git hash in the index metadata and display it when starting a server with that index.
- Loading branch information
Showing
8 changed files
with
92 additions
and
18 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
* | ||
!.clang-format | ||
!CMakeLists.txt | ||
!CompilationInfo.cmake | ||
!.git | ||
!LICENSE | ||
!README.md | ||
!e2e | ||
|
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,26 @@ | ||
# A small cmake script that writes the current git hash and time to a | ||
# .cpp file | ||
|
||
# Get the current time, remove the trailing newline and add quotes. | ||
execute_process(COMMAND date OUTPUT_VARIABLE DATETIME_OF_COMPILATION) | ||
string(REPLACE "\n" "" DATETIME_OF_COMPILATION "${DATETIME_OF_COMPILATION}") | ||
set(DATETIME_OF_COMPILATION "\"${DATETIME_OF_COMPILATION}\"") | ||
message(STATUS "DATETIME_OF_COMPILATION is ${DATETIME_OF_COMPILATION}" ) | ||
|
||
# Get the current git hash. | ||
execute_process(COMMAND git log -1 --format="%H" OUTPUT_VARIABLE GIT_HASH) | ||
if ((NOT DEFINED GIT_HASH) OR (GIT_HASH STREQUAL "")) | ||
set(GIT_HASH "\"QLever compilation not taking place in a git repository\"") | ||
endif() | ||
message(STATUS "GIT_HASH is ${GIT_HASH}") | ||
|
||
# Write the .cpp file. | ||
set(CONSTANTS "#include <string> | ||
namespace qlever::version { | ||
const char* GitHash = ${GIT_HASH}; | ||
const char* DatetimeOfCompilation = ${DATETIME_OF_COMPILATION}; | ||
}") | ||
|
||
# For some reason `CMAKE_CURRENT_SOURCE_DIR` inside this script is | ||
# `CMAKE_CURRENT_BINARY_DIR` in the main `CMakeLists.txt`. | ||
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/CompilationInfo.cpp "${CONSTANTS}") |
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,17 @@ | ||
// Copyright 2022, University of Freiburg, | ||
// Chair of Algorithms and Data Structures. | ||
// Author: Johannes Kalmbach<joka921> ([email protected]) | ||
|
||
// Several constants. The values of these constants reside in the | ||
// File `CompilationInfo.cpp` which is created and linked by CMake. | ||
|
||
#pragma once | ||
#include <string> | ||
namespace qlever::version { | ||
// The git hash of the commit that was used to QLever. | ||
extern const char* GitHash; | ||
// The date and time at which QLever was compiled. | ||
extern const char* DatetimeOfCompilation; | ||
|
||
inline std::string GitShortHash() { return std::string{GitHash}.substr(0, 6); } | ||
} // namespace qlever::version |
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 |
---|---|---|
@@ -1,10 +1,22 @@ | ||
// Copyright 2014, University of Freiburg, | ||
// Chair of Algorithms and Data Structures. | ||
// Author: Björn Buchhold ([email protected]) | ||
// Authors: | ||
// 2014-2017 Björn Buchhold ([email protected]) | ||
// 2018- Johannes Kalmbach ([email protected]) | ||
|
||
#include "./Index.h" | ||
|
||
#include <CompilationInfo.h> | ||
#include <absl/strings/str_join.h> | ||
#include <index/PrefixHeuristic.h> | ||
#include <index/TriplesView.h> | ||
#include <index/VocabularyGenerator.h> | ||
#include <parser/ParallelParseBuffer.h> | ||
#include <util/BatchedPipeline.h> | ||
#include <util/CompressionUsingZstd/ZstdWrapper.h> | ||
#include <util/HashMap.h> | ||
#include <util/Serializer/FileSerializer.h> | ||
#include <util/TupleHelpers.h> | ||
|
||
#include <algorithm> | ||
#include <cmath> | ||
|
@@ -15,17 +27,6 @@ | |
#include <stxxl/map> | ||
#include <unordered_map> | ||
|
||
#include "../parser/ParallelParseBuffer.h" | ||
#include "../util/BatchedPipeline.h" | ||
#include "../util/CompressionUsingZstd/ZstdWrapper.h" | ||
#include "../util/Conversions.h" | ||
#include "../util/HashMap.h" | ||
#include "../util/Serializer/FileSerializer.h" | ||
#include "../util/TupleHelpers.h" | ||
#include "./PrefixHeuristic.h" | ||
#include "./VocabularyGenerator.h" | ||
#include "TriplesView.h" | ||
|
||
using std::array; | ||
|
||
// _____________________________________________________________________________ | ||
|
@@ -852,14 +853,25 @@ void Index::setPrefixCompression(bool compressed) { | |
|
||
// ____________________________________________________________________________ | ||
void Index::writeConfiguration() const { | ||
// Copy the configuration and add the current commit hash. | ||
auto configuration = _configurationJson; | ||
configuration["git_hash"] = std::string(qlever::version::GitHash); | ||
auto f = ad_utility::makeOfstream(_onDiskBase + CONFIGURATION_FILE); | ||
f << _configurationJson; | ||
f << configuration; | ||
} | ||
|
||
// ___________________________________________________________________________ | ||
void Index::readConfiguration() { | ||
auto f = ad_utility::makeIfstream(_onDiskBase + CONFIGURATION_FILE); | ||
f >> _configurationJson; | ||
if (_configurationJson.find("git_hash") != _configurationJson.end()) { | ||
LOG(INFO) << "The git hash used to build this index was " | ||
<< _configurationJson["git_hash"] << std::endl; | ||
} else { | ||
LOG(INFO) << "The index was built before git commit hashes were stored in " | ||
"the index meta data" | ||
<< std::endl; | ||
} | ||
if (_configurationJson.find("external-literals") != | ||
_configurationJson.end()) { | ||
_onDiskLiterals = | ||
|
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