diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 06aedd226..c8e60bc4b 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -725,7 +725,7 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { } } - if (!dependency_manifest_name_.empty()) { + if (!dependency_out_name_.empty()) { if (!GenerateDependencyManifestFile(parsed_files, &source_tree)) { return 1; } @@ -781,7 +781,7 @@ void CommandLineInterface::Clear() { output_directives_.clear(); codec_type_.clear(); descriptor_set_name_.clear(); - dependency_manifest_name_.clear(); + dependency_out_name_.clear(); mode_ = MODE_COMPILE; print_mode_ = PRINT_NONE; @@ -1020,7 +1020,7 @@ CommandLineInterface::InterpretArgument(const string& name, descriptor_set_name_ = value; } else if (name == "--dependency_out") { - if (!dependency_manifest_name_.empty()) { + if (!dependency_out_name_.empty()) { cerr << name << " may only be passed once." << endl; return PARSE_ARGUMENT_FAIL; } @@ -1029,11 +1029,11 @@ CommandLineInterface::InterpretArgument(const string& name, return PARSE_ARGUMENT_FAIL; } if (mode_ != MODE_COMPILE) { - cerr << "Cannot use --encode or --decode and generate a manifest at the " - "same time." << endl; + cerr << "Cannot use --encode or --decode and --dependency_out=FILE at " + "the same time." << endl; return PARSE_ARGUMENT_FAIL; } - dependency_manifest_name_ = value; + dependency_out_name_ = value; } else if (name == "--include_imports") { if (imports_in_descriptor_set_) { @@ -1309,44 +1309,44 @@ bool CommandLineInterface::GenerateOutput( } bool CommandLineInterface::GenerateDependencyManifestFile( - const vector parsed_files, - DiskSourceTree * source_tree) { + const vector& parsed_files, + DiskSourceTree* source_tree) { FileDescriptorSet file_set; set already_seen; for (int i = 0; i < parsed_files.size(); i++) { GetTransitiveDependencies(parsed_files[i], false, - &already_seen, file_set.mutable_file()); + &already_seen, + file_set.mutable_file()); } int fd; do { - fd = open(dependency_manifest_name_.c_str(), + fd = open(dependency_out_name_.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); } while (fd < 0 && errno == EINTR); if (fd < 0) { - perror(dependency_manifest_name_.c_str()); + perror(dependency_out_name_.c_str()); return false; } io::FileOutputStream out(fd); io::Printer printer(&out, '$'); - string output_filename = dependency_manifest_name_; - if (output_filename.compare(0, 1, "/") != 0) { + if (dependency_out_name_.compare(0, 1, "/") != 0) { // Convert relative path to absolute path before print. printer.Print("$working_directory$/$output_filename$:", "working_directory", get_current_dir_name(), - "output_filename",output_filename); + "output_filename", dependency_out_name_); } else { printer.Print("$output_filename$:", - "output_filename",output_filename); + "output_filename", dependency_out_name_); } for (int i = 0; i < file_set.file_size(); i++) { const FileDescriptorProto& file = file_set.file(i); - string virtual_file = file.name(); + const string& virtual_file = file.name(); string disk_file; if (source_tree && source_tree->VirtualFileToDiskFile(virtual_file, &disk_file)) { diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 13e93c54d..92c578c8f 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -247,10 +247,10 @@ class LIBPROTOC_EXPORT CommandLineInterface { // Implements the --descriptor_set_out option. bool WriteDescriptorSet(const vector parsed_files); - // Implements the --manifest-file option + // Implements the --dependency_out option bool GenerateDependencyManifestFile( - const vector parsed_files, - DiskSourceTree * source_tree); + const vector& parsed_files, + DiskSourceTree* source_tree); // Get all transitive dependencies of the given file (including the file // itself), adding them to the given list of FileDescriptorProtos. The @@ -360,7 +360,7 @@ class LIBPROTOC_EXPORT CommandLineInterface { // If --dependency_out was given, this is the filename to which the input file // should be written. Otherwise, empty. - string dependency_manifest_name_; + string dependency_out_name_; // True if --include_imports was given, meaning that we should // write all transitive dependencies to the DescriptorSet. Otherwise, only