From 1f0c1e922ff068912b5bc7e31a32def29e19141e Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Tue, 31 Oct 2017 15:43:27 -0700 Subject: [PATCH] Fix compile_commands.json parsing when filename is absolute. Some compile_commands.json generators will emit absolute paths for the filename, such as cmake. --- src/project.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/project.cc b/src/project.cc index 26bcc462..86c06faf 100644 --- a/src/project.cc +++ b/src/project.cc @@ -272,7 +272,11 @@ std::vector LoadCompilationEntriesFromDirectory( clang_time.Pause(); // TODO: don't call clang::ToString in this block. our_time.Resume(); - std::string absolute_filename = directory + "/" + relative_filename; + std::string absolute_filename; + if (!relative_filename.empty() && relative_filename[0] == '/') + absolute_filename = relative_filename; + else + absolute_filename = directory + "/" + relative_filename; entry.file = NormalizePathWithTestOptOut(absolute_filename); entry.directory = directory;