From e30d46e20ee71d57e09f83fafa39b7e464efe110 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 Jun 2012 19:59:33 +0200 Subject: [PATCH 1/3] Use full paths in compile_commands.json for out of source builds. Clang tooling requires that paths in the directory and file JSON fields are relative to the directory field, but clang doesn't normalize the paths already. The result is that clang doesn't find the relevant entry for files which begin with ../. --- Source/cmGlobalNinjaGenerator.cxx | 11 ++++++++++- Source/cmNinjaTargetGenerator.cxx | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 40348e673..f21cddbb2 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -644,13 +644,22 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand( *this->CompileCommandsStream << "," << std::endl; } + std::string sourceFileName = sourceFile; + if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str())) + { + sourceFileName = cmSystemTools::CollapseFullPath( + sourceFileName.c_str(), + this->GetCMakeInstance()->GetHomeOutputDirectory()); + } + + *this->CompileCommandsStream << "\n{\n" << " \"directory\": \"" << cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n" << " \"command\": \"" << cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n" << " \"file\": \"" - << cmGlobalGenerator::EscapeJSON(sourceFile) << "\"\n" + << cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n" << "}"; } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index a362d1362..0c8ae8d6a 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -492,6 +492,15 @@ cmNinjaTargetGenerator std::string escapedSourceFileName = this->LocalGenerator->ConvertToOutputFormat( sourceFileName.c_str(), cmLocalGenerator::SHELL); + + if (!cmSystemTools::FileIsFullPath(escapedSourceFileName.c_str())) + { + escapedSourceFileName = cmSystemTools::CollapseFullPath( + escapedSourceFileName.c_str(), + this->GetGlobalGenerator()->GetCMakeInstance()->GetHomeOutputDirectory()); + } + + compileObjectVars.Source = escapedSourceFileName.c_str(); compileObjectVars.Object = objectFileName.c_str(); compileObjectVars.Flags = vars["FLAGS"].c_str(); From f9383a9898b915fb836c8b7fe0877acc6aec78c6 Mon Sep 17 00:00:00 2001 From: David Cole Date: Tue, 19 Jun 2012 14:49:13 -0400 Subject: [PATCH 2/3] STYLE: Fix line length, remove extra blank line --- Source/cmNinjaTargetGenerator.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 0c8ae8d6a..106332892 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -497,10 +497,10 @@ cmNinjaTargetGenerator { escapedSourceFileName = cmSystemTools::CollapseFullPath( escapedSourceFileName.c_str(), - this->GetGlobalGenerator()->GetCMakeInstance()->GetHomeOutputDirectory()); + this->GetGlobalGenerator()->GetCMakeInstance()-> + GetHomeOutputDirectory()); } - compileObjectVars.Source = escapedSourceFileName.c_str(); compileObjectVars.Object = objectFileName.c_str(); compileObjectVars.Flags = vars["FLAGS"].c_str(); From ca403b8c436e25e2fe5de5144fecf7aef8b5de78 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 20 Jun 2012 22:47:41 +0200 Subject: [PATCH 3/3] Construct the full path before escaping it. Should fix some dashboard errors. --- Source/cmNinjaTargetGenerator.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 106332892..e13006555 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -489,11 +489,10 @@ cmNinjaTargetGenerator cmLocalGenerator::RuleVariables compileObjectVars; std::string lang = language; compileObjectVars.Language = lang.c_str(); - std::string escapedSourceFileName = - this->LocalGenerator->ConvertToOutputFormat( - sourceFileName.c_str(), cmLocalGenerator::SHELL); - if (!cmSystemTools::FileIsFullPath(escapedSourceFileName.c_str())) + std::string escapedSourceFileName = sourceFileName; + + if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str())) { escapedSourceFileName = cmSystemTools::CollapseFullPath( escapedSourceFileName.c_str(), @@ -501,6 +500,10 @@ cmNinjaTargetGenerator GetHomeOutputDirectory()); } + escapedSourceFileName = + this->LocalGenerator->ConvertToOutputFormat( + escapedSourceFileName.c_str(), cmLocalGenerator::SHELL); + compileObjectVars.Source = escapedSourceFileName.c_str(); compileObjectVars.Object = objectFileName.c_str(); compileObjectVars.Flags = vars["FLAGS"].c_str();