From 0400cca3236de1ca303af38bf81eab332d042b7c Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 13 Mar 2018 16:37:29 -0700 Subject: Integrated internal changes from Google --- .../protobuf/compiler/command_line_interface.cc | 43 ++++++++++------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'src/google/protobuf/compiler/command_line_interface.cc') diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 7c45fe75..8380367f 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -58,9 +58,6 @@ #include //For PATH_MAX #include -#ifndef _SHARED_PTR_H -#include -#endif #ifdef __APPLE__ #include @@ -171,8 +168,7 @@ bool VerifyDirectoryExists(const string& path) { // directories listed in |filename|. bool TryCreateParentDirectory(const string& prefix, const string& filename) { // Recursively create parent directories to the output file. - std::vector parts = - Split(filename, "/", true); + std::vector parts = Split(filename, "/", true); string path_so_far = prefix; for (int i = 0; i < parts.size() - 1; i++) { path_so_far += parts[i]; @@ -440,7 +436,7 @@ class CommandLineInterface::MemoryOutputStream bool append_mode_; // StringOutputStream writing to data_. - google::protobuf::scoped_ptr inner_; + std::unique_ptr inner_; }; // ------------------------------------------------------------------- @@ -835,10 +831,10 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { std::vector parsed_files; // null unless descriptor_set_in_names_.empty() - google::protobuf::scoped_ptr disk_source_tree; - google::protobuf::scoped_ptr error_collector; - google::protobuf::scoped_ptr descriptor_pool; - google::protobuf::scoped_ptr descriptor_database; + std::unique_ptr disk_source_tree; + std::unique_ptr error_collector; + std::unique_ptr descriptor_pool; + std::unique_ptr descriptor_database; if (descriptor_set_in_names_.empty()) { disk_source_tree.reset(new DiskSourceTree()); if (!InitializeDiskSourceTree(disk_source_tree.get())) { @@ -1395,8 +1391,7 @@ CommandLineInterface::InterpretArgument(const string& name, // with colons. Let's accept that syntax too just to make things more // intuitive. std::vector parts = Split( - value, - CommandLineInterface::kPathSeparator, + value, CommandLineInterface::kPathSeparator, true); for (int i = 0; i < parts.size(); i++) { @@ -1421,7 +1416,7 @@ CommandLineInterface::InterpretArgument(const string& name, // Make sure disk path exists, warn otherwise. if (access(disk_path.c_str(), F_OK) < 0) { - // Try the original path; it may have just happed to have a '=' in it. + // Try the original path; it may have just happened to have a '=' in it. if (access(parts[i].c_str(), F_OK) < 0) { std::cerr << disk_path << ": warning: directory does not exist." << std::endl; @@ -1447,8 +1442,7 @@ CommandLineInterface::InterpretArgument(const string& name, } direct_dependencies_explicitly_set_ = true; - std::vector direct = Split( - value, ":", true); + std::vector direct = Split(value, ":", true); GOOGLE_DCHECK(direct_dependencies_.empty()); direct_dependencies_.insert(direct.begin(), direct.end()); @@ -1481,9 +1475,8 @@ CommandLineInterface::InterpretArgument(const string& name, } descriptor_set_in_names_ = Split( - value, - CommandLineInterface::kPathSeparator, - true); + value, CommandLineInterface::kPathSeparator, + true); } else if (name == "-o" || name == "--descriptor_set_out") { if (!descriptor_set_out_name_.empty()) { @@ -1629,7 +1622,6 @@ CommandLineInterface::InterpretArgument(const string& name, } mode_ = MODE_PRINT; print_mode_ = PRINT_FREE_FIELDS; - } else if (name == "--profile_path") { } else { // Some other flag. Look it up in the generators list. const GeneratorInfo* generator_info = @@ -1908,10 +1900,12 @@ bool CommandLineInterface::GeneratePluginOutput( string* error) { CodeGeneratorRequest request; CodeGeneratorResponse response; + string processed_parameter = parameter; + // Build the request. - if (!parameter.empty()) { - request.set_parameter(parameter); + if (!processed_parameter.empty()) { + request.set_parameter(processed_parameter); } @@ -1948,17 +1942,18 @@ bool CommandLineInterface::GeneratePluginOutput( // Write the files. We do this even if there was a generator error in order // to match the behavior of a compiled-in generator. - google::protobuf::scoped_ptr current_output; + std::unique_ptr current_output; for (int i = 0; i < response.file_size(); i++) { const CodeGeneratorResponse::File& output_file = response.file(i); if (!output_file.insertion_point().empty()) { + string filename = output_file.name(); // Open a file for insert. // We reset current_output to NULL first so that the old file is closed // before the new one is opened. current_output.reset(); current_output.reset(generator_context->OpenForInsert( - output_file.name(), output_file.insertion_point())); + filename, output_file.insertion_point())); } else if (!output_file.name().empty()) { // Starting a new file. Open it. // We reset current_output to NULL first so that the old file is closed @@ -1997,7 +1992,7 @@ bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool) { } DynamicMessageFactory dynamic_factory(pool); - google::protobuf::scoped_ptr message(dynamic_factory.GetPrototype(type)->New()); + std::unique_ptr message(dynamic_factory.GetPrototype(type)->New()); if (mode_ == MODE_ENCODE) { SetFdToTextMode(STDIN_FILENO); -- cgit v1.2.3