Repository: protocolbuffers/protobuf (language: python)

Issue:
Errors with --error_format  gcc contains only proto filename without --proto_path prefix.

**What version of protobuf and what language are you using?**
Version: main (libprotoc 29.0-dev)
Language: C++
**What operating system (Linux, Windows, ...) and version?**
Linux
**What runtime / compiler are you using (e.g., python version or gcc version)**
gcc I guess

**What did you do?**
Consider following file structure
``` console
$ tree /tmp/protoc_test/
/tmp/protoc_test/
├── output
└── protos
    └── simple.proto
 2 directories, 1 file
```
Content of simple.proto with error(missing semicolon)
```proto
message MsgResponse {
     required string msg1 = 1
     required string msg2 = 2;
}
```
Compilation command
```
$ protoc --error_format gcc --cpp_out ./output --proto_path ./protos simple.proto
simple.proto:3:6: Expected ";".
```
Error is expected, but path to .proto file does not contain `--proto_path` prefix which makes it harder to goto/jump to the file with error.

**What did you expect to see**
Path to proto with provided `--proto_path` prefix, similar to what `--error_format msvs` provides
**Current** output with `--error_format msvs`:
```bash
# relative
$ protoc --error_format msvs --cpp_out ./output --proto_path ./protos simple.proto
protos/simple.proto(3) : error in column=6: Expected ";".
# absolute
$ protoc --error_format msvs --cpp_out ./output --proto_path $PWD/protos simple.proto
/tmp/protoc_test/protos/simple.proto(3) : error in column=6: Expected ";".
```

**Expected** output with --error_format gcc:
```
# relative
$ protoc --error_format gcc --cpp_out ./output --proto_path ./protos simple.proto
protos/simple.proto:3:6: Expected ";".
# absolute
protoc --error_format gcc --cpp_out ./output --proto_path $PWD/protos simple.proto
/tmp/protoc_test/protos/simple.proto:3:6: Expected ";".
```

Errors with --error_format  gcc contains only proto filename without --proto_path prefix.

**What version of protobuf and what language are you using?**
Version: main (libprotoc 29.0-dev)
Language: C++
**What operating system (Linux, Windows, ...) and version?**
Linux
**What runtime / compiler are you using (e.g., python version or gcc version)**
gcc I guess

**What did you do?**
Consider following file structure
``` console
$ tree /tmp/protoc_test/
/tmp/protoc_test/
├── output
└── protos
    └── simple.proto
 2 directories, 1 file
```
Content of simple.proto with error(missing semicolon)
```proto
message MsgResponse {
     required string msg1 = 1
     required string msg2 = 2;
}
```
Compilation command
```
$ protoc --error_format gcc --cpp_out ./output --proto_path ./protos simple.proto
simple.proto:3:6: Expected ";".
```
Error is expected, but path to .proto file does not contain `--proto_path` prefix which makes it harder to goto/jump to the file with error.

**What did you expect to see**
Path to proto with provided `--proto_path` prefix, similar to what `--error_format msvs` provides
**Current** output with `--error_format msvs`:
```bash
# relative
$ protoc --error_format msvs --cpp_out ./output --proto_path ./protos simple.proto
protos/simple.proto(3) : error in column=6: Expected ";".
# absolute
$ protoc --error_format msvs --cpp_out ./output --proto_path $PWD/protos simple.proto
/tmp/protoc_test/protos/simple.proto(3) : error in column=6: Expected ";".
```

**Expected** output with --error_format gcc:
```
# relative
$ protoc --error_format gcc --cpp_out ./output --proto_path ./protos simple.proto
protos/simple.proto:3:6: Expected ";".
# absolute
protoc --error_format gcc --cpp_out ./output --proto_path $PWD/protos simple.proto
/tmp/protoc_test/protos/simple.proto:3:6: Expected ";".
```



Discussion / hints:

