diff options
-rw-r--r-- | lib/Tooling/CommandLineClangTool.cpp | 7 | ||||
-rw-r--r-- | lib/Tooling/CompilationDatabase.cpp | 2 | ||||
-rw-r--r-- | lib/Tooling/CustomCompilationDatabase.h | 9 | ||||
-rw-r--r-- | lib/Tooling/CustomToolInit.h | 35 |
4 files changed, 50 insertions, 3 deletions
diff --git a/lib/Tooling/CommandLineClangTool.cpp b/lib/Tooling/CommandLineClangTool.cpp index 8da2a335a5..32b2ac2857 100644 --- a/lib/Tooling/CommandLineClangTool.cpp +++ b/lib/Tooling/CommandLineClangTool.cpp @@ -25,6 +25,10 @@ #include "clang/Tooling/CommandLineClangTool.h" #include "clang/Tooling/Tooling.h" +#ifdef USE_CUSTOM_TOOL_INIT +#include "CustomToolInit.h" +#endif + using namespace clang::tooling; using namespace llvm; @@ -58,6 +62,9 @@ CommandLineClangTool::CommandLineClangTool() : } void CommandLineClangTool::initialize(int argc, const char **argv) { +#ifdef USE_CUSTOM_TOOL_INIT + customToolInit(argc, argv); +#endif Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc, argv)); cl::ParseCommandLineOptions(argc, argv); if (!Compilations) { diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 802a4c3ea4..3139cc21bb 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -130,7 +130,7 @@ static CompilationDatabase * findCompilationDatabaseFromDirectory(StringRef Directory) { #ifdef USE_CUSTOM_COMPILATION_DATABASE if (CompilationDatabase *DB = - ::findCompilationDatabaseForDirectory(Directory)) + ::clang::tooling::findCompilationDatabaseForDirectory(Directory)) return DB; #endif while (!Directory.empty()) { diff --git a/lib/Tooling/CustomCompilationDatabase.h b/lib/Tooling/CustomCompilationDatabase.h index a24915a08f..b375f8d256 100644 --- a/lib/Tooling/CustomCompilationDatabase.h +++ b/lib/Tooling/CustomCompilationDatabase.h @@ -19,14 +19,14 @@ // custom compilation databases and make enabling that a build option. // //===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_TOOLING_CUSTOM_COMPILATION_DATABASE_H +#define LLVM_CLANG_TOOLING_CUSTOM_COMPILATION_DATABASE_H #include "llvm/ADT/StringRef.h" namespace clang { namespace tooling { class CompilationDatabase; -} -} /// \brief Returns a CompilationDatabase for the given \c Directory. /// @@ -35,3 +35,8 @@ class CompilationDatabase; /// parents. If a compilation database cannot be found or loaded, returns NULL. clang::tooling::CompilationDatabase *findCompilationDatabaseForDirectory( llvm::StringRef Directory); + +} // namespace tooling +} // namespace clang + +#endif // LLVM_CLANG_TOOLING_CUSTOM_COMPILATION_DATABASE_H diff --git a/lib/Tooling/CustomToolInit.h b/lib/Tooling/CustomToolInit.h new file mode 100644 index 0000000000..745edbe484 --- /dev/null +++ b/lib/Tooling/CustomToolInit.h @@ -0,0 +1,35 @@ +//===--- CustomToolInit.h -------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains a hook to supply a custom tool initialization routine. +// +// The mechanism can be used by IDEs or non-public code bases to integrate with +// their build system. Currently we support statically linking in an +// implementation of \c customToolInit and enabling it with +// -DUSE_CUSTOM_TOOL_INIT when compiling the Tooling library. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_TOOLING_CUSTOM_TOOL_INIT_H +#define LLVM_CLANG_TOOLING_CUSTOM_TOOL_INIT_H + +namespace clang { +namespace tooling { + +/// \brief Performs a custom initialization of a tool. +/// +/// This function provides a hook for custom initialization of a clang tool. It +/// receives command-line arguments and can change them if needed. +/// If the initialization fails (say, custom command-line arguments are invalid) +/// this function should terminate the process. +void customToolInit(int argc, const char **argv); + +} // namespace tooling +} // namespace clang + +#endif // LLVM_CLANG_TOOLING_CUSTOM_TOOL_INIT_H |