From: Eric Liu Date: Fri, 2 Feb 2018 18:19:22 +0000 (+0000) Subject: [Tooling] Returns non-zero status code when files are skipped. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a50153bd0141742604a6ced60663e748b8770f43;p=clang [Tooling] Returns non-zero status code when files are skipped. Reviewers: hokein, bkramer Reviewed By: bkramer Subscribers: bkramer, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42361 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324113 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Tooling/Tooling.h b/include/clang/Tooling/Tooling.h index ea3b0e0421..8ddfef3707 100644 --- a/include/clang/Tooling/Tooling.h +++ b/include/clang/Tooling/Tooling.h @@ -330,6 +330,9 @@ class ClangTool { /// Runs an action over all files specified in the command line. /// /// \param Action Tool action. + /// + /// \returns 0 on success; 1 if any error occured; 2 if there is no error but + /// some files are skipped due to missing compile commands. int run(ToolAction *Action); /// \brief Create an AST for each file specified in the command line and diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index b618508617..7ae2950037 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -388,6 +388,7 @@ int ClangTool::run(ToolAction *Action) { llvm::MemoryBuffer::getMemBuffer(MappedFile.second)); bool ProcessingFailed = false; + bool FileSkipped = false; for (const auto &SourcePath : SourcePaths) { std::string File(getAbsolutePath(SourcePath)); @@ -401,12 +402,8 @@ int ClangTool::run(ToolAction *Action) { std::vector CompileCommandsForFile = Compilations.getCompileCommands(File); if (CompileCommandsForFile.empty()) { - // FIXME: There are two use cases here: doing a fuzzy - // "find . -name '*.cc' |xargs tool" match, where as a user I don't care - // about the .cc files that were not found, and the use case where I - // specify all files I want to run over explicitly, where this should - // be an error. We'll want to add an option for this. llvm::errs() << "Skipping " << File << ". Compile command not found.\n"; + FileSkipped = true; continue; } for (CompileCommand &CompileCommand : CompileCommandsForFile) { @@ -466,7 +463,7 @@ int ClangTool::run(ToolAction *Action) { Twine(InitialDirectory) + "\n!"); } } - return ProcessingFailed ? 1 : 0; + return ProcessingFailed ? 1 : (FileSkipped ? 2 : 0); } namespace {