Skip to content

Commit 3b716e1

Browse files
authored
Merge pull request #516 from bruntib/fix_cpp_parser_relative_path
Fix C++ parser relative path
2 parents a97086d + 04826d2 commit 3b716e1

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

plugins/cpp/parser/src/cppparser.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ namespace cc
4242
namespace parser
4343
{
4444

45+
namespace fs = boost::filesystem;
46+
4547
class VisitorActionFactory : public clang::tooling::FrontendActionFactory
4648
{
4749
public:
@@ -157,7 +159,7 @@ bool CppParser::isSourceFile(const std::string& file_) const
157159
const std::vector<std::string> cppExts{
158160
".c", ".cc", ".cpp", ".cxx", ".o", ".so", ".a"};
159161

160-
std::string ext = boost::filesystem::extension(file_);
162+
std::string ext = fs::extension(file_);
161163
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
162164

163165
return std::find(cppExts.begin(), cppExts.end(), ext) != cppExts.end();
@@ -188,16 +190,13 @@ std::map<std::string, std::string> CppParser::extractInputOutputs(
188190
{
189191
if (state == OParam)
190192
{
191-
boost::filesystem::path absolutePath =
192-
boost::filesystem::absolute(arg, command_.Directory);
193-
193+
fs::path absolutePath = fs::absolute(arg, command_.Directory);
194194
output = absolutePath.native();
195195
state = None;
196196
}
197197
else if (isSourceFile(arg) && !isNonSourceFlag(arg))
198198
{
199-
boost::filesystem::path absolutePath =
200-
boost::filesystem::absolute(arg, command_.Directory);
199+
fs::path absolutePath = fs::absolute(arg, command_.Directory);
201200
sources.insert(absolutePath.native());
202201
}
203202
else if (arg == "-c")
@@ -210,7 +209,7 @@ std::map<std::string, std::string> CppParser::extractInputOutputs(
210209
{
211210
for (const std::string& src : sources)
212211
{
213-
std::string extension = boost::filesystem::extension(src);
212+
std::string extension = fs::extension(src);
214213
inToOut[src] = src.substr(0, src.size() - extension.size() - 1) + ".o";
215214
}
216215
}
@@ -233,7 +232,7 @@ model::BuildActionPtr CppParser::addBuildAction(
233232

234233
model::BuildActionPtr buildAction(new model::BuildAction);
235234

236-
std::string extension = boost::filesystem::extension(command_.Filename);
235+
std::string extension = fs::extension(command_.Filename);
237236

238237
buildAction->command = boost::algorithm::join(command_.CommandLine, " ");
239238
buildAction->type
@@ -313,7 +312,9 @@ int CppParser::parseWorker(const clang::tooling::CompileCommand& command_)
313312

314313
if (!compilationDb)
315314
{
316-
LOG(error) << "Failed to create compilation database from command-line. " << compilationDbLoadError;
315+
LOG(error)
316+
<< "Failed to create compilation database from command-line. "
317+
<< compilationDbLoadError;
317318
return 1;
318319
}
319320

@@ -323,10 +324,15 @@ int CppParser::parseWorker(const clang::tooling::CompileCommand& command_)
323324

324325
//--- Start the tool ---//
325326

327+
fs::path sourceFullPath(command_.Filename);
328+
if (!sourceFullPath.is_absolute())
329+
sourceFullPath = fs::path(command_.Directory) / command_.Filename;
330+
326331
VisitorActionFactory factory(_ctx);
327-
clang::tooling::ClangTool tool(*compilationDb, command_.Filename);
332+
clang::tooling::ClangTool tool(*compilationDb, sourceFullPath.string());
328333

329-
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts = new clang::DiagnosticOptions();
334+
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts
335+
= new clang::DiagnosticOptions();
330336
DiagnosticMessageHandler diagMsgHandler(diagOpts.get(), _ctx.srcMgr, _ctx.db);
331337
tool.setDiagnosticConsumer(&diagMsgHandler);
332338

@@ -427,7 +433,7 @@ std::vector<std::vector<std::string>> CppParser::createCleanupOrder()
427433
{
428434
order[index].push_back(item.first);
429435
}
430-
436+
431437
fileNameToVertex.clear();
432438

433439
LOG(debug) << "[cppparser] Circular dependency detected.";
@@ -475,7 +481,7 @@ void CppParser::markModifiedFiles()
475481
// Detect changed translation units through the build actions.
476482
for (const std::string& input
477483
: _ctx.options["input"].as<std::vector<std::string>>())
478-
if (boost::filesystem::is_regular_file(input))
484+
if (fs::is_regular_file(input))
479485
{
480486
std::string errorMsg;
481487

@@ -687,7 +693,7 @@ bool CppParser::parse()
687693

688694
for (const std::string& input
689695
: _ctx.options["input"].as<std::vector<std::string>>())
690-
if (boost::filesystem::is_regular_file(input))
696+
if (fs::is_regular_file(input))
691697
success
692698
= success && parseByJson(input, _ctx.options["jobs"].as<int>());
693699

@@ -709,7 +715,7 @@ void CppParser::markByInclusion(model::FilePtr file_)
709715
{
710716
auto inclusions = _ctx.db->query<model::CppHeaderInclusion>(
711717
odb::query<model::CppHeaderInclusion>::included == file_->id);
712-
718+
713719
for (auto inc : inclusions)
714720
{
715721
model::FilePtr loaded = inc.includer.load();

0 commit comments

Comments
 (0)