Added handling of query-driver target and using default driver for '.'
This commit is contained in:
@@ -94,9 +94,12 @@ void compilation_database::adjust_compilation_database(
|
|||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
if (config().query_driver && !config().query_driver().empty()) {
|
if (config().query_driver && !config().query_driver().empty()) {
|
||||||
for (auto &compile_command : commands) {
|
for (auto &compile_command : commands) {
|
||||||
|
auto argv0 = config().query_driver() == "."
|
||||||
|
? compile_command.CommandLine.at(0)
|
||||||
|
: config().query_driver();
|
||||||
|
|
||||||
util::query_driver_output_extractor extractor{
|
util::query_driver_output_extractor extractor{
|
||||||
config().query_driver(),
|
argv0, guess_language_from_filename(compile_command.Filename)};
|
||||||
guess_language_from_filename(compile_command.Filename)};
|
|
||||||
|
|
||||||
extractor.execute();
|
extractor.execute();
|
||||||
|
|
||||||
@@ -109,6 +112,12 @@ void compilation_database::adjust_compilation_database(
|
|||||||
compile_command.CommandLine.insert(
|
compile_command.CommandLine.insert(
|
||||||
compile_command.CommandLine.begin() + 1,
|
compile_command.CommandLine.begin() + 1,
|
||||||
system_header_args.begin(), system_header_args.end());
|
system_header_args.begin(), system_header_args.end());
|
||||||
|
|
||||||
|
if (!extractor.target().empty()) {
|
||||||
|
compile_command.CommandLine.insert(
|
||||||
|
compile_command.CommandLine.begin() + 1,
|
||||||
|
fmt::format("--target={}", extractor.target()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ void query_driver_output_extractor::execute()
|
|||||||
|
|
||||||
system_include_paths_.clear();
|
system_include_paths_.clear();
|
||||||
extract_system_include_paths(driver_output);
|
extract_system_include_paths(driver_output);
|
||||||
|
extract_target(driver_output);
|
||||||
|
|
||||||
if (system_include_paths_.empty()) {
|
if (system_include_paths_.empty()) {
|
||||||
throw query_driver_no_paths(fmt::format(
|
throw query_driver_no_paths(fmt::format(
|
||||||
@@ -55,6 +56,20 @@ void query_driver_output_extractor::execute()
|
|||||||
fmt::join(system_include_paths_, ","));
|
fmt::join(system_include_paths_, ","));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void query_driver_output_extractor::extract_target(const std::string &output)
|
||||||
|
{
|
||||||
|
std::istringstream f(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(f, line)) {
|
||||||
|
line = trim(line);
|
||||||
|
if (util::starts_with(line, std::string{"Target: "})) {
|
||||||
|
target_ = line.substr(strlen("Target: "));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void query_driver_output_extractor::extract_system_include_paths(
|
void query_driver_output_extractor::extract_system_include_paths(
|
||||||
const std::string &output)
|
const std::string &output)
|
||||||
{
|
{
|
||||||
@@ -84,4 +99,8 @@ query_driver_output_extractor::system_include_paths() const
|
|||||||
return system_include_paths_;
|
return system_include_paths_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string &query_driver_output_extractor::target() const
|
||||||
|
{
|
||||||
|
return target_;
|
||||||
|
}
|
||||||
} // namespace clanguml::util
|
} // namespace clanguml::util
|
||||||
@@ -35,13 +35,18 @@ public:
|
|||||||
|
|
||||||
void execute();
|
void execute();
|
||||||
|
|
||||||
|
void extract_target(const std::string &output);
|
||||||
|
|
||||||
void extract_system_include_paths(const std::string &output);
|
void extract_system_include_paths(const std::string &output);
|
||||||
|
|
||||||
const std::vector<std::string> &system_include_paths() const;
|
const std::vector<std::string> &system_include_paths() const;
|
||||||
|
|
||||||
|
const std::string &target() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string command_;
|
const std::string command_;
|
||||||
const std::string language_;
|
const std::string language_;
|
||||||
|
std::string target_;
|
||||||
std::vector<std::string> system_include_paths_;
|
std::vector<std::string> system_include_paths_;
|
||||||
};
|
};
|
||||||
} // namespace clanguml::util
|
} // namespace clanguml::util
|
||||||
@@ -39,6 +39,7 @@ TEST_CASE("Test compilation_database should work", "[unit-test]")
|
|||||||
using clanguml::common::model::access_t;
|
using clanguml::common::model::access_t;
|
||||||
using clanguml::common::model::relationship_t;
|
using clanguml::common::model::relationship_t;
|
||||||
using clanguml::util::contains;
|
using clanguml::util::contains;
|
||||||
|
using std::filesystem::path;
|
||||||
|
|
||||||
auto cfg =
|
auto cfg =
|
||||||
clanguml::config::load("./test_compilation_database_data/config.yml");
|
clanguml::config::load("./test_compilation_database_data/config.yml");
|
||||||
@@ -51,12 +52,19 @@ TEST_CASE("Test compilation_database should work", "[unit-test]")
|
|||||||
auto all_files = db->getAllFiles();
|
auto all_files = db->getAllFiles();
|
||||||
|
|
||||||
REQUIRE(all_files.size() == 3);
|
REQUIRE(all_files.size() == 3);
|
||||||
REQUIRE(all_files.at(0) ==
|
REQUIRE(contains(all_files,
|
||||||
"src/class_diagram/generators/json/class_diagram_generator.cc");
|
path("src/class_diagram/generators/json/class_diagram_generator.cc")
|
||||||
REQUIRE(all_files.at(1) ==
|
.make_preferred()
|
||||||
"src/class_diagram/generators/plantuml/"
|
.string()));
|
||||||
"class_diagram_generator.cc");
|
REQUIRE(contains(all_files,
|
||||||
REQUIRE(all_files.at(2) == "src/class_diagram/model/class.cc");
|
path("src/class_diagram/generators/plantuml/"
|
||||||
|
"class_diagram_generator.cc")
|
||||||
|
.make_preferred()
|
||||||
|
.string()));
|
||||||
|
REQUIRE(contains(all_files,
|
||||||
|
path("src/class_diagram/model/class.cc")
|
||||||
|
.make_preferred()
|
||||||
|
.string()));
|
||||||
|
|
||||||
auto ccs = db->getAllCompileCommands();
|
auto ccs = db->getAllCompileCommands();
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,13 @@ COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
|
|||||||
|
|
||||||
extractor.extract_system_include_paths(output);
|
extractor.extract_system_include_paths(output);
|
||||||
|
|
||||||
|
extractor.extract_target(output);
|
||||||
|
|
||||||
std::vector<std::string> expected = {
|
std::vector<std::string> expected = {
|
||||||
"/usr/lib/gcc/x86_64-linux-gnu/11/include", "/usr/local/include",
|
"/usr/lib/gcc/x86_64-linux-gnu/11/include", "/usr/local/include",
|
||||||
"/usr/include/x86_64-linux-gnu", "/usr/include"};
|
"/usr/include/x86_64-linux-gnu", "/usr/include"};
|
||||||
|
|
||||||
REQUIRE(extractor.system_include_paths() == expected);
|
REQUIRE(extractor.system_include_paths() == expected);
|
||||||
|
|
||||||
|
REQUIRE(extractor.target() == "x86_64-linux-gnu");
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user