From 865ae9d8edab339a817b7ecb17db6cc374b8dc17 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Tue, 7 Feb 2023 18:32:11 +0100 Subject: [PATCH] Reverted custom compilation database class to default --- src/CMakeLists.txt | 13 +++-- tests/CMakeLists.txt | 19 +++---- tests/t00018/test_case.h | 2 +- tests/t00048/test_case.h | 3 +- tests/t20014/test_case.h | 3 +- tests/t40001/test_case.h | 2 +- tests/t40002/test_case.h | 3 +- tests/t40003/test_case.h | 3 +- tests/test_cases.cc | 107 +-------------------------------------- 9 files changed, 26 insertions(+), 129 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 99f08aae..ef4b7700 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,13 +22,12 @@ else(MSVC) add_library(clang-umllib OBJECT ${SOURCES}) endif(MSVC) -target_compile_options(clang-umllib PUBLIC +target_compile_options(clang-umllib PRIVATE $<$,$>: -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-private-field> $<$: - /W1 /std:c++17 /bigobj /wd4291 /wd4624 /wd4244 /NODEFAULTLIB:MSVCRT - /NODEFAULTLIB:MSVCRTD>) -target_compile_definitions(clang-umllib PUBLIC + /MP /W1 /std:c++17 /bigobj /wd4291 /wd4624 /wd4244>) +target_compile_definitions(clang-umllib PRIVATE $<$: -DLLVM_FORCE_USE_OLD_TOOLCHAIN>) @@ -37,6 +36,12 @@ target_compile_definitions(clang-umllib PUBLIC # add_executable(clang-uml ${MAIN_SOURCE_FILE}) +target_compile_options(clang-uml PRIVATE + $<$,$>: + -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-private-field> + $<$: + /MP /W1 /std:c++17 /bigobj /wd4291 /wd4624 /wd4244>) + target_link_libraries(clang-uml ${YAML_CPP_LIBRARIES} ${LIBTOOLING_LIBS} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f8a7e95c..dfba8252 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,3 @@ - if(APPLE) # Without this, clang-uml test cases fail with error saying that # clang cannot find stdarg.h @@ -33,16 +32,18 @@ set(TEST_CASES test_filters test_thread_pool_executor) -foreach(TEST_CASE_NAME ${TEST_CASES}) - add_executable(${TEST_CASE_NAME} - ${TEST_CASE_NAME}.cc catch.h) - target_compile_options(${TEST_CASE_NAME} PRIVATE +foreach(TEST_NAME ${TEST_CASES}) + add_executable(${TEST_NAME} + ${TEST_NAME}.cc + $<$:${TEST_CASE_SOURCES}> + catch.h) + target_compile_options(${TEST_NAME} PRIVATE $<$,$>: -Wno-unused-parameter -Wno-unused-private-field -Wno-unused-variable -Wno-attributes -Wno-nonnull> $<$: - /W1 /std:c++17 /bigobj /wd4624>) - target_link_libraries(${TEST_CASE_NAME} PRIVATE ${CLANG_UML_TEST_LIBRARIES}) + /MP /W1 /std:c++17 /bigobj /wd4624>) + target_link_libraries(${TEST_NAME} PRIVATE ${CLANG_UML_TEST_LIBRARIES}) endforeach() foreach(TEST_CASE_CONFIG ${TEST_CASE_CONFIGS}) @@ -69,6 +70,6 @@ foreach(TEST_CONFIG_YML ${TEST_CONFIG_YMLS}) COPYONLY) endforeach() -foreach(TEST_CASE_NAME ${TEST_CASES}) - add_test(NAME ${TEST_CASE_NAME} COMMAND ${TEST_CASE_NAME}) +foreach(TEST_NAME ${TEST_CASES}) + add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) endforeach() diff --git a/tests/t00018/test_case.h b/tests/t00018/test_case.h index 6da1c833..cea7544b 100644 --- a/tests/t00018/test_case.h +++ b/tests/t00018/test_case.h @@ -18,7 +18,7 @@ TEST_CASE("t00018", "[test-case][class]") { - auto [config, db] = load_config("t00018", {"t00018.cc", "t00018_impl.cc"}); + auto [config, db] = load_config("t00018"); auto diagram = config.diagrams["t00018_class"]; diff --git a/tests/t00048/test_case.h b/tests/t00048/test_case.h index 4376c20e..9bf75981 100644 --- a/tests/t00048/test_case.h +++ b/tests/t00048/test_case.h @@ -18,8 +18,7 @@ TEST_CASE("t00048", "[test-case][class]") { - auto [config, db] = - load_config("t00048", {"t00048.cc", "a_t00048.cc", "b_t00048.cc"}); + auto [config, db] = load_config("t00048"); auto diagram = config.diagrams["t00048_class"]; diff --git a/tests/t20014/test_case.h b/tests/t20014/test_case.h index a54452f1..f7d7aeb9 100644 --- a/tests/t20014/test_case.h +++ b/tests/t20014/test_case.h @@ -18,8 +18,7 @@ TEST_CASE("t20014", "[test-case][sequence]") { - auto [config, db] = load_config( - "t20014", {"t20014.cc", "t20014_a.cc", "t20014_b.cc", "t20014_c.cc"}); + auto [config, db] = load_config("t20014"); auto diagram = config.diagrams["t20014_sequence"]; diff --git a/tests/t40001/test_case.h b/tests/t40001/test_case.h index 8aae49c4..2ed7621f 100644 --- a/tests/t40001/test_case.h +++ b/tests/t40001/test_case.h @@ -18,7 +18,7 @@ TEST_CASE("t40001", "[test-case][include]") { - auto [config, db] = load_config("t40001", {"src/t40001.cc"}); + auto [config, db] = load_config("t40001"); auto diagram = config.diagrams["t40001_include"]; diff --git a/tests/t40002/test_case.h b/tests/t40002/test_case.h index c217af96..0f6451b4 100644 --- a/tests/t40002/test_case.h +++ b/tests/t40002/test_case.h @@ -18,8 +18,7 @@ TEST_CASE("t40002", "[test-case][include]") { - auto [config, db] = load_config( - "t40002", {"src/t40002.cc", "src/lib1/lib1.cc", "src/lib2/lib2.cc"}); + auto [config, db] = load_config("t40002"); auto diagram = config.diagrams["t40002_include"]; diff --git a/tests/t40003/test_case.h b/tests/t40003/test_case.h index 160537b2..e45cbea9 100644 --- a/tests/t40003/test_case.h +++ b/tests/t40003/test_case.h @@ -18,8 +18,7 @@ TEST_CASE("t40003", "[test-case][include]") { - auto [config, db] = load_config( - "t40003", {"src/dependants/t1.cc", "src/dependencies/t2.cc"}); + auto [config, db] = load_config("t40003"); auto diagram = config.diagrams["t40003_include"]; diff --git a/tests/test_cases.cc b/tests/test_cases.cc index dca7d479..42448016 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -18,66 +18,9 @@ #include "test_cases.h" #include "common/generators/plantuml/generator.h" -#include "util/util.h" -#include #include -#include - -namespace clanguml::tests::util { -class TestCaseCompilationDatabase : public clang::tooling::CompilationDatabase { -public: - TestCaseCompilationDatabase(clang::tooling::CompileCommand &&cc) - : compile_commands_{{std::move(cc)}} - { - } - - TestCaseCompilationDatabase( - std::vector &&ccs) - : compile_commands_{std::move(ccs)} - { - } - - virtual ~TestCaseCompilationDatabase() { } - - static std::unique_ptr fromCompileCommand( - clang::tooling::CompileCommand &&cc) - { - return std::make_unique(std::move(cc)); - } - - std::vector getCompileCommands( - clang::StringRef FilePath) const override - { - std::vector ccs; - std::copy_if(begin(compile_commands_), end(compile_commands_), - std::back_inserter(ccs), [&](const auto &cc) { - return clanguml::util::starts_with(cc.Filename, FilePath.str()); - }); - return ccs; - } - - std::vector getAllFiles() const override - { - std::vector files; - std::transform(begin(compile_commands_), end(compile_commands_), - std::back_inserter(files), - [](const auto &cc) { return cc.Filename; }); - return files; - } - - std::vector - getAllCompileCommands() const override - { - return compile_commands_; - } - -private: - std::vector compile_commands_; -}; -} - void inject_diagram_options(std::shared_ptr diagram) { // Inject links config to all test cases @@ -90,10 +33,8 @@ void inject_diagram_options(std::shared_ptr diagram) std::pair> -load_config(const std::string &test_name, const std::vector &tus) +load_config(const std::string &test_name) { - using std::filesystem::path; - auto config = clanguml::config::load(test_name + "/.clang-uml", true); std::string err{}; @@ -101,58 +42,12 @@ load_config(const std::string &test_name, const std::vector &tus) clang::tooling::CompilationDatabase::autoDetectFromDirectory( config.compilation_database_dir(), err); - for (const auto &cc : compilation_database->getAllCompileCommands()) { - if (clanguml::util::ends_with( - cc.Filename, std::string{"/test_cases.cc"})) { - // Create artificial CompileCommand for each source file of a - // specific test case, based on command line options for the - // test_cases.cc translation_unit, which imports specific test - // cases using #include directive - std::vector compile_commands; - for (const auto &tu : tus) { - auto test_case_path = - path{cc.Filename}.parent_path() / test_name / path(tu); - - auto test_case_command = cc; - auto &cline = test_case_command.CommandLine; - // We don't want to worry about all minor warnings in test - // cases during Clang parsing - cline.erase(std::remove(cline.begin(), cline.end(), "-Wall"), - cline.end()); - cline.erase(std::remove(cline.begin(), cline.end(), "-Wextra"), - cline.end()); - cline.erase(std::remove(cline.begin(), cline.end(), "-Werror"), - cline.end()); - - test_case_command.CommandLine.pop_back(); - test_case_command.CommandLine.push_back( - test_case_path.string()); - test_case_command.Filename = test_case_path.string(); - - compile_commands.push_back(std::move(test_case_command)); - } - - auto test_case_db = std::make_unique< - clanguml::tests::util::TestCaseCompilationDatabase>( - std::move(compile_commands)); - - return std::make_pair(std::move(config), std::move(test_case_db)); - } - } - if (!err.empty()) throw std::runtime_error{err}; return std::make_pair(std::move(config), std::move(compilation_database)); } -std::pair> -load_config(const std::string &test_name) -{ - return load_config(test_name, {fmt::format("{}.cc", test_name)}); -} - std::unique_ptr generate_sequence_diagram(clang::tooling::CompilationDatabase &db, std::shared_ptr diagram)