From 9d4ae833cc85cc03401e40f88a55606ae1d001a5 Mon Sep 17 00:00:00 2001 From: Teon Banek <teon.banek@memgraph.io> Date: Tue, 26 Sep 2017 14:25:01 +0200 Subject: [PATCH] Setup basic installation for CPackDeb Summary: Remove traces of plan_compiler in cmake. Add memgraph executable to install target. Fix indentation in tests/CMakeLists.txt. Install alpha.conf to /etc/memgraph/config. Rename executable to 'memgraph' and install /var dirs. Reviewers: mferencevic, buda Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D829 --- CMakeLists.txt | 56 ++++-- cmake/recursive_include | 178 ------------------ config/alpha.conf | 21 +-- config/benchmarking_latency.conf | 9 - config/benchmarking_throughput.conf | 9 - config/stress.conf | 9 - config/testing.conf | 9 - libs/CMakeLists.txt | 16 +- src/query/plan_template_cpp | 33 ---- tests/CMakeLists.txt | 15 +- .../ldbc/config/memgraph.conf | 9 - 11 files changed, 59 insertions(+), 305 deletions(-) delete mode 100755 cmake/recursive_include delete mode 100644 src/query/plan_template_cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index eea396150..b26fd719c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,8 +35,7 @@ set(CMAKE_CXX_COMPILER "clang++") get_filename_component(project_name ${CMAKE_SOURCE_DIR} NAME) # replace whitespaces with underscores string(REPLACE " " "_" project_name ${project_name}) -# set project name -project(${project_name}) +project(${project_name} VERSION 0.7.0) # ----------------------------------------------------------------------------- # setup CMake module path, defines path for include() and find_package() @@ -111,7 +110,6 @@ message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}") add_subdirectory(libs) # fmt set(fmt_source_dir ${libs_dir}/fmt) -set(fmt_static_lib ${fmt_source_dir}/fmt/libfmt.a) # linter setup (clang-tidy) # all source files for linting @@ -188,9 +186,6 @@ message(STATUS "Generate coverage from unit tests: ${TEST_COVERAGE}") include_directories(${src_dir}) include_directories(SYSTEM ${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS}) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/libs) # cppitertools -# needed to include configured files (plan_compiler_flags.hpp) -set(generated_headers_dir ${CMAKE_BINARY_DIR}/generated_headers) -include_directories(${generated_headers_dir}) include_directories(SYSTEM ${GLOG_INCLUDE_DIR}) # ----------------------------------------------------------------------------- @@ -292,15 +287,6 @@ endif() add_subdirectory(tests) # ----------------------------------------------------------------------------- -add_custom_target(recursive_include_plan_template - COMMAND ./recursive_include --roots ${src_dir} ${libs_dir} ${CMAKE_BINARY_DIR}/libs/gflags/include ${GLOG_INCLUDE_DIR} --start ${src_dir}/query/plan_template_cpp --copy ${CMAKE_BINARY_DIR}/include - DEPENDS ${src_dir}/query/plan_template_cpp - SOURCES ${src_dir}/query/plan_template_cpp - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/cmake -) -add_dependencies(recursive_include_plan_template fmt gflags glog) -add_dependencies(memgraph_lib recursive_include_plan_template) - # memgraph build name execute_process( OUTPUT_VARIABLE COMMIT_BRANCH @@ -329,6 +315,24 @@ if (MEMGRAPH) set_property(TARGET ${MEMGRAPH_BUILD_NAME} PROPERTY CXX_STANDARD ${cxx_standard}) target_link_libraries(${MEMGRAPH_BUILD_NAME} memgraph_lib) + # Strip the executable in release build. + string(TOLOWER ${CMAKE_BUILD_TYPE} lower_build_type) + if (lower_build_type STREQUAL "release") + add_custom_command(TARGET ${MEMGRAPH_BUILD_NAME} POST_BUILD + COMMAND strip -s ${MEMGRAPH_BUILD_NAME} + COMMENT Stripping symbols and sections from + ${MEMGRAPH_BUILD_NAME}) + endif() + # Install and rename executable to just 'memgraph' Since we have to rename, + # we cannot use the recommended `install(TARGETS ...)`. + install(PROGRAMS ${CMAKE_BINARY_DIR}/${MEMGRAPH_BUILD_NAME} + DESTINATION bin RENAME memgraph) + # Install the config file. + install(FILES ${CMAKE_SOURCE_DIR}/config/alpha.conf + DESTINATION /etc/memgraph RENAME config) + # Create empty directories for default location of snapshots and logs. + install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}/var/log/memgraph + \$ENV{DESTDIR}/var/lib/memgraph/snapshots)") endif() # make CLion aware of all source files so we get refactoring etc @@ -339,3 +343,25 @@ add_executable(__refactor_target ${__SOURCES}) set_target_properties(__refactor_target PROPERTIES EXCLUDE_FROM_ALL 1) get_target_cxx_flags(memgraph_lib compile_flags) + +# ---- Setup CPack -------- +# General setup +set(CPACK_PACKAGE_NAME memgraph) +set(CPACK_PACKAGE_VENDOR "Memgraph Ltd.") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY + "High performance, in-memory, transactional graph database") +set(CPACK_PACKAGE_VERSION_MAJOR ${${project_name}_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${${project_name}_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${${project_name}_VERSION_PATCH}) +set(CPACK_PACKAGE_VERSION_TWEAK ${${project_name}_VERSION_TWEAK}) +# TODO: Longer description, readme and license files. +# DEB specific +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Memgraph Ltd.") +set(CPACK_DEBIAN_PACKAGE_SECTION database) +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE https://memgraph.com) +# We may need conffiles, postinst, postrm or prerm scripts. +# set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ...) +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) +# All variables must be set before including. +include(CPack) +# ---- End Setup CPack ---- diff --git a/cmake/recursive_include b/cmake/recursive_include deleted file mode 100755 index 6ce2c527e..000000000 --- a/cmake/recursive_include +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/env python - -""" -A script for finding and [copying|printing] C++ -headers that get recursively imported from one (or more) -starting points. - -Supports absolute imports relative to some root folder -(project root) and relative imports relative to the -header that is doing the importing. - -Does not support conditional imports (resulting from -#ifdef macros and such). All the #import statements -found in a header (one #import per line) are traversed. - -Supports Python2 and Python3. -""" - -__author__ = "Florijan Stamenkovic" -__copyright__ = "Copyright 2017, Memgraph" - -import logging -import sys -import os -import re -import shutil -from argparse import ArgumentParser - -# the prefix of an include directive -PREFIX = "#include" - -log = logging.getLogger(__name__) - - -def parse_args(): - argp = ArgumentParser(description=__doc__) - argp.add_argument("--logging", default="INFO", choices=["INFO", "DEBUG"], - help="Logging level") - argp.add_argument("--roots", required=True, nargs="+", - help="One or more paths in which headers are sought") - argp.add_argument("--start", required=True, nargs="+", - help="One or more headers from which to start scanning") - argp.add_argument("--stdout", action="store_true", - help="If found paths should be printed out to stdout") - argp.add_argument("--copy", default=None, - help="Prefix of the path where the headers should be copied") - return argp.parse_args() - - -def main(): - args = parse_args() - logging.basicConfig(level=args.logging) - - log.info("Recursively detecting used C/C++ headers in roots '%s' with starting point(s) '%s'", - args.roots, args.start) - - args.roots = [os.path.abspath(p) for p in args.roots] - - results = set() - for start in args.start: - find_recursive(start, args.roots, results) - - results = list(sorted(results)) - - log.debug("Found %d paths:", len(results)) - for r in results: - log.debug("\t%s", r) - - # print out the results if required - if args.stdout: - for result in results: - print(result) - - # copy the results if required - if args.copy is not None: - for root, path in results: - from_path = os.path.join(root, path) - to_path = os.path.join(args.copy, path) - log.debug("Copying '%s' to '%s'", from_path, to_path) - - # create a directory if necessary, Py2 and Py3 compatible - to_dir = os.path.dirname(to_path) - if not os.path.exists(to_dir): - os.makedirs(to_dir) - - shutil.copy(from_path, to_path) - - -def abs_to_relative(roots, path): - """ - Args: - roots: list of str, a list of possible prefixes - to the 'path'. - path: str, a path to a file. - Return: - A tuple (relative_path, root) where 'root' is one - of the given 'roots' and where - os.path.join(root, relative_path) equals the given - 'path' - Raise: - An exception if none of the 'roots' is a prefix of - 'path' - """ - for root in roots: - if path.startswith(root): - return (root, path[len(root) + 1:]) - - raise Exception("Failed to find prefix of '%s'in '%r'" % ( - path, roots)) - - -def find_recursive(path, roots, results): - """ - Recursivelly looks for headers and adds them to results. - - Results are added as tuples of form (root, header_path) - where 'root' is one of the given roots: the one in which - the header was found, and 'header_path' is the found - header's path relative to 'root'. - - Args: - path: str of tuple. If str, it's considered a path - that has one of the roots as prefix. If tuple - it's considered a (prefix, suffix) that defines - a path. - In both forms the path is to a header. This header is added - to results and scanned for #include statements of - other headers. For each #include (relative to current - `path` or to `project_root`) for which a file is found - this same function is called. - roots: list of str, List of folders in which headers are - sought. Must be absolute paths. - results: a collection into which the results are - added. The collection contains tuples of form - (root, path), see function description. - """ - log.debug("Processing path: %s", path) - - if isinstance(path, str): - path = os.path.abspath(path) - path = abs_to_relative(roots, path) - - # from this point onward 'path' is a tuple (root, suffix) - - if path in results: - log.debug("Skipping already present path '%r'", path) - return - - log.debug("Adding path '%r'", path) - results.add(path) - - # go through files and look for include directives - with open(os.path.join(*path)) as f: - for line in filter(lambda l: l.startswith(PREFIX), - map(lambda l: l.strip(), f)): - - include = line[len(PREFIX):].strip() - include = re.sub("[\"\'\>\<]", "", include) - - log.debug("Processing include '%s'", include) - - # search for the include relatively to the current header - include_rel = os.path.join( - os.path.dirname(os.path.join(*path)), include) - if os.path.exists(include_rel) and os.path.isfile(include_rel): - find_recursive(include_rel, roots, results) - continue - - # search for file in roots - for root in roots: - include_abs = os.path.join(root, include) - if os.path.exists(include_abs) and os.path.isfile(include_abs): - find_recursive((root, include), roots, results) - continue - - -if __name__ == '__main__': - main() diff --git a/config/alpha.conf b/config/alpha.conf index fe29aa11b..2ff871fe2 100644 --- a/config/alpha.conf +++ b/config/alpha.conf @@ -3,19 +3,9 @@ # NOTE: all paths are relative to the run folder # (where the executable is run) -# path to the codes which will be compiled ---compile-path=./compiled/ - -# path to the template (cpp) for codes generation ---template-cpp-path=./template/plan_template_cpp - # path to the folder with snapshots --snapshot-directory=/var/lib/memgraph/snapshots -# cleaning cycle interval -# if set to -1 the GC will not run ---cleaning-cycle-sec=30 - # snapshot cycle interval # if set to -1 the snapshooter will not run --snapshot-cycle-sec=300 @@ -27,13 +17,12 @@ # if set to -1 the max number of snapshots is unlimited --snapshot-max-retained=3 -# by default query engine runs in interpret mode ---interpret=true - +# true if the database should recover the latest snapshot on startup --snapshot-recover-on-startup=true -# use ast caching ---ast-cache=false +# cleaning cycle interval +# if set to -1 the GC will not run +--gc-cycle-sec=30 # path to where the log should be stored ---log-file=/var/lib/memgraph/memgraph.log +--log-file=/var/log/memgraph/memgraph.log diff --git a/config/benchmarking_latency.conf b/config/benchmarking_latency.conf index 665c430fb..a0dfc267d 100644 --- a/config/benchmarking_latency.conf +++ b/config/benchmarking_latency.conf @@ -3,12 +3,6 @@ # NOTE: all paths are relative to the run folder # (where the executable is run) -# directory to the codes which will be compiled ---compile-directory=compiled - -# path to the template (cpp) for codes generation ---template-cpp-path=template/plan_template_cpp - # directory to the folder with snapshots --snapshot-directory=snapshots @@ -35,9 +29,6 @@ # if set to -1 the max number of snapshots is unlimited --snapshot-max-retained=-1 -# by default query engine runs in interpret mode ---interpret=true - # database recovering is disabled by default --snapshot-recover-on-startup=false diff --git a/config/benchmarking_throughput.conf b/config/benchmarking_throughput.conf index 1c56c9b58..27332280d 100644 --- a/config/benchmarking_throughput.conf +++ b/config/benchmarking_throughput.conf @@ -3,12 +3,6 @@ # NOTE: all paths are relative to the run folder # (where the executable is run) -# directory to the codes which will be compiled ---compile-directory=compiled - -# path to the template (cpp) for codes generation ---template-cpp-path=template/plan_template_cpp - # directory to the folder with snapshots --snapshot-directory=snapshots @@ -27,9 +21,6 @@ # if set to -1 the max number of snapshots is unlimited --snapshot-max-retained=-1 -# by default query engine runs in interpret mode ---interpret=true - # database recovering is disabled by default --snapshot-recover-on-startup=false diff --git a/config/stress.conf b/config/stress.conf index ec3442b22..0d2fe750c 100644 --- a/config/stress.conf +++ b/config/stress.conf @@ -3,12 +3,6 @@ # NOTE: all paths are relative to the run folder # (where the executable is run) -# directory to the codes which will be compiled ---compile-directory=compiled - -# path to the template (cpp) for codes generation ---template-cpp-path=template/plan_template_cpp - # directory to the folder with snapshots --snapshot-directory=snapshots @@ -27,9 +21,6 @@ # if set to -1 the max number of snapshots is unlimited --snapshot-max-retained=1 -# by default query engine runs in interpret mode ---interpret=true - # database recovering is disabled by default --snapshot-recover-on-startup=false diff --git a/config/testing.conf b/config/testing.conf index 09a5814f8..5d5b04e09 100644 --- a/config/testing.conf +++ b/config/testing.conf @@ -3,12 +3,6 @@ # NOTE: all paths are relative to the run folder # (where the executable is run) -# directory to the codes which will be compiled ---compile-directory=compiled - -# path to the template (cpp) for codes generation ---template-cpp-path=template/plan_template_cpp - # directory to the folder with snapshots --snapshot-directory=snapshots @@ -27,9 +21,6 @@ # if set to -1 the max number of snapshots is unlimited --snapshot-max-retained=-1 -# by default query engine runs in interpret mode ---interpret=true - # database recovering is disabled by default --snapshot-recover-on-startup=false diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 743593dc1..e5a89a4e6 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -17,11 +17,10 @@ ExternalProject_Add(antlr4 -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/antlr4/runtime/Cpp # http://stackoverflow.com/questions/37096062/get-a-basic-c-program-to-compile-using-clang-on-ubuntu-16/38385967#38385967 -DWITH_LIBCXX=OFF # because of debian bug - BUILD_COMMAND make -j${NPROC} # Make a License.txt out of thin air, so that antlr4.6 knows how to build. # When we upgrade antlr, this will no longer be needed. INSTALL_COMMAND touch ${CMAKE_CURRENT_SOURCE_DIR}/antlr4/runtime/Cpp/License.txt - COMMAND make install) + COMMAND $(MAKE) install) set(ANTLR4_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/antlr4/runtime/Cpp/lib/libantlr4-runtime.a CACHE FILEPATH "Path to antlr4 library" FORCE) set(ANTLR4_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/antlr4/runtime/Cpp/include/antlr4-runtime @@ -29,18 +28,18 @@ set(ANTLR4_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/antlr4/runtime/Cpp/include/an mark_as_advanced(ANTLR4_LIBRARY ANTLR4_INCLUDE_DIR) # setup google benchmark -add_subdirectory(benchmark) +add_subdirectory(benchmark EXCLUDE_FROM_ALL) # setup fmt format # fmt uses google test but if fmt isn't top project (here it isn't) fmt tests # are disabled (reasonable configuration) -add_subdirectory(fmt) +add_subdirectory(fmt EXCLUDE_FROM_ALL) # setup rapidcheck -add_subdirectory(rapidcheck) +add_subdirectory(rapidcheck EXCLUDE_FROM_ALL) # setup google test -add_subdirectory(googletest) +add_subdirectory(googletest EXCLUDE_FROM_ALL) # setup google flags set(GFLAGS_BUILD_gflags_nothreads_LIB OFF) @@ -48,7 +47,7 @@ set(GFLAGS_BUILD_gflags_LIB ON) # Gflags has to be position independant otherwise Glog complains. set(CMAKE_CXX_FLAGS_SAVED ${CMAKE_CXX_FLAGS}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -add_subdirectory(gflags) +add_subdirectory(gflags EXCLUDE_FROM_ALL) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVED}) # Setup google logging after gflags (so that glog can use it). @@ -59,8 +58,7 @@ ExternalProject_Add(glog DEPENDS gflags -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/glog - -Dgflags_DIR=${CMAKE_CURRENT_BINARY_DIR}/gflags - BUILD_COMMAND make -j${NPROC}) + -Dgflags_DIR=${CMAKE_CURRENT_BINARY_DIR}/gflags) set(GLOG_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/glog/lib/libglog.a CACHE FILEPATH "Path to glog library" FORCE) set(GLOG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glog/include CACHE PATH diff --git a/src/query/plan_template_cpp b/src/query/plan_template_cpp deleted file mode 100644 index 181df1068..000000000 --- a/src/query/plan_template_cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include <iostream> -#include <string> - -#include "gflags/gflags.h" -#include "gflags/gflags_declare.h" -#include "glog/logging.h" -#include "data_structures/bitset/static_bitset.hpp" -#include "communication/bolt/v1/encoder/result_stream.hpp" -#include "io/network/socket.hpp" -#include "query/backend/cpp/typed_value.hpp" -#include "query/plan_interface.hpp" - -using std::cout; -using std::endl; - -// Query: {{query}} - -class {{class_name}} : public PlanInterface<{{stream}}> { -public: - bool run(Db &db, const PlanArgsT &args, {{stream}} &stream) override { - {{code}} - } - - ~{{class_name}}() {} -}; - -extern "C" PlanInterface<{{stream}}>* produce() { - return new {{class_name}}(); -} - -extern "C" void destruct(PlanInterface<{{stream}}>* p) { - delete p; -} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8c782a0d4..77b36ae71 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,15 +13,12 @@ file(COPY ${CMAKE_SOURCE_DIR}/tests/data DESTINATION ${CMAKE_BINARY_DIR}/tests) # move test data data to the build directory -if (UNIX) - set(test_data "tests/data") - set(test_data_src "${CMAKE_SOURCE_DIR}/${test_data}") - set(test_data_dst "${CMAKE_BINARY_DIR}/${test_data}") - add_custom_target (test_data - COMMAND rm -rf ${test_data_dst} - COMMAND cp -r ${test_data_src} ${test_data_dst} - ) -endif (UNIX) +set(test_data "tests/data") +set(test_data_src "${CMAKE_SOURCE_DIR}/${test_data}") +set(test_data_dst "${CMAKE_BINARY_DIR}/${test_data}") +add_custom_target(test_data + COMMAND rm -rf ${test_data_dst} + COMMAND cp -r ${test_data_src} ${test_data_dst}) # ----------------------------------------------------------------------------- # benchmark test binaries diff --git a/tests/public_benchmark/ldbc/config/memgraph.conf b/tests/public_benchmark/ldbc/config/memgraph.conf index 5094f6397..9dd75a5ab 100644 --- a/tests/public_benchmark/ldbc/config/memgraph.conf +++ b/tests/public_benchmark/ldbc/config/memgraph.conf @@ -3,12 +3,6 @@ # NOTE: all paths are relative to the run folder # (where the executable is run) -# directory to the codes which will be compiled ---compile-directory=compiled - -# path to the template (cpp) for codes generation ---template-cpp-path=template/plan_template_cpp - # directory to the folder with snapshots --snapshot-directory=snapshots @@ -27,9 +21,6 @@ # if set to -1 the max number of snapshots is unlimited --snapshot-max-retained=-1 -# by default query engine runs in interpret mode ---interpret=true - --snapshot-recover-on-startup=true # use ast caching