Reverted custom compilation database class to default
This commit is contained in:
@@ -22,13 +22,12 @@ else(MSVC)
|
|||||||
add_library(clang-umllib OBJECT ${SOURCES})
|
add_library(clang-umllib OBJECT ${SOURCES})
|
||||||
endif(MSVC)
|
endif(MSVC)
|
||||||
|
|
||||||
target_compile_options(clang-umllib PUBLIC
|
target_compile_options(clang-umllib PRIVATE
|
||||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
||||||
-Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-private-field>
|
-Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-private-field>
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:
|
$<$<CXX_COMPILER_ID:MSVC>:
|
||||||
/W1 /std:c++17 /bigobj /wd4291 /wd4624 /wd4244 /NODEFAULTLIB:MSVCRT
|
/MP /W1 /std:c++17 /bigobj /wd4291 /wd4624 /wd4244>)
|
||||||
/NODEFAULTLIB:MSVCRTD>)
|
target_compile_definitions(clang-umllib PRIVATE
|
||||||
target_compile_definitions(clang-umllib PUBLIC
|
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:
|
$<$<CXX_COMPILER_ID:MSVC>:
|
||||||
-DLLVM_FORCE_USE_OLD_TOOLCHAIN>)
|
-DLLVM_FORCE_USE_OLD_TOOLCHAIN>)
|
||||||
|
|
||||||
@@ -37,6 +36,12 @@ target_compile_definitions(clang-umllib PUBLIC
|
|||||||
#
|
#
|
||||||
add_executable(clang-uml ${MAIN_SOURCE_FILE})
|
add_executable(clang-uml ${MAIN_SOURCE_FILE})
|
||||||
|
|
||||||
|
target_compile_options(clang-uml PRIVATE
|
||||||
|
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
||||||
|
-Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-private-field>
|
||||||
|
$<$<CXX_COMPILER_ID:MSVC>:
|
||||||
|
/MP /W1 /std:c++17 /bigobj /wd4291 /wd4624 /wd4244>)
|
||||||
|
|
||||||
target_link_libraries(clang-uml
|
target_link_libraries(clang-uml
|
||||||
${YAML_CPP_LIBRARIES}
|
${YAML_CPP_LIBRARIES}
|
||||||
${LIBTOOLING_LIBS}
|
${LIBTOOLING_LIBS}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
# Without this, clang-uml test cases fail with error saying that
|
# Without this, clang-uml test cases fail with error saying that
|
||||||
# clang cannot find stdarg.h
|
# clang cannot find stdarg.h
|
||||||
@@ -33,16 +32,18 @@ set(TEST_CASES
|
|||||||
test_filters
|
test_filters
|
||||||
test_thread_pool_executor)
|
test_thread_pool_executor)
|
||||||
|
|
||||||
foreach(TEST_CASE_NAME ${TEST_CASES})
|
foreach(TEST_NAME ${TEST_CASES})
|
||||||
add_executable(${TEST_CASE_NAME}
|
add_executable(${TEST_NAME}
|
||||||
${TEST_CASE_NAME}.cc catch.h)
|
${TEST_NAME}.cc
|
||||||
target_compile_options(${TEST_CASE_NAME} PRIVATE
|
$<$<STREQUAL:${TEST_NAME},test_cases>:${TEST_CASE_SOURCES}>
|
||||||
|
catch.h)
|
||||||
|
target_compile_options(${TEST_NAME} PRIVATE
|
||||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
|
||||||
-Wno-unused-parameter -Wno-unused-private-field -Wno-unused-variable
|
-Wno-unused-parameter -Wno-unused-private-field -Wno-unused-variable
|
||||||
-Wno-attributes -Wno-nonnull>
|
-Wno-attributes -Wno-nonnull>
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:
|
$<$<CXX_COMPILER_ID:MSVC>:
|
||||||
/W1 /std:c++17 /bigobj /wd4624>)
|
/MP /W1 /std:c++17 /bigobj /wd4624>)
|
||||||
target_link_libraries(${TEST_CASE_NAME} PRIVATE ${CLANG_UML_TEST_LIBRARIES})
|
target_link_libraries(${TEST_NAME} PRIVATE ${CLANG_UML_TEST_LIBRARIES})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
foreach(TEST_CASE_CONFIG ${TEST_CASE_CONFIGS})
|
foreach(TEST_CASE_CONFIG ${TEST_CASE_CONFIGS})
|
||||||
@@ -69,6 +70,6 @@ foreach(TEST_CONFIG_YML ${TEST_CONFIG_YMLS})
|
|||||||
COPYONLY)
|
COPYONLY)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
foreach(TEST_CASE_NAME ${TEST_CASES})
|
foreach(TEST_NAME ${TEST_CASES})
|
||||||
add_test(NAME ${TEST_CASE_NAME} COMMAND ${TEST_CASE_NAME})
|
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
TEST_CASE("t00018", "[test-case][class]")
|
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"];
|
auto diagram = config.diagrams["t00018_class"];
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
TEST_CASE("t00048", "[test-case][class]")
|
TEST_CASE("t00048", "[test-case][class]")
|
||||||
{
|
{
|
||||||
auto [config, db] =
|
auto [config, db] = load_config("t00048");
|
||||||
load_config("t00048", {"t00048.cc", "a_t00048.cc", "b_t00048.cc"});
|
|
||||||
|
|
||||||
auto diagram = config.diagrams["t00048_class"];
|
auto diagram = config.diagrams["t00048_class"];
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
TEST_CASE("t20014", "[test-case][sequence]")
|
TEST_CASE("t20014", "[test-case][sequence]")
|
||||||
{
|
{
|
||||||
auto [config, db] = load_config(
|
auto [config, db] = load_config("t20014");
|
||||||
"t20014", {"t20014.cc", "t20014_a.cc", "t20014_b.cc", "t20014_c.cc"});
|
|
||||||
|
|
||||||
auto diagram = config.diagrams["t20014_sequence"];
|
auto diagram = config.diagrams["t20014_sequence"];
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
TEST_CASE("t40001", "[test-case][include]")
|
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"];
|
auto diagram = config.diagrams["t40001_include"];
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
TEST_CASE("t40002", "[test-case][include]")
|
TEST_CASE("t40002", "[test-case][include]")
|
||||||
{
|
{
|
||||||
auto [config, db] = load_config(
|
auto [config, db] = load_config("t40002");
|
||||||
"t40002", {"src/t40002.cc", "src/lib1/lib1.cc", "src/lib2/lib2.cc"});
|
|
||||||
|
|
||||||
auto diagram = config.diagrams["t40002_include"];
|
auto diagram = config.diagrams["t40002_include"];
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
TEST_CASE("t40003", "[test-case][include]")
|
TEST_CASE("t40003", "[test-case][include]")
|
||||||
{
|
{
|
||||||
auto [config, db] = load_config(
|
auto [config, db] = load_config("t40003");
|
||||||
"t40003", {"src/dependants/t1.cc", "src/dependencies/t2.cc"});
|
|
||||||
|
|
||||||
auto diagram = config.diagrams["t40003_include"];
|
auto diagram = config.diagrams["t40003_include"];
|
||||||
|
|
||||||
|
|||||||
@@ -18,66 +18,9 @@
|
|||||||
|
|
||||||
#include "test_cases.h"
|
#include "test_cases.h"
|
||||||
#include "common/generators/plantuml/generator.h"
|
#include "common/generators/plantuml/generator.h"
|
||||||
#include "util/util.h"
|
|
||||||
|
|
||||||
#include <clang/Tooling/CompilationDatabase.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace clanguml::tests::util {
|
|
||||||
class TestCaseCompilationDatabase : public clang::tooling::CompilationDatabase {
|
|
||||||
public:
|
|
||||||
TestCaseCompilationDatabase(clang::tooling::CompileCommand &&cc)
|
|
||||||
: compile_commands_{{std::move(cc)}}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TestCaseCompilationDatabase(
|
|
||||||
std::vector<clang::tooling::CompileCommand> &&ccs)
|
|
||||||
: compile_commands_{std::move(ccs)}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~TestCaseCompilationDatabase() { }
|
|
||||||
|
|
||||||
static std::unique_ptr<CompilationDatabase> fromCompileCommand(
|
|
||||||
clang::tooling::CompileCommand &&cc)
|
|
||||||
{
|
|
||||||
return std::make_unique<TestCaseCompilationDatabase>(std::move(cc));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<clang::tooling::CompileCommand> getCompileCommands(
|
|
||||||
clang::StringRef FilePath) const override
|
|
||||||
{
|
|
||||||
std::vector<clang::tooling::CompileCommand> 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<std::string> getAllFiles() const override
|
|
||||||
{
|
|
||||||
std::vector<std::string> files;
|
|
||||||
std::transform(begin(compile_commands_), end(compile_commands_),
|
|
||||||
std::back_inserter(files),
|
|
||||||
[](const auto &cc) { return cc.Filename; });
|
|
||||||
return files;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<clang::tooling::CompileCommand>
|
|
||||||
getAllCompileCommands() const override
|
|
||||||
{
|
|
||||||
return compile_commands_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<clang::tooling::CompileCommand> compile_commands_;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void inject_diagram_options(std::shared_ptr<clanguml::config::diagram> diagram)
|
void inject_diagram_options(std::shared_ptr<clanguml::config::diagram> diagram)
|
||||||
{
|
{
|
||||||
// Inject links config to all test cases
|
// Inject links config to all test cases
|
||||||
@@ -90,10 +33,8 @@ void inject_diagram_options(std::shared_ptr<clanguml::config::diagram> diagram)
|
|||||||
|
|
||||||
std::pair<clanguml::config::config,
|
std::pair<clanguml::config::config,
|
||||||
std::unique_ptr<clang::tooling::CompilationDatabase>>
|
std::unique_ptr<clang::tooling::CompilationDatabase>>
|
||||||
load_config(const std::string &test_name, const std::vector<std::string> &tus)
|
load_config(const std::string &test_name)
|
||||||
{
|
{
|
||||||
using std::filesystem::path;
|
|
||||||
|
|
||||||
auto config = clanguml::config::load(test_name + "/.clang-uml", true);
|
auto config = clanguml::config::load(test_name + "/.clang-uml", true);
|
||||||
|
|
||||||
std::string err{};
|
std::string err{};
|
||||||
@@ -101,58 +42,12 @@ load_config(const std::string &test_name, const std::vector<std::string> &tus)
|
|||||||
clang::tooling::CompilationDatabase::autoDetectFromDirectory(
|
clang::tooling::CompilationDatabase::autoDetectFromDirectory(
|
||||||
config.compilation_database_dir(), err);
|
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<clang::tooling::CompileCommand> 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())
|
if (!err.empty())
|
||||||
throw std::runtime_error{err};
|
throw std::runtime_error{err};
|
||||||
|
|
||||||
return std::make_pair(std::move(config), std::move(compilation_database));
|
return std::make_pair(std::move(config), std::move(compilation_database));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<clanguml::config::config,
|
|
||||||
std::unique_ptr<clang::tooling::CompilationDatabase>>
|
|
||||||
load_config(const std::string &test_name)
|
|
||||||
{
|
|
||||||
return load_config(test_name, {fmt::format("{}.cc", test_name)});
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<clanguml::sequence_diagram::model::diagram>
|
std::unique_ptr<clanguml::sequence_diagram::model::diagram>
|
||||||
generate_sequence_diagram(clang::tooling::CompilationDatabase &db,
|
generate_sequence_diagram(clang::tooling::CompilationDatabase &db,
|
||||||
std::shared_ptr<clanguml::config::diagram> diagram)
|
std::shared_ptr<clanguml::config::diagram> diagram)
|
||||||
|
|||||||
Reference in New Issue
Block a user