class CompilationDatabase

Declaration

class CompilationDatabase { /* full declaration omitted */ };

Description

Interface for compilation databases. A compilation database allows the user to retrieve compile command lines for the files in a project. Many implementations are enumerable, allowing all command lines to be retrieved. These can be used to run clang tools over a subset of the files in a project.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:87

Method Overview

Methods

static std::unique_ptr<CompilationDatabase>
autoDetectFromDirectory(llvm::StringRef SourceDir,
                        std::string& ErrorMessage)

Description

Tries to detect a compilation database location and load it. Looks for a compilation database in directory 'SourceDir' and all its parent paths by calling loadFromDirectory.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:118

Parameters

llvm::StringRef SourceDir
std::string& ErrorMessage

static std::unique_ptr<CompilationDatabase>
autoDetectFromSource(llvm::StringRef SourceFile,
                     std::string& ErrorMessage)

Description

Tries to detect a compilation database location and load it. Looks for a compilation database in all parent paths of file 'SourceFile' by calling loadFromDirectory.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:111

Parameters

llvm::StringRef SourceFile
std::string& ErrorMessage

virtual std::vector<CompileCommand>
getAllCompileCommands() const

Description

Returns all compile commands for all the files in the compilation database. FIXME: Add a layer in Tooling that provides an interface to run a tool over all files in a compilation database. Not all build systems have the ability to provide a feasible implementation for \c getAllCompileCommands. By default, this is implemented in terms of getAllFiles() and getCompileCommands(). Subclasses may override this for efficiency.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:147

virtual std::vector<std::string> getAllFiles()
    const

Description

Returns the list of all files available in the compilation database. By default, returns nothing. Implementations should override this if they can enumerate their source files.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:136

virtual std::vector<CompileCommand>
getCompileCommands(llvm::StringRef FilePath) const

Description

Returns all compile commands in which the specified file was compiled. This includes compile commands that span multiple source files. For example, consider a project with the following compilations: $ clang++ -o test a.cc b.cc t.cc $ clang++ -o production a.cc b.cc -DPRODUCTION A compilation database representing the project would return both command lines for a.cc and b.cc and only the first command line for t.cc.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:129

Parameters

llvm::StringRef FilePath

static std::unique_ptr<CompilationDatabase>
loadFromDirectory(llvm::StringRef BuildDirectory,
                  std::string& ErrorMessage)

Description

Loads a compilation database from a build directory. Looks at the specified 'BuildDirectory' and creates a compilation database that allows to query compile commands for source files in the corresponding source tree. Returns NULL and sets ErrorMessage if we were not able to build up a compilation database for the build directory. FIXME: Currently only supports JSON compilation databases, which are named 'compile_commands.json' in the given directory. Extend this for other build types (like ninja build files).

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:104

Parameters

llvm::StringRef BuildDirectory
std::string& ErrorMessage

virtual ~CompilationDatabase()

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:89