Add return build type command (#894)

This commit is contained in:
gvolfing 2023-05-16 16:02:03 +02:00 committed by GitHub
parent c3e4f81026
commit 7ddce539fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 76 additions and 4 deletions

View File

@ -231,6 +231,8 @@ endif()
message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
# -----------------------------------------------------------------------------
add_definitions( -DCMAKE_BUILD_TYPE_NAME="${CMAKE_BUILD_TYPE}")
if (NOT MG_ARCH)
set(MG_ARCH_DESCR "Host architecture to build Memgraph on. Supported values are x86_64, ARM64.")
if (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64")

View File

@ -2786,7 +2786,7 @@ class InfoQuery : public memgraph::query::Query {
static const utils::TypeInfo kType;
const utils::TypeInfo &GetTypeInfo() const override { return kType; }
enum class InfoType { STORAGE, INDEX, CONSTRAINT };
enum class InfoType { STORAGE, INDEX, CONSTRAINT, BUILD };
DEFVISITABLE(QueryVisitor<void>);

View File

@ -124,6 +124,9 @@ antlrcpp::Any CypherMainVisitor::visitInfoQuery(MemgraphCypher::InfoQueryContext
} else if (ctx->constraintInfo()) {
info_query->info_type_ = InfoQuery::InfoType::CONSTRAINT;
return info_query;
} else if (ctx->buildInfo()) {
info_query->info_type_ = InfoQuery::InfoType::BUILD;
return info_query;
} else {
throw utils::NotYetImplemented("Info query: '{}'", ctx->getText());
}

View File

@ -46,7 +46,9 @@ indexInfo : INDEX INFO ;
constraintInfo : CONSTRAINT INFO ;
infoQuery : SHOW ( storageInfo | indexInfo | constraintInfo ) ;
buildInfo : BUILD INFO ;
infoQuery : SHOW ( storageInfo | indexInfo | constraintInfo | buildInfo) ;
explainQuery : EXPLAIN cypherQuery ;

View File

@ -31,6 +31,7 @@ memgraphCypherKeyword : cypherKeyword
| BATCH_SIZE
| BEFORE
| BOOTSTRAP_SERVERS
| BUILD
| CHECK
| CLEAR
| COMMIT

View File

@ -35,6 +35,7 @@ BATCH_INTERVAL : B A T C H UNDERSCORE I N T E R V A L ;
BATCH_LIMIT : B A T C H UNDERSCORE L I M I T ;
BATCH_SIZE : B A T C H UNDERSCORE S I Z E ;
BEFORE : B E F O R E ;
BUILD : B U I L D ;
BOOTSTRAP_SERVERS : B O O T S T R A P UNDERSCORE S E R V E R S ;
CALL : C A L L ;
CHECK : C H E C K ;

View File

@ -43,6 +43,7 @@ class PrivilegeExtractor : public QueryVisitor<void>, public HierarchicalTreeVis
AddPrivilege(AuthQuery::Privilege::INDEX);
break;
case InfoQuery::InfoType::STORAGE:
case InfoQuery::InfoType::BUILD:
AddPrivilege(AuthQuery::Privilege::STATS);
break;
case InfoQuery::InfoType::CONSTRAINT:

View File

@ -211,7 +211,8 @@ const trie::Trie kKeywords = {"union",
"edge_types",
"off",
"in_memory_transactional",
"in_memory_analytical"};
"in_memory_analytical",
"build"};
// Unicode codepoints that are allowed at the start of the unescaped name.
const std::bitset<kBitsetSize> kUnescapedNameAllowedStarts(

View File

@ -57,6 +57,7 @@
#include "storage/v2/property_value.hpp"
#include "storage/v2/storage_mode.hpp"
#include "utils/algorithm.hpp"
#include "utils/build_info.hpp"
#include "utils/csv_parsing.hpp"
#include "utils/event_counter.hpp"
#include "utils/exceptions.hpp"
@ -2394,6 +2395,15 @@ PreparedQuery PrepareInfoQuery(ParsedQuery parsed_query, bool in_explicit_transa
return std::pair{results, QueryHandlerResult::NOTHING};
};
break;
case InfoQuery::InfoType::BUILD:
header = {"build info", "value"};
handler = [] {
std::vector<std::vector<TypedValue>> results{
{TypedValue("build_type"), TypedValue(utils::GetBuildInfo().build_name)}};
return std::pair{results, QueryHandlerResult::NOTHING};
};
break;
}
return PreparedQuery{std::move(header), std::move(parsed_query.required_privileges),

View File

@ -15,7 +15,8 @@ set(utils_src_files
thread_pool.cpp
tsc.cpp
system_info.cpp
uuid.cpp)
uuid.cpp
build_info.cpp)
find_package(Boost REQUIRED)
find_package(fmt REQUIRED)

26
src/utils/build_info.cpp Normal file
View File

@ -0,0 +1,26 @@
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
#include "build_info.hpp"
namespace memgraph::utils {
BuildInfo GetBuildInfo() {
#ifdef CMAKE_BUILD_TYPE_NAME
constexpr const char *build_info_name = CMAKE_BUILD_TYPE_NAME;
#else
constexpr const char *build_info_name = "unkown";
#endif
BuildInfo info{build_info_name};
return info;
}
} // namespace memgraph::utils

24
src/utils/build_info.hpp Normal file
View File

@ -0,0 +1,24 @@
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
#pragma once
#include <string>
namespace memgraph::utils {
struct BuildInfo {
std::string build_name;
};
BuildInfo GetBuildInfo();
} // namespace memgraph::utils