diff --git a/.gitignore b/.gitignore index 6c0865d1959..6e969a8459c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,10 @@ # auto generated files *.logrt +dbms/src/Storages/System/StorageSystemContributors.generated.cpp + /build +/build_* /docs/build /docs/edit /docs/tools/venv/ diff --git a/dbms/CMakeLists.txt b/dbms/CMakeLists.txt index 0cb5824e1fc..91171eea685 100644 --- a/dbms/CMakeLists.txt +++ b/dbms/CMakeLists.txt @@ -6,18 +6,12 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/find_vectorclass.cmake) set (CONFIG_VERSION ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config_version.h) set (CONFIG_COMMON ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config.h) -set (CONFIG_BUILD ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config_build.cpp) include (cmake/version.cmake) message (STATUS "Will build ${VERSION_FULL}") configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config.h.in ${CONFIG_COMMON}) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config_version.h.in ${CONFIG_VERSION}) -get_property (BUILD_COMPILE_DEFINITIONS DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS) -get_property (BUILD_INCLUDE_DIRECTORIES DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) -string (TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC) -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config_build.cpp.in ${CONFIG_BUILD}) - if (NOT MSVC) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") endif () diff --git a/dbms/src/Common/config_build.h b/dbms/src/Common/config_build.h deleted file mode 100644 index 93e9ba35a8d..00000000000 --- a/dbms/src/Common/config_build.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include - -extern const char * auto_config_build[]; diff --git a/dbms/src/Storages/System/CMakeLists.txt b/dbms/src/Storages/System/CMakeLists.txt index 907fbc2907a..ed12cf6f78c 100644 --- a/dbms/src/Storages/System/CMakeLists.txt +++ b/dbms/src/Storages/System/CMakeLists.txt @@ -1,5 +1,16 @@ +if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/StorageSystemContributors.generated.cpp) + execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/StorageSystemContributors.sh) +endif() + +set (CONFIG_BUILD ${CMAKE_CURRENT_BINARY_DIR}/StorageSystemBuildOptions.generated.cpp) +get_property (BUILD_COMPILE_DEFINITIONS DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS) +get_property (BUILD_INCLUDE_DIRECTORIES DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) +string (TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC) +configure_file (StorageSystemBuildOptions.generated.cpp.in ${CONFIG_BUILD}) include(${ClickHouse_SOURCE_DIR}/cmake/dbms_glob_sources.cmake) add_headers_and_sources(storages_system .) +list (APPEND storages_system_sources ${CONFIG_BUILD}) add_library(clickhouse_storages_system ${LINK_MODE} ${storages_system_headers} ${storages_system_sources}) target_link_libraries(clickhouse_storages_system dbms) +target_include_directories(clickhouse_storages_system PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/dbms/src/Storages/System/StorageSystemBuildOptions.cpp b/dbms/src/Storages/System/StorageSystemBuildOptions.cpp index 2a8ffc947be..b85cc9cf9f7 100644 --- a/dbms/src/Storages/System/StorageSystemBuildOptions.cpp +++ b/dbms/src/Storages/System/StorageSystemBuildOptions.cpp @@ -1,7 +1,9 @@ -#include +#include "StorageSystemBuildOptions.h" + #include #include -#include + +extern const char * auto_config_build[]; namespace DB { diff --git a/dbms/src/Common/config_build.cpp.in b/dbms/src/Storages/System/StorageSystemBuildOptions.generated.cpp.in similarity index 98% rename from dbms/src/Common/config_build.cpp.in rename to dbms/src/Storages/System/StorageSystemBuildOptions.generated.cpp.in index 9e74ea43e00..57c418d7f98 100644 --- a/dbms/src/Common/config_build.cpp.in +++ b/dbms/src/Storages/System/StorageSystemBuildOptions.generated.cpp.in @@ -1,7 +1,5 @@ // .cpp autogenerated by cmake -#include - const char * auto_config_build[] { "VERSION_FULL", "@VERSION_FULL@", diff --git a/dbms/src/Storages/System/StorageSystemContributors.cpp b/dbms/src/Storages/System/StorageSystemContributors.cpp new file mode 100644 index 00000000000..99c720e0f97 --- /dev/null +++ b/dbms/src/Storages/System/StorageSystemContributors.cpp @@ -0,0 +1,36 @@ +#if __has_include("StorageSystemContributors.generated.cpp") + +#include "StorageSystemContributors.h" + +#include +#include +#include +#include + + +extern const char * auto_contributors[]; + +namespace DB +{ +NamesAndTypesList StorageSystemContributors::getNamesAndTypes() +{ + return { + {"name", std::make_shared()}, + }; +} + +void StorageSystemContributors::fillData(MutableColumns & res_columns, const Context &, const SelectQueryInfo &) const +{ + std::vector contributors; + for (auto it = auto_contributors; *it; ++it) + contributors.emplace_back(*it); + + pcg64 rng(randomSeed()); + std::shuffle(contributors.begin(), contributors.end(), rng); + + for (auto & it : contributors) + res_columns[0]->insert(String(it)); +} +} + +#endif diff --git a/dbms/src/Storages/System/StorageSystemContributors.h b/dbms/src/Storages/System/StorageSystemContributors.h new file mode 100644 index 00000000000..b62895d5788 --- /dev/null +++ b/dbms/src/Storages/System/StorageSystemContributors.h @@ -0,0 +1,34 @@ +#pragma once + +#if __has_include("StorageSystemContributors.generated.cpp") + +#include +#include + + +namespace DB +{ +class Context; + + +/** System table "contributors" with list of clickhouse contributors + */ +class StorageSystemContributors : public ext::shared_ptr_helper, + public IStorageSystemOneBlock +{ +protected: + void fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo & query_info) const override; + + using IStorageSystemOneBlock::IStorageSystemOneBlock; + +public: + std::string getName() const override + { + return "SystemContributors"; + } + + static NamesAndTypesList getNamesAndTypes(); +}; +} + +#endif diff --git a/dbms/src/Storages/System/StorageSystemContributors.sh b/dbms/src/Storages/System/StorageSystemContributors.sh new file mode 100755 index 00000000000..44b4730a6f4 --- /dev/null +++ b/dbms/src/Storages/System/StorageSystemContributors.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + +CONTRIBUTORS_FILE=${CONTRIBUTORS_FILE=$CUR_DIR/StorageSystemContributors.generated.cpp} + +git shortlog --summary | perl -lnE 's/^\s+\d+\s+(.+)/"$1",/; next unless $1; say $_' > $CONTRIBUTORS_FILE.tmp + +# If git history not available - dont make target file +if [ ! -s $CONTRIBUTORS_FILE.tmp ]; then + exit +fi + +echo "// autogenerated by $0" > $CONTRIBUTORS_FILE +echo "const char * auto_contributors[] {" >> $CONTRIBUTORS_FILE +cat $CONTRIBUTORS_FILE.tmp >> $CONTRIBUTORS_FILE +echo "nullptr };" >> $CONTRIBUTORS_FILE + +rm $CONTRIBUTORS_FILE.tmp diff --git a/dbms/src/Storages/System/attachSystemTables.cpp b/dbms/src/Storages/System/attachSystemTables.cpp index 10448948942..facaa6c4fd3 100644 --- a/dbms/src/Storages/System/attachSystemTables.cpp +++ b/dbms/src/Storages/System/attachSystemTables.cpp @@ -32,6 +32,9 @@ #include #include #include +#if __has_include("StorageSystemContributors.generated.cpp") +# include +#endif namespace DB @@ -56,6 +59,9 @@ void attachSystemTablesLocal(IDatabase & system_database) system_database.attachTable("data_type_families", StorageSystemDataTypeFamilies::create("data_type_families")); system_database.attachTable("collations", StorageSystemCollations::create("collations")); system_database.attachTable("table_engines", StorageSystemTableEngines::create("table_engines")); +#if __has_include("StorageSystemContributors.generated.cpp") + system_database.attachTable("contributors", StorageSystemContributors::create("contributors")); +#endif } void attachSystemTablesServer(IDatabase & system_database, bool has_zookeeper) diff --git a/dbms/tests/queries/0_stateless/00747_contributors.reference b/dbms/tests/queries/0_stateless/00747_contributors.reference new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00747_contributors.reference @@ -0,0 +1 @@ +ok diff --git a/dbms/tests/queries/0_stateless/00747_contributors.sql b/dbms/tests/queries/0_stateless/00747_contributors.sql new file mode 100644 index 00000000000..ec75d877841 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00747_contributors.sql @@ -0,0 +1,2 @@ +-- Normally table should contain 250+ contributors. But when fast git clone used (--depth=X) (Travis build) table will contain only <=X contributors +SELECT if ((SELECT count(*) FROM system.contributors) > 1, 'ok', 'fail'); diff --git a/release b/release index 23bfd6f2dd6..2a76b9bbdd4 100755 --- a/release +++ b/release @@ -107,6 +107,8 @@ echo -e "\nCurrent version is $VERSION_STRING" gen_changelog "$VERSION_STRING" "" "$AUTHOR" "" +$CURDIR/dbms/src/Storages/System/StorageSystemContributors.sh + if [ -z "$USE_PBUILDER" ] ; then DEB_CC=${DEB_CC:=`which gcc-7 gcc-8 gcc | head -n1`} DEB_CXX=${DEB_CXX:=`which g++-7 g++-8 g++ | head -n1`}