Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort dependency manifest #10414

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/google/protobuf/compiler/command_line_interface.cc
Original file line number Diff line number Diff line change
@@ -2215,6 +2215,12 @@ bool CommandLineInterface::GenerateDependencyManifestFile(
output_filenames.push_back(descriptor_set_out_name_);
}

// Some consumers consider first output as the "primary output" (ninja)
// If this doesn't match their primary output it ignores the manifest.
// The unordered map for output_directories means we can't guarantee the order of files.
// Sorting here makes the "primary output" can be whichever is first alphabetically
std::sort(output_filenames.begin(), output_filenames.end());

int fd;
do {
fd = open(dependency_out_name_.c_str(),
33 changes: 33 additions & 0 deletions src/google/protobuf/compiler/command_line_interface_unittest.cc
Original file line number Diff line number Diff line change
@@ -1779,6 +1779,39 @@ TEST_F(CommandLineInterfaceTest,
"$tmpdir/bar.pb: "
"$tmpdir/foo.proto\\\n $tmpdir/bar.proto");
}

TEST_F(CommandLineInterfaceTest,
DependencyManifestFileIsOrderedByFilePath) {
CreateTempFile("foo.proto",
"syntax = \"proto2\";\n"
"message Foo {}\n");
CreateTempFile("bar.proto",
"syntax = \"proto2\";\n"
"import \"foo.proto\";\n"
"message Bar {\n"
" optional Foo foo = 1;\n"
"}\n");

Run("protocol_compiler --dependency_out=$tmpdir/manifest_a "
"--test_out=$tmpdir "
"--descriptor_set_out=$tmpdir/a.pb --proto_path=$tmpdir bar.proto");

ExpectNoErrors();

ExpectFileContent("manifest_a",
"$tmpdir/a.pb \\\n$tmpdir/bar.proto.MockCodeGenerator.test_generator: "
TrentHouliston marked this conversation as resolved.
Show resolved Hide resolved
"$tmpdir/foo.proto\\\n $tmpdir/bar.proto");
mkruskal-google marked this conversation as resolved.
Show resolved Hide resolved

Run("protocol_compiler --dependency_out=$tmpdir/manifest_z "
"--test_out=$tmpdir "
"--descriptor_set_out=$tmpdir/z.pb --proto_path=$tmpdir bar.proto");

ExpectNoErrors();

ExpectFileContent("manifest_z",
"$tmpdir/bar.proto.MockCodeGenerator.test_generator \\\n$tmpdir/z.pb: "
TrentHouliston marked this conversation as resolved.
Show resolved Hide resolved
"$tmpdir/foo.proto\\\n $tmpdir/bar.proto");
}
#endif // !_WIN32

TEST_F(CommandLineInterfaceTest, TestArgumentFile) {