Commits

ken...@google.com@630680e5-0e50-0410-840e-4b1c322b438d  committed 041c224

Use full paths when writing MSVS-style errors. Patch from Oleg Smolsky.

  • Participants
  • Parent commits 87b5fa1

Comments (0)

Files changed (2)

File src/google/protobuf/compiler/command_line_interface.cc

 class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
                                            public io::ErrorCollector {
  public:
-  ErrorPrinter(ErrorFormat format) : format_(format) {}
+  ErrorPrinter(ErrorFormat format, DiskSourceTree *tree = NULL) 
+    : format_(format), tree_(tree) {}
   ~ErrorPrinter() {}
 
   // implements MultiFileErrorCollector ------------------------------
   void AddError(const string& filename, int line, int column,
                 const string& message) {
 
-    cerr << filename;
+    // Print full path when running under MSVS
+    std::string dfile;
+    if (format_ == CommandLineInterface::ERROR_FORMAT_MSVS && 
+        tree_ != NULL &&
+        tree_->VirtualFileToDiskFile(filename, &dfile)) {
+      cerr << dfile;
+    } else {
+      cerr << filename;
+    }
 
     // Users typically expect 1-based line/column numbers, so we add 1
     // to each here.
 
  private:
   const ErrorFormat format_;
+  DiskSourceTree *tree_;
 };
 
 // -------------------------------------------------------------------
   }
 
   // Allocate the Importer.
-  ErrorPrinter error_collector(error_format_);
+  ErrorPrinter error_collector(error_format_, &source_tree);
   Importer importer(&source_tree, &error_collector);
 
   vector<const FileDescriptor*> parsed_files;

File src/google/protobuf/compiler/command_line_interface_unittest.cc

       "--proto_path=$tmpdir --error_format=msvs foo.proto");
 
   ExpectErrorText(
-    "foo.proto(2) : error in column=1: Expected top-level statement "
+    "$tmpdir/foo.proto(2) : error in column=1: Expected top-level statement "
       "(e.g. \"message\").\n");
 }