Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Change relative paths to absolute ones when using compile_commands.js…
Browse files Browse the repository at this point in the history
…on file

Signed-off-by: caozhong <zhong.z.cao@intel.com>
  • Loading branch information
CaoZhongZ committed May 7, 2021
1 parent 8cf0799 commit 65ab95a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/conf/load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ namespace color_coded

return line;
}

void make_absolute(std::string &line, std::string &next, const fs::path &base) {
static const std::regex reg_dual {
"\\s*(-I|-isystem|-iquote)\\s*$",
std::regex::optimize
};

std::smatch match;
if (std::regex_search(line, match, reg_dual)) {
next = fs::absolute(next.c_str(), base).string();
} else {
line = make_absolute(line, base);
}
}
}

inline args_t load_compilation_database(std::string const &file, fs::path filename)
Expand Down Expand Up @@ -106,6 +120,7 @@ namespace color_coded
if(compile_commands.empty())
{ return {}; }

const auto base(fs::path{compile_commands[0].Directory});
// Skip argv[0] which is the name of the clang executable.
args_t commands((compile_commands[0].CommandLine.begin() + 1), compile_commands[0].CommandLine.end());

Expand All @@ -114,6 +129,10 @@ namespace color_coded
commands.erase(std::remove(commands.begin(), commands.end(), filename), commands.end());
commands.erase(std::remove(commands.begin(), commands.end(), compile_commands[0].Filename), commands.end());

for (auto i = commands.begin(); i < commands.end() -1; ++ i) {
detail::make_absolute(*i, *(i+1), base);
}

return commands;
}

Expand Down

0 comments on commit 65ab95a

Please sign in to comment.