Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chivay committed Apr 10, 2020
1 parent a966aeb commit 41ab2ad
Show file tree
Hide file tree
Showing 216 changed files with 189 additions and 98 deletions.
76 changes: 20 additions & 56 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,70 +1,34 @@
cmake_minimum_required(VERSION 3.5)
project(ursadb VERSION 1.3.0)
project(ursadb VERSION 1.3.0
LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(ClangFormat)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-Wall")

message("Looking for clang-format")
find_program(CLANG_FORMAT_EXEC clang-format)
if(NOT EXISTS ${CLANG_FORMAT_EXEC})
message(WARNING "clang-format not found! Target 'format' won't be available")
else()
file(GLOB FORMAT_SOURCES *.cpp *.h)
add_custom_target(format
COMMAND
${CLANG_FORMAT_EXEC}
-style=file
-i
${FORMAT_SOURCES}
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Formatting..."
)
endif()

configure_file(Version.h.in Version.h)

add_library(
ursa
STATIC
Utils.cpp
OnDiskDataset.cpp
OnDiskIterator.cpp
DatasetBuilder.cpp
Database.cpp
Trim.cpp
OnDiskIndex.cpp
FlatIndexBuilder.cpp
BitmapIndexBuilder.cpp
MemMap.cpp
Query.cpp
QueryParser.cpp
ExclusiveFile.cpp
DatabaseSnapshot.cpp
Task.cpp
Indexer.cpp
DatabaseHandle.cpp
ZHelpers.cpp
Responses.cpp
RawFile.cpp
OnDiskFileIndex.cpp
)
target_include_directories(ursa PRIVATE ${PROJECT_BINARY_DIR})
target_link_libraries(ursa -lstdc++fs -lzmq -pthread)
add_subdirectory(libursa)

add_executable(ursadb Daemon.cpp NetworkService.cpp)
add_executable(ursadb src/Daemon.cpp
src/Daemon.h
src/NetworkService.cpp
src/NetworkService.h)
target_include_directories(ursadb PUBLIC ${CMAKE_SOURCE_DIR})
target_link_libraries(ursadb ursa)

add_executable(ursadb_new NewDatabase.cpp)
add_executable(ursadb_new src/NewDatabase.cpp)
target_include_directories(ursadb_new PUBLIC ${CMAKE_SOURCE_DIR})
target_link_libraries(ursadb_new ursa)

add_executable(ursadb_trim Trim.cpp)
add_executable(ursadb_trim src/Trim.cpp)
target_include_directories(ursadb_trim PUBLIC ${CMAKE_SOURCE_DIR})
target_link_libraries(ursadb_trim ursa)

add_executable(ursadb_test Tests.cpp)
add_executable(ursadb_test src/Tests.cpp)
target_include_directories(ursadb_test PUBLIC ${CMAKE_SOURCE_DIR})
target_link_libraries(ursadb_test ursa)

add_executable(ursadb_bench Benchmark.cpp)
target_link_libraries(ursadb_bench ursa)
add_executable(ursadb_bench src/Benchmark.cpp)
target_include_directories(ursadb_bench PUBLIC ${CMAKE_SOURCE_DIR})
target_link_libraries(ursadb_bench ursa)
48 changes: 48 additions & 0 deletions cmake/ClangFormat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright Tomas Zeman 2019.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

function(clangformat_setup)
if(NOT CLANGFORMAT_EXECUTABLE)
set(CLANGFORMAT_EXECUTABLE clang-format)
endif()

if(NOT EXISTS ${CLANGFORMAT_EXECUTABLE})
find_program(clangformat_executable_tmp ${CLANGFORMAT_EXECUTABLE})
if(clangformat_executable_tmp)
set(CLANGFORMAT_EXECUTABLE ${clangformat_executable_tmp})
unset(clangformat_executable_tmp)
else()
message(FATAL_ERROR "ClangFormat: ${CLANGFORMAT_EXECUTABLE} not found! Aborting")
endif()
endif()

foreach(clangformat_source ${ARGV})
get_filename_component(clangformat_source ${clangformat_source} ABSOLUTE)
list(APPEND clangformat_sources ${clangformat_source})
endforeach()

add_custom_target(${PROJECT_NAME}_clangformat
COMMAND
${CLANGFORMAT_EXECUTABLE}
-style=file
-i
${clangformat_sources}
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMENT
"Formating with ${CLANGFORMAT_EXECUTABLE} ..."
)

if(TARGET clangformat)
add_dependencies(clangformat ${PROJECT_NAME}_clangformat)
else()
add_custom_target(clangformat DEPENDS ${PROJECT_NAME}_clangformat)
endif()
endfunction()

function(target_clangformat_setup target)
get_target_property(target_sources ${target} SOURCES)
clangformat_setup(${target_sources})
endfunction()
File renamed without changes.
File renamed without changes.
57 changes: 57 additions & 0 deletions libursa/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
add_library(
ursa
STATIC
BitmapIndexBuilder.cpp
Database.h
DatasetBuilder.h
IndexBuilder.h
OnDiskDataset.cpp
OnDiskIterator.cpp
RawFile.cpp
Task.h
BitmapIndexBuilder.h
DatabaseHandle.cpp
ExclusiveFile.cpp
Indexer.cpp
OnDiskDataset.h
OnDiskIterator.h
RawFile.h
Utils.cpp
DatabaseHandle.h
ExclusiveFile.h
Indexer.h
OnDiskFileIndex.cpp
Query.cpp
Responses.cpp
Utils.h
Command.h
DatabaseSnapshot.cpp
Json.h
OnDiskFileIndex.h
Query.h
Responses.h
Version.h.in
Core.h
DatabaseSnapshot.h
FlatIndexBuilder.cpp
MemMap.cpp
OnDiskIndex.cpp
QueryParser.cpp
ResultWriter.h
ZHelpers.cpp
Database.cpp
DatasetBuilder.cpp
FlatIndexBuilder.h
MemMap.h
OnDiskIndex.h
QueryParser.h
Task.cpp
ZHelpers.h
)
configure_file(Version.h.in
${PROJECT_BINARY_DIR}/generated/Version.h)

target_include_directories(ursa PRIVATE .
PRIVATE ${PROJECT_BINARY_DIR}/generated)
target_link_libraries(ursa -lstdc++fs -lzmq -pthread)
target_clangformat_setup(ursa)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Json.h → libursa/Json.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#include "lib/Json.h"
#include "extern/json/Json.h"

using json = nlohmann::json;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions QueryParser.cpp → libursa/QueryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include "Command.h"
#include "Core.h"
#include "Query.h"
#include "lib/pegtl.hpp"
#include "lib/pegtl/contrib/abnf.hpp"
#include "lib/pegtl/contrib/parse_tree.hpp"
#include "lib/pegtl/contrib/unescape.hpp"
#include "extern/pegtl/pegtl.hpp"
#include "extern/pegtl/pegtl/contrib/abnf.hpp"
#include "extern/pegtl/pegtl/contrib/parse_tree.hpp"
#include "extern/pegtl/pegtl/contrib/unescape.hpp"

using namespace tao::TAO_PEGTL_NAMESPACE; // NOLINT

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions Benchmark.cpp → src/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <random>
#include <vector>

#include "Core.h"
#include "Database.h"
#include "Utils.h"
#include "libursa/Core.h"
#include "libursa/Database.h"
#include "libursa/Utils.h"

template <typename F, typename... Args>
static uint64_t benchmark_ms(F &&func, Args &&... args) {
Expand Down
22 changes: 22 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
add_executable(ursadb Daemon.cpp
Daemon.h
NetworkService.cpp
NetworkService.h)
target_link_libraries(ursadb ursa)
target_clangformat_setup(ursadb)

add_executable(ursadb_new NewDatabase.cpp)
target_link_libraries(ursadb_new ursa)
target_clangformat_setup(ursadb_new)

add_executable(ursadb_trim Trim.cpp)
target_link_libraries(ursadb_trim ursa)
target_clangformat_setup(ursadb_trim)

add_executable(ursadb_test Tests.cpp)
target_link_libraries(ursadb_test ursa)
target_clangformat_setup(ursadb_test)

add_executable(ursadb_bench Benchmark.cpp)
target_link_libraries(ursadb_bench ursa)
target_clangformat_setup(ursadb_bench)
File renamed without changes.
14 changes: 7 additions & 7 deletions Daemon.cpp → src/Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include <vector>
#include <zmq.hpp>

#include "Command.h"
#include "Database.h"
#include "DatasetBuilder.h"
#include "libursa/Command.h"
#include "libursa/Database.h"
#include "libursa/DatasetBuilder.h"
#include "libursa/OnDiskDataset.h"
#include "libursa/QueryParser.h"
#include "libursa/Responses.h"
#include "libursa/ResultWriter.h"
#include "NetworkService.h"
#include "OnDiskDataset.h"
#include "QueryParser.h"
#include "Responses.h"
#include "ResultWriter.h"

Response execute_command(const SelectCommand &cmd, Task *task,
const DatabaseSnapshot *snap) {
Expand Down
6 changes: 3 additions & 3 deletions Daemon.h → src/Daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <string>

#include "DatabaseSnapshot.h"
#include "Responses.h"
#include "Task.h"
#include "libursa/DatabaseSnapshot.h"
#include "libursa/Responses.h"
#include "libursa/Task.h"

Response dispatch_command_safe(const std::string &cmd_str, Task *task,
const DatabaseSnapshot *snap);
6 changes: 3 additions & 3 deletions NetworkService.cpp → src/NetworkService.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "NetworkService.h"

#include "Daemon.h"
#include "DatabaseHandle.h"
#include "Responses.h"
#include "ZHelpers.h"
#include "libursa/DatabaseHandle.h"
#include "libursa/Responses.h"
#include "libursa/ZHelpers.h"

[[noreturn]] static void *worker_thread(void *arg) {
auto *wctx = static_cast<WorkerContext *>(arg);
Expand Down
2 changes: 1 addition & 1 deletion NetworkService.h → src/NetworkService.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <vector>
#include <zmq.hpp>

#include "Database.h"
#include "libursa/Database.h"

constexpr int NUM_WORKERS = 4;

Expand Down
10 changes: 5 additions & 5 deletions NewDatabase.cpp → src/NewDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include <vector>
#include <zmq.hpp>

#include "Command.h"
#include "Database.h"
#include "DatasetBuilder.h"
#include "OnDiskDataset.h"
#include "QueryParser.h"
#include "libursa/Command.h"
#include "libursa/Database.h"
#include "libursa/DatasetBuilder.h"
#include "libursa/OnDiskDataset.h"
#include "libursa/QueryParser.h"

int main(int argc, char *argv[]) {
if (argc < 2) {
Expand Down
20 changes: 10 additions & 10 deletions Tests.cpp → src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
#include <cstdlib>
#include <variant>

#include "BitmapIndexBuilder.h"
#include "FlatIndexBuilder.h"
#include "IndexBuilder.h"
#include "OnDiskDataset.h"
#include "OnDiskIndex.h"
#include "Query.h"
#include "QueryParser.h"
#include "ResultWriter.h"
#include "Utils.h"
#include "lib/Catch.h"
#include "libursa/BitmapIndexBuilder.h"
#include "libursa/FlatIndexBuilder.h"
#include "libursa/IndexBuilder.h"
#include "libursa/OnDiskDataset.h"
#include "libursa/OnDiskIndex.h"
#include "libursa/Query.h"
#include "libursa/QueryParser.h"
#include "libursa/ResultWriter.h"
#include "libursa/Utils.h"
#include "Catch.h"

TriGram gram3_pack(const char (&s)[4]) {
TriGram v0 = (uint8_t)s[0];
Expand Down
10 changes: 5 additions & 5 deletions Trim.cpp → src/Trim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include <vector>
#include <zmq.hpp>

#include "Command.h"
#include "Database.h"
#include "DatasetBuilder.h"
#include "OnDiskDataset.h"
#include "QueryParser.h"
#include "libursa/Command.h"
#include "libursa/Database.h"
#include "libursa/DatasetBuilder.h"
#include "libursa/OnDiskDataset.h"
#include "libursa/QueryParser.h"

static bool endsWith(const std::string &str, const std::string &suffix) {
return str.size() >= suffix.size() &&
Expand Down

0 comments on commit 41ab2ad

Please sign in to comment.