copy hardcoded queries
Summary: copy hardcoded queries Reviewers: dgleich, mislav.bradac, florijan, mferencevic Reviewed By: dgleich Subscribers: buda Differential Revision: https://phabricator.memgraph.io/D74
This commit is contained in:
parent
1946ab6e07
commit
a32b2831e5
@ -390,15 +390,26 @@ if (MEMGRAPH)
|
||||
target_link_libraries(${MEMGRAPH_BUILD_NAME} memgraph_lib)
|
||||
target_link_libraries(${MEMGRAPH_BUILD_NAME} stdc++fs)
|
||||
target_link_libraries(${MEMGRAPH_BUILD_NAME} Threads::Threads)
|
||||
# target_link_libraries(${MEMGRAPH_BUILD_NAME} crypto)
|
||||
# target_link_libraries(${MEMGRAPH_BUILD_NAME} ssl)
|
||||
target_link_libraries(${MEMGRAPH_BUILD_NAME} fmt)
|
||||
target_link_libraries(${MEMGRAPH_BUILD_NAME} yaml-cpp)
|
||||
target_link_libraries(${MEMGRAPH_BUILD_NAME} antlr_opencypher_parser_lib)
|
||||
target_link_libraries(${MEMGRAPH_BUILD_NAME} dl)
|
||||
endif()
|
||||
# add_dependencies(${MEMGRAPH_BUILD_NAME} generate_opencypher_parser)
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# utility target to copy hardcoded queries
|
||||
# FROM: tests/integration/hardcoded_query TO: build/compiled/hardcode
|
||||
add_executable(__copy_hardcoded_queries ${src_dir}/copy_hardcoded_queries.cpp)
|
||||
set_property(TARGET __copy_hardcoded_queries PROPERTY CXX_STANDARD
|
||||
${cxx_standard})
|
||||
target_link_libraries(__copy_hardcoded_queries memgraph_lib)
|
||||
target_link_libraries(__copy_hardcoded_queries stdc++fs)
|
||||
target_link_libraries(__copy_hardcoded_queries fmt)
|
||||
target_link_libraries(__copy_hardcoded_queries Threads::Threads)
|
||||
target_link_libraries(__copy_hardcoded_queries antlr_opencypher_parser_lib)
|
||||
add_custom_target(copy_hardcoded_queries ./__copy_hardcoded_queries --src
|
||||
${CMAKE_SOURCE_DIR}/tests/integration/hardcoded_query --dst
|
||||
${CMAKE_BINARY_DIR}/compiled/hardcode
|
||||
WORKING_DIR ${CMAKE_BINARY_DIR})
|
||||
|
||||
# make CLion aware of all source files so we get refactoring etc
|
||||
# this target won't be built
|
||||
|
49
src/copy_hardcoded_queries.cpp
Normal file
49
src/copy_hardcoded_queries.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by buda on 27/02/17.
|
||||
//
|
||||
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#include "logging/streams/stdout.hpp"
|
||||
#include "query/preprocessor.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "utils/command_line/arguments.hpp"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
logging::init_sync();
|
||||
logging::log->pipe(std::make_unique<Stdout>());
|
||||
|
||||
auto logger = logging::log->logger("CopyHardcodedQueries");
|
||||
logger.info("{}", logging::log->type());
|
||||
|
||||
REGISTER_ARGS(argc, argv);
|
||||
|
||||
auto src_path = fs::path(
|
||||
GET_ARG("--src", "tests/integration/hardcoded_queries").get_string());
|
||||
logger.info("Src path is: {}", src_path);
|
||||
permanent_assert(fs::exists(src_path), "src folder must exist");
|
||||
|
||||
auto dst_path =
|
||||
fs::path(GET_ARG("--dst", "build/compiled/hardcode").get_string());
|
||||
logger.info("Dst path is: {}", dst_path);
|
||||
fs::create_directories(dst_path);
|
||||
|
||||
auto src_files = utils::LoadFilePaths(src_path, "cpp");
|
||||
|
||||
QueryPreprocessor preprocessor;
|
||||
for (auto &src_file : src_files) {
|
||||
auto query = extract_query(src_file);
|
||||
auto query_hash = preprocessor.preprocess(query).hash;
|
||||
auto dst_file = dst_path / fs::path(std::to_string(query_hash) + ".cpp");
|
||||
fs::copy(src_file, dst_file, fs::copy_options::overwrite_existing);
|
||||
logger.info("{} - (copy) -> {}", src_file, dst_file);
|
||||
}
|
||||
|
||||
auto hpp_files = utils::LoadFilePaths(src_path, "hpp");
|
||||
for (auto &hpp_file : hpp_files) {
|
||||
fs::copy(hpp_file, dst_path / hpp_file.filename(),
|
||||
fs::copy_options::overwrite_existing);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -53,6 +53,7 @@ class PlanCompiler : public Loggable {
|
||||
// generate compile command
|
||||
auto compile_command = utils::prints(
|
||||
"clang++" + flags,
|
||||
"-DHARDCODED_OUTPUT_STREAM",
|
||||
// "-std=c++1y -O2 -DNDEBUG",
|
||||
"-std=c++1y", // compile flags
|
||||
in_file, // input file
|
||||
|
@ -5,9 +5,16 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <experimental/filesystem>
|
||||
#include <utils/exceptions/basic_exception.hpp>
|
||||
#include "fmt/format.h"
|
||||
#include "logging/default.hpp"
|
||||
#include "utils/exceptions/stacktrace_exception.hpp"
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/string/file.hpp"
|
||||
#include "utils/string/trim.hpp"
|
||||
#include "utils/types/byte.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
@ -18,6 +25,31 @@ using std::endl;
|
||||
// but sometimes that might be a problem
|
||||
namespace {
|
||||
|
||||
std::string extract_query(const fs::path &path) {
|
||||
auto comment_mark = std::string("// ");
|
||||
auto query_mark = comment_mark + std::string("Query: ");
|
||||
auto lines = utils::read_lines(path);
|
||||
// find the line with a query (the query can be split across multiple
|
||||
// lines)
|
||||
for (int i = 0; i < (int)lines.size(); ++i) {
|
||||
// find query in the line
|
||||
auto &line = lines[i];
|
||||
auto pos = line.find(query_mark);
|
||||
// if query doesn't exist pass
|
||||
if (pos == std::string::npos) continue;
|
||||
auto query = utils::trim(line.substr(pos + query_mark.size()));
|
||||
while (i + 1 < (int)lines.size() &&
|
||||
lines[i + 1].find(comment_mark) != std::string::npos) {
|
||||
query += utils::trim(lines[i + 1].substr(lines[i + 1].find(comment_mark) +
|
||||
comment_mark.length()));
|
||||
++i;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
throw BasicException("Unable to find query!");
|
||||
}
|
||||
|
||||
class CodeLineFormatException : public StacktraceException {
|
||||
public:
|
||||
using StacktraceException::StacktraceException;
|
||||
|
@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
|
||||
// TODO: remove experimental from here once that becomes possible (C++17
|
||||
// standard)
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// #include "communication/communication.hpp"
|
||||
// using Stream = communication::OutputStream;
|
||||
|
||||
// TODO: modular
|
||||
// the flag is only used in hardcoded queries compilation
|
||||
// see usage in plan_compiler.hpp
|
||||
#ifdef HARDCODED_OUTPUT_STREAM
|
||||
#include "communication/bolt/communication.hpp"
|
||||
using Stream = communication::OutputStream;
|
||||
#else
|
||||
#include "../stream/print_record_stream.hpp"
|
||||
using Stream = PrintRecordStream;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user