diff options
author | Daniel Moody <daniel.moody@mongodb.com> | 2022-12-16 04:55:07 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-16 05:24:21 +0000 |
commit | d824f5a6e46ac74967e38e015bc46858c235a788 (patch) | |
tree | ae57a560abeb27f53400792335c67d33ed0aa794 /src/mongo | |
parent | 9fa0565a40bf6740eac5d2749046d14aa1a5ea15 (diff) | |
download | mongo-d824f5a6e46ac74967e38e015bc46858c235a788.tar.gz |
SERVER-71748 create dummy mongo custom checks module for reference.
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/tools/SConscript | 34 | ||||
-rw-r--r-- | src/mongo/tools/mongo_tidy_checks/MongoTestCheck.cpp | 85 | ||||
-rw-r--r-- | src/mongo/tools/mongo_tidy_checks/SConscript | 124 | ||||
-rw-r--r-- | src/mongo/tools/mongobridge/SConscript | 31 | ||||
-rw-r--r-- | src/mongo/tools/mongobridge/bridge.cpp (renamed from src/mongo/tools/bridge.cpp) | 4 | ||||
-rw-r--r-- | src/mongo/tools/mongobridge/bridge_commands.cpp (renamed from src/mongo/tools/bridge_commands.cpp) | 2 | ||||
-rw-r--r-- | src/mongo/tools/mongobridge/bridge_commands.h (renamed from src/mongo/tools/bridge_commands.h) | 0 | ||||
-rw-r--r-- | src/mongo/tools/mongobridge/mongobridge_options.cpp (renamed from src/mongo/tools/mongobridge_options.cpp) | 2 | ||||
-rw-r--r-- | src/mongo/tools/mongobridge/mongobridge_options.h (renamed from src/mongo/tools/mongobridge_options.h) | 0 | ||||
-rw-r--r-- | src/mongo/tools/mongobridge/mongobridge_options.idl (renamed from src/mongo/tools/mongobridge_options.idl) | 2 | ||||
-rw-r--r-- | src/mongo/tools/mongobridge/mongobridge_options_init.cpp (renamed from src/mongo/tools/mongobridge_options_init.cpp) | 2 |
11 files changed, 253 insertions, 33 deletions
diff --git a/src/mongo/tools/SConscript b/src/mongo/tools/SConscript index 78882321775..f5be11e24bd 100644 --- a/src/mongo/tools/SConscript +++ b/src/mongo/tools/SConscript @@ -1,33 +1,13 @@ -# -*- mode: python; -*- - -Import('env') -Import('get_option') +Import("env") env = env.Clone() -yamlEnv = env.Clone() -yamlEnv.InjectThirdParty(libraries=['yaml']) - -mongobridge = env.Program( - target="mongobridge", - source=[ - "bridge.cpp", - "bridge_commands.cpp", - "mongobridge_options.cpp", - "mongobridge_options.idl", - "mongobridge_options_init.cpp", +env.SConscript( + dirs=[ + 'mongobridge', + 'mongo_tidy_checks', ], - LIBDEPS=[ - '$BUILD_DIR/mongo/db/dbmessage', - '$BUILD_DIR/mongo/rpc/rpc', - '$BUILD_DIR/mongo/transport/message_compressor', - '$BUILD_DIR/mongo/transport/message_compressor_options_server', - '$BUILD_DIR/mongo/transport/service_entry_point', - '$BUILD_DIR/mongo/transport/service_executor', - '$BUILD_DIR/mongo/transport/transport_layer', - '$BUILD_DIR/mongo/util/net/network', - '$BUILD_DIR/mongo/util/options_parser/options_parser_init', - '$BUILD_DIR/mongo/util/signal_handlers', + exports=[ + 'env', ], - AIB_COMPONENT='dist-test', ) diff --git a/src/mongo/tools/mongo_tidy_checks/MongoTestCheck.cpp b/src/mongo/tools/mongo_tidy_checks/MongoTestCheck.cpp new file mode 100644 index 00000000000..eaccb77af78 --- /dev/null +++ b/src/mongo/tools/mongo_tidy_checks/MongoTestCheck.cpp @@ -0,0 +1,85 @@ +/** + * Copyright (C) 2022-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "clang-tidy/ClangTidy.h" +#include "clang-tidy/ClangTidyCheck.h" +#include "clang-tidy/ClangTidyModule.h" +#include "clang-tidy/ClangTidyModuleRegistry.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang; +using namespace clang::tidy; +using namespace clang::ast_matchers; + +// TODO SERVER-72150 +// This is a dummy reference check to give example for writing new checks. +// This check should be removed (the file here and any references to it) once we have +// some real checks. +namespace { +class MongoDummyCheck : public ClangTidyCheck { + +public: + MongoDummyCheck(StringRef Name, ClangTidyContext* Context) : ClangTidyCheck(Name, Context) {} + + void registerMatchers(ast_matchers::MatchFinder* Finder) override { + Finder->addMatcher(translationUnitDecl().bind("tu"), this); + } + + void check(const ast_matchers::MatchFinder::MatchResult& Result) override { + auto S = Result.Nodes.getNodeAs<TranslationUnitDecl>("tu"); + if (S) + diag("mytest success"); + } + +private: +}; + +class CTTestModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories& CheckFactories) override { + CheckFactories.registerCheck<MongoDummyCheck>("mongo-test-check"); + } +}; +} // namespace + +namespace tidy1 { +// Register the CTTestTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add<::CTTestModule> X("mytest-module", "Adds my checks."); +} // namespace tidy1 + +namespace tidy2 { +// intentionally collide with an existing test group name, merging with it +static ClangTidyModuleRegistry::Add<::CTTestModule> X("misc-module", + "Adds miscellaneous lint checks."); +} // namespace tidy2 + +// This anchor is used to force the linker to link in the generated object file +// and thus register the CTTestModule. +volatile int CTTestModuleAnchorSource = 0; diff --git a/src/mongo/tools/mongo_tidy_checks/SConscript b/src/mongo/tools/mongo_tidy_checks/SConscript new file mode 100644 index 00000000000..9a955c92294 --- /dev/null +++ b/src/mongo/tools/mongo_tidy_checks/SConscript @@ -0,0 +1,124 @@ +Import('env') + +import os +import pathlib +from buildscripts.toolchains import DEFAULT_DATA_FILE, ToolchainConfig, ToolchainPlatform + +try: + toolchain_config = ToolchainConfig(DEFAULT_DATA_FILE, ToolchainPlatform('default')) + symlink_path = str( + toolchain_config.base_path / toolchain_config.aliases['stable'] / 'bin' / 'clang-tidy') + # using os.readlink because pathlib readlink not support on python 3.7 + base_path = pathlib.Path(os.readlink(symlink_path)).resolve().parent.parent +except FileNotFoundError: + Return() + +tidy_include = base_path / 'include' +tidy_lib = base_path / 'lib' + +env = env.Clone() + +# TODO SERVER-72147 +# This config was ripped from the toolchain build because our standard build config produced +# mismatched ABI, as well as using z,defs which will not work in this situation, so I am not +# sure what flags were specifically responsible and I just swapped them all. The toolchain build +# should test the check module so that if the configuration of clang-tidy changes there it would +# catch any issues here. +env['CPPPATH'] = [str(tidy_include)] +env['LIBPATH'] = [] +env['CCFLAGS'] = [ + '-DGTEST_HAS_RTTI=0', + '-D_GNU_SOURCE', + '-D__STDC_CONSTANT_MACROS', + '-D__STDC_FORMAT_MACROS', + '-D__STDC_LIMIT_MACROS', + '-fPIC', + '-fvisibility-inlines-hidden', + '-Werror=date-time', + '-Wall', + '-Wextra', + '-Wno-unused-parameter', + '-Wwrite-strings', + '-Wcast-qual', + '-Wno-missing-field-initializers', + '-pedantic', + '-Wno-long-long', + '-Wimplicit-fallthrough', + '-Wno-maybe-uninitialized', + '-Wno-class-memaccess', + '-Wno-redundant-move', + '-Wno-noexcept-type', + '-Wdelete-non-virtual-dtor', + '-Wsuggest-override', + '-Wno-comment', + '-fdiagnostics-color', + '-ffunction-sections', + '-fdata-sections', + '-fno-common', + '-Woverloaded-virtual', + '-fno-strict-aliasing', + '-O3', + '-DNDEBUG', + '-fPIC', + '-fno-exceptions', + '-fno-rtti', + '-std=c++17', +] +env['LINKFLAGS'] = [] +env['SHLINKFLAGS'] = [ + '-fPIC', + '-fvisibility-inlines-hidden', + '-Werror=date-time', + '-Wall', + '-Wextra', + '-Wno-unused-parameter', + '-Wwrite-strings', + '-Wcast-qual', + '-Wno-missing-field-initializers', + '-pedantic', + '-Wno-long-long', + '-Wimplicit-fallthrough', + '-Wno-maybe-uninitialized', + '-Wno-class-memaccess', + '-Wno-redundant-move', + '-Wno-noexcept-type', + '-Wdelete-non-virtual-dtor', + '-Wsuggest-override', + '-Wno-comment', + '-fdiagnostics-color', + '-ffunction-sections', + '-fdata-sections', + '-fno-common', + '-Woverloaded-virtual', + '-fno-strict-aliasing', + '-O3', + '-DNDEBUG', + '-Wl,-z,nodelete', + f'-Wl,-rpath-link,{tidy_lib}', + '-Wl,-O3', + '-Wl,--gc-sections', + '-shared', + r'-Wl,-rpath,"\$$ORIGIN/../lib"', +] +env['CXXFLAGS'] = [] +env['CFLAGS'] = [] +env['FORCEINCLUDES'] = [] +env['LIBDEPS_TAG_EXPANSIONS'] = [] + +mongo_custom_check = env.SharedLibrary( + target="mongo_tidy_checks", + source=[ + "MongoTestCheck.cpp", + ], + LIBDEPS_NO_INHERIT=[ + '$BUILD_DIR/third_party/shim_allocator', + ], + AIB_COMPONENT='mongo-tidy-checks', +) + +pretty_printer_test_installed = env.AutoInstall( + target='$PREFIX_LIBDIR', + source=mongo_custom_check, + AIB_ROLE='runtime', + AIB_COMPONENT='mongo-tidy-checks', +) diff --git a/src/mongo/tools/mongobridge/SConscript b/src/mongo/tools/mongobridge/SConscript new file mode 100644 index 00000000000..f917a686bd2 --- /dev/null +++ b/src/mongo/tools/mongobridge/SConscript @@ -0,0 +1,31 @@ +Import('env') +Import('get_option') + +env = env.Clone() + +yamlEnv = env.Clone() +yamlEnv.InjectThirdParty(libraries=['yaml']) + +mongobridge = env.Program( + target="mongobridge", + source=[ + "bridge.cpp", + "bridge_commands.cpp", + "mongobridge_options.cpp", + "mongobridge_options.idl", + "mongobridge_options_init.cpp", + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/db/dbmessage', + '$BUILD_DIR/mongo/rpc/rpc', + '$BUILD_DIR/mongo/transport/message_compressor', + '$BUILD_DIR/mongo/transport/message_compressor_options_server', + '$BUILD_DIR/mongo/transport/service_entry_point', + '$BUILD_DIR/mongo/transport/service_executor', + '$BUILD_DIR/mongo/transport/transport_layer', + '$BUILD_DIR/mongo/util/net/network', + '$BUILD_DIR/mongo/util/options_parser/options_parser_init', + '$BUILD_DIR/mongo/util/signal_handlers', + ], + AIB_COMPONENT='dist-test', +) diff --git a/src/mongo/tools/bridge.cpp b/src/mongo/tools/mongobridge/bridge.cpp index 242e4b89e0d..73d8f9aff07 100644 --- a/src/mongo/tools/bridge.cpp +++ b/src/mongo/tools/mongobridge/bridge.cpp @@ -48,8 +48,8 @@ #include "mongo/rpc/message.h" #include "mongo/rpc/reply_builder_interface.h" #include "mongo/stdx/thread.h" -#include "mongo/tools/bridge_commands.h" -#include "mongo/tools/mongobridge_options.h" +#include "mongo/tools/mongobridge/bridge_commands.h" +#include "mongo/tools/mongobridge/mongobridge_options.h" #include "mongo/transport/message_compressor_manager.h" #include "mongo/transport/service_entry_point_impl.h" #include "mongo/transport/service_executor_synchronous.h" diff --git a/src/mongo/tools/bridge_commands.cpp b/src/mongo/tools/mongobridge/bridge_commands.cpp index 6ff96970e7e..453ccb5fce4 100644 --- a/src/mongo/tools/bridge_commands.cpp +++ b/src/mongo/tools/mongobridge/bridge_commands.cpp @@ -29,7 +29,7 @@ #include "mongo/platform/basic.h" -#include "mongo/tools/bridge_commands.h" +#include "mongo/tools/mongobridge/bridge_commands.h" #include "mongo/base/init.h" #include "mongo/base/status.h" diff --git a/src/mongo/tools/bridge_commands.h b/src/mongo/tools/mongobridge/bridge_commands.h index 8b32fbba86c..8b32fbba86c 100644 --- a/src/mongo/tools/bridge_commands.h +++ b/src/mongo/tools/mongobridge/bridge_commands.h diff --git a/src/mongo/tools/mongobridge_options.cpp b/src/mongo/tools/mongobridge/mongobridge_options.cpp index 72dc1d0cf03..d237eaef0c1 100644 --- a/src/mongo/tools/mongobridge_options.cpp +++ b/src/mongo/tools/mongobridge/mongobridge_options.cpp @@ -28,7 +28,7 @@ */ -#include "mongo/tools/mongobridge_options.h" +#include "mongo/tools/mongobridge/mongobridge_options.h" #include <algorithm> #include <iostream> diff --git a/src/mongo/tools/mongobridge_options.h b/src/mongo/tools/mongobridge/mongobridge_options.h index 4fac287f976..4fac287f976 100644 --- a/src/mongo/tools/mongobridge_options.h +++ b/src/mongo/tools/mongobridge/mongobridge_options.h diff --git a/src/mongo/tools/mongobridge_options.idl b/src/mongo/tools/mongobridge/mongobridge_options.idl index 240f9eba04c..7865680fac5 100644 --- a/src/mongo/tools/mongobridge_options.idl +++ b/src/mongo/tools/mongobridge/mongobridge_options.idl @@ -31,7 +31,7 @@ global: configs: source: [ cli] cpp_includes: - - "mongo/tools/mongobridge_options.h" + - "mongo/tools/mongobridge/mongobridge_options.h" imports: - "mongo/db/basic_types.idl" diff --git a/src/mongo/tools/mongobridge_options_init.cpp b/src/mongo/tools/mongobridge/mongobridge_options_init.cpp index f0023ed7c10..fbf6fc90cdf 100644 --- a/src/mongo/tools/mongobridge_options_init.cpp +++ b/src/mongo/tools/mongobridge/mongobridge_options_init.cpp @@ -27,7 +27,7 @@ * it in the license file. */ -#include "mongo/tools/mongobridge_options.h" +#include "mongo/tools/mongobridge/mongobridge_options.h" #include <iostream> |