Index: include/clang/Tooling/CompilationDatabase.h
===================================================================
--- include/clang/Tooling/CompilationDatabase.h	(revision 154319)
+++ include/clang/Tooling/CompilationDatabase.h	(working copy)
@@ -33,6 +33,7 @@
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include <string>
 #include <vector>
@@ -47,8 +48,8 @@
 /// \brief Specifies the working directory and command of a compilation.
 struct CompileCommand {
   CompileCommand() {}
-  CompileCommand(StringRef Directory, ArrayRef<std::string> CommandLine)
-    : Directory(Directory), CommandLine(CommandLine) {}
+  CompileCommand(Twine Directory, ArrayRef<std::string> CommandLine)
+    : Directory(Directory.str()), CommandLine(CommandLine) {}
 
   /// \brief The working directory the command was executed from.
   std::string Directory;
@@ -95,6 +96,27 @@
     StringRef FilePath) const = 0;
 };
 
+/// \brief A compilation database that returns a single compile command line.
+///
+/// Useful when we want a tool to behave more like a compiler invocation.
+class FixedCompilationDatabase {
+public:
+  FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine);
+
+  /// \brief Returns the given compile command.
+  ///
+  /// Will always return a vector with one entry that contains the directory
+  /// and command line specified at construction, independently of the given
+  /// argument.
+  virtual std::vector<CompileCommand> getCompileCommands(
+    StringRef /*FilePath*/) const;
+
+private:
+  /// This is built up to contain a single entry vector to be returned from
+  /// getCompileCommands.
+  std::vector<CompileCommand> CompileCommands;
+};
+
 /// \brief A JSON based compilation database.
 ///
 /// JSON compilation database files must contain a list of JSON objects which
Index: unittests/Tooling/CompilationDatabaseTest.cpp
===================================================================
--- unittests/Tooling/CompilationDatabaseTest.cpp	(revision 154319)
+++ unittests/Tooling/CompilationDatabaseTest.cpp	(working copy)
@@ -219,5 +219,17 @@
   EXPECT_EQ("", Empty[0]);
 }
 
+TEST(FixedCompilationDatabase, ReturnsFixedCommandLine) {
+  std::vector<std::string> CommandLine;
+  CommandLine.push_back("one");
+  CommandLine.push_back("two");
+  FixedCompilationDatabase Database(".", CommandLine);
+  std::vector<CompileCommand> Result =
+    Database.getCompileCommands("nonexistent");
+  ASSERT_EQ(1ul, Result.size());
+  EXPECT_EQ(".", Result[0].Directory);
+  EXPECT_EQ(CommandLine, Result[0].CommandLine);
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Tooling/CompilationDatabase.cpp
===================================================================
--- lib/Tooling/CompilationDatabase.cpp	(revision 154319)
+++ lib/Tooling/CompilationDatabase.cpp	(working copy)
@@ -124,6 +124,16 @@
   return Database.take();
 }
 
+FixedCompilationDatabase::
+FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine) {
+  CompileCommands.push_back(CompileCommand(Directory, CommandLine));
+}
+
+std::vector<CompileCommand>
+FixedCompilationDatabase::getCompileCommands(StringRef /*FilePath*/) const {
+  return CompileCommands;
+}
+
 JSONCompilationDatabase *
 JSONCompilationDatabase::loadFromFile(StringRef FilePath,
                                       std::string &ErrorMessage) {
