diff --git a/clang/lib/Tooling/CompilationDatabase.cpp b/clang/lib/Tooling/CompilationDatabase.cpp index 6e941802dc2a..4149cda3787c 100644 --- a/clang/lib/Tooling/CompilationDatabase.cpp +++ b/clang/lib/Tooling/CompilationDatabase.cpp @@ -49,14 +49,19 @@ static CompilationDatabase * findCompilationDatabaseFromDirectory(StringRef Directory, std::string &ErrorMessage) { std::stringstream ErrorStream; + bool HasErrorMessage = false; while (!Directory.empty()) { std::string LoadErrorMessage; if (CompilationDatabase *DB = CompilationDatabase::loadFromDirectory(Directory, LoadErrorMessage)) return DB; - ErrorStream << "No compilation database found in " << Directory.str() - << "\n" << LoadErrorMessage; + + if (!HasErrorMessage) { + ErrorStream << "No compilation database found in " << Directory.str() + << " or any parent directory\n" << LoadErrorMessage; + HasErrorMessage = true; + } Directory = llvm::sys::path::parent_path(Directory); }