]> granicus.if.org Git - clang/commitdiff
[Tooling] Returns non-zero status code when files are skipped.
authorEric Liu <ioeric@google.com>
Fri, 2 Feb 2018 18:19:22 +0000 (18:19 +0000)
committerEric Liu <ioeric@google.com>
Fri, 2 Feb 2018 18:19:22 +0000 (18:19 +0000)
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

include/clang/Tooling/Tooling.h
lib/Tooling/Tooling.cpp

index ea3b0e042140894593913df598f82bf1ca3bc8f1..8ddfef37074bcbcd3e525f9c53aaa7cc3169b410 100644 (file)
@@ -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
index b6185086176a719edb58662270d542f9b9ce9cca..7ae2950037ba54bf4f15938c731b26fc1a576d3f 100644 (file)
@@ -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<CompileCommand> 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 {