[cfe-commits] r160369 - in /cfe/trunk/lib/Tooling: CommandLineClangTool.cpp CompilationDatabase.cpp CustomCompilationDatabase.h CustomToolInit.h
Douglas Gregor
dgregor at apple.com
Tue Jul 17 15:28:21 PDT 2012
On Jul 17, 2012, at 9:11 AM, Alexander Kornienko <alexfh at google.com> wrote:
> Author: alexfh
> Date: Tue Jul 17 11:11:17 2012
> New Revision: 160369
>
> URL: http://llvm.org/viewvc/llvm-project?rev=160369&view=rev
> Log:
> Add a custom initialize hook for clang tools + minor fixes in CustomCompilationDatabase.h
This kind of #define-based hack doesn't have a lot of precedent in Clang or LLVM. What is the point of this custom initialization hook? Why does it have to be a #define hacked into the build of Clang itself (which is supposed to be a reusable *library*) rather than being introduced via a plugin or by setting some function pointer/callback somewhere?
This feels very much like the wrong solution for the problem you're trying to solve, but it's not at all clear what problem you're solving.
- Doug
> Added:
> cfe/trunk/lib/Tooling/CustomToolInit.h
> Modified:
> cfe/trunk/lib/Tooling/CommandLineClangTool.cpp
> cfe/trunk/lib/Tooling/CompilationDatabase.cpp
> cfe/trunk/lib/Tooling/CustomCompilationDatabase.h
>
> Modified: cfe/trunk/lib/Tooling/CommandLineClangTool.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CommandLineClangTool.cpp?rev=160369&r1=160368&r2=160369&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Tooling/CommandLineClangTool.cpp (original)
> +++ cfe/trunk/lib/Tooling/CommandLineClangTool.cpp Tue Jul 17 11:11:17 2012
> @@ -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 @@
> }
>
> 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) {
>
> Modified: cfe/trunk/lib/Tooling/CompilationDatabase.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CompilationDatabase.cpp?rev=160369&r1=160368&r2=160369&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Tooling/CompilationDatabase.cpp (original)
> +++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp Tue Jul 17 11:11:17 2012
> @@ -130,7 +130,7 @@
> findCompilationDatabaseFromDirectory(StringRef Directory) {
> #ifdef USE_CUSTOM_COMPILATION_DATABASE
> if (CompilationDatabase *DB =
> - ::findCompilationDatabaseForDirectory(Directory))
> + ::clang::tooling::findCompilationDatabaseForDirectory(Directory))
> return DB;
> #endif
> while (!Directory.empty()) {
>
> Modified: cfe/trunk/lib/Tooling/CustomCompilationDatabase.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CustomCompilationDatabase.h?rev=160369&r1=160368&r2=160369&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Tooling/CustomCompilationDatabase.h (original)
> +++ cfe/trunk/lib/Tooling/CustomCompilationDatabase.h Tue Jul 17 11:11:17 2012
> @@ -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 @@
> /// 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
>
> Added: cfe/trunk/lib/Tooling/CustomToolInit.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CustomToolInit.h?rev=160369&view=auto
> ==============================================================================
> --- cfe/trunk/lib/Tooling/CustomToolInit.h (added)
> +++ cfe/trunk/lib/Tooling/CustomToolInit.h Tue Jul 17 11:11:17 2012
> @@ -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
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list