Fix patch:
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index ae6b87e4ad1f..f85814197732 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -394,10 +394,6 @@ class CommandLineInterface::ErrorPrinter
                          std::ostream& out) {
     std::string dfile;
     if (
-#ifndef PROTOBUF_OPENSOURCE
-        // Print full path when running under MSVS
-        format_ == CommandLineInterface::ERROR_FORMAT_MSVS &&
-#endif  // !PROTOBUF_OPENSOURCE
         tree_ != nullptr && tree_->VirtualFileToDiskFile(filename, &dfile)) {
       out << dfile;
     } else {
diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h
index cd1ad9846cbb..58c5c2bdddd0 100644
--- a/src/google/protobuf/message_lite.h
+++ b/src/google/protobuf/message_lite.h
@@ -1206,11 +1206,6 @@ PROTOBUF_ALWAYS_INLINE inline MessageLite* MessageCreator::PlacementNew(
   //  - We know the minimum size is 16. We have a fallback for when it is not.
   //  - We can "underflow" the buffer because those are the MessageLite bytes
   //    we will set later.
-#ifndef PROTO2_OPENSOURCE
-  // This manual handling shows a 1.85% improvement in the parsing
-  // microbenchmark.
-  // TODO: Verify this is still the case.
-#endif  // !PROTO2_OPENSOUCE
   if (as_tag == kZeroInit) {
     // Make sure the input is really all zeros.
     ABSL_DCHECK(std::all_of(src + sizeof(MessageLite), src + size,


Test patch:
diff --git a/src/google/protobuf/compiler/command_line_interface_tester.cc b/src/google/protobuf/compiler/command_line_interface_tester.cc
index 1586ee1df616..e965d2734849 100644
--- a/src/google/protobuf/compiler/command_line_interface_tester.cc
+++ b/src/google/protobuf/compiler/command_line_interface_tester.cc
@@ -122,8 +122,8 @@ void CommandLineInterfaceTester::ExpectNoErrors() {
 void CommandLineInterfaceTester::ExpectErrorText(
     absl::string_view expected_text) {
   EXPECT_NE(0, return_code_);
-  EXPECT_EQ(absl::StrReplaceAll(expected_text, {{"$tmpdir", temp_directory_}}),
-            error_text_);
+  EXPECT_THAT(error_text_, HasSubstr(absl::StrReplaceAll(
+                               expected_text, {{"$tmpdir", temp_directory_}})));
 }
 
 void CommandLineInterfaceTester::ExpectErrorSubstring(
diff --git a/src/google/protobuf/compiler/command_line_interface_tester.h b/src/google/protobuf/compiler/command_line_interface_tester.h
index b77dfa32b963..5f428c81933f 100644
--- a/src/google/protobuf/compiler/command_line_interface_tester.h
+++ b/src/google/protobuf/compiler/command_line_interface_tester.h
@@ -25,6 +25,7 @@
 #include "absl/strings/string_view.h"
 #include "google/protobuf/compiler/code_generator.h"
 #include "google/protobuf/compiler/command_line_interface.h"
+#include "google/protobuf/testing/file.h"
 
 // Must be included last.
 #include "google/protobuf/port_def.inc"
@@ -76,12 +77,10 @@ class CommandLineInterfaceTester : public testing::Test {
   // Creates a subdirectory within temp_directory_.
   void CreateTempDir(absl::string_view name);
 
-#ifdef PROTOBUF_OPENSOURCE
   // Changes working directory to temp directory.
   void SwitchToTempDirectory() {
     File::ChangeWorkingDirectory(temp_directory_);
   }
-#endif  // !PROTOBUF_OPENSOURCE
 
   // -----------------------------------------------------------------
   // Methods to check the test results (called after Run()).
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index 787d56fbf0cf..436e8ce760f1 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -2618,7 +2618,6 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileGivenTwoInputs) {
       "Can only process one input file when using --dependency_out=FILE.\n");
 }
 
-#ifdef PROTOBUF_OPENSOURCE
 TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFile) {
   CreateTempFile("foo.proto",
                  "syntax = \"proto2\";\n"
@@ -2630,7 +2629,8 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFile) {
                  "  optional Foo foo = 1;\n"
                  "}\n");
 
-  std::string current_working_directory = getcwd(nullptr, 0);
+  char current_dir[PATH_MAX];
+  ASSERT_EQ(getcwd(current_dir, sizeof(current_dir)), current_dir);
   SwitchToTempDirectory();
 
   Run("protocol_compiler --dependency_out=manifest --test_out=. "
@@ -2642,12 +2642,8 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFile) {
                     "bar.proto.MockCodeGenerator.test_generator: "
                     "foo.proto\\\n bar.proto");
 
-  File::ChangeWorkingDirectory(current_working_directory);
+  File::ChangeWorkingDirectory(current_dir);
 }
-#else  // !PROTOBUF_OPENSOURCE
-// TODO: Figure out how to change and get working directory in
-// google3.
-#endif  // !PROTOBUF_OPENSOURCE
 
 TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForAbsolutePath) {
   CreateTempFile("foo.proto",
@@ -2771,9 +2767,12 @@ TEST_F(CommandLineInterfaceTest, ParseErrorsMultipleFiles) {
       "--proto_path=$tmpdir foo.proto");
 
   ExpectErrorText(
-      "bar.proto:2:1: Expected top-level statement (e.g. \"message\").\n"
-      "baz.proto:2:1: Import \"bar.proto\" was not found or had errors.\n"
-      "foo.proto:2:1: Import \"bar.proto\" was not found or had errors.\n"
+      "bar.proto:2:1: Expected top-level statement (e.g. \"message\").\n");
+  ExpectErrorText(
+      "baz.proto:2:1: Import \"bar.proto\" was not found or had errors.\n");
+  ExpectErrorText(
+      "foo.proto:2:1: Import \"bar.proto\" was not found or had errors.\n");
+  ExpectErrorText(
       "foo.proto:3:1: Import \"baz.proto\" was not found or had errors.\n");
 }
 
diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc
index 277e0f23d4d8..a75872c52802 100644
--- a/src/google/protobuf/testing/file.cc
+++ b/src/google/protobuf/testing/file.cc
@@ -196,8 +196,8 @@ void File::DeleteRecursively(const std::string& name, void* dummy1,
 #endif
 }
 
-bool File::ChangeWorkingDirectory(const std::string& new_working_directory) {
-  return chdir(new_working_directory.c_str()) == 0;
+bool File::ChangeWorkingDirectory(absl::string_view new_working_directory) {
+  return chdir(new_working_directory.data()) == 0;
 }
 
 }  // namespace protobuf
diff --git a/src/google/protobuf/testing/file.h b/src/google/protobuf/testing/file.h
index 74dfdbf98a0a..7cfc7d2197a4 100644
--- a/src/google/protobuf/testing/file.h
+++ b/src/google/protobuf/testing/file.h
@@ -63,7 +63,7 @@ class File {
                                 void* dummy2);
 
   // Change working directory to given directory.
-  static bool ChangeWorkingDirectory(const std::string& new_working_directory);
+  static bool ChangeWorkingDirectory(absl::string_view new_working_directory);
 
   static absl::Status GetContents(const std::string& name, std::string* output,
                                   bool /*is_default*/) {