Index: third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc |
diff --git a/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc |
index bef0fe5a9d86042cc843908c6c762e3b66a8d9cc..fcad6b61652b5e69ca388063a3eb6d7293425d98 100644 |
--- a/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc |
+++ b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc |
@@ -50,7 +50,9 @@ |
#include <iostream> |
#include <ctype.h> |
+#ifdef GOOGLE_PROTOBUF_ARCH_SPARC |
#include <limits.h> //For PATH_MAX |
+#endif |
#include <memory> |
#ifndef _SHARED_PTR_H |
@@ -173,8 +175,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<string> parts = |
- Split(filename, "/", true); |
+ vector<string> parts = Split(filename, "/", true); |
string path_so_far = prefix; |
for (int i = 0; i < parts.size() - 1; i++) { |
path_so_far += parts[i]; |
@@ -263,12 +264,6 @@ void AddDefaultProtoPaths(vector<pair<string, string> >* paths) { |
return; |
} |
} |
- |
-string PluginName(const string& plugin_prefix, const string& directive) { |
- // Assuming the directive starts with "--" and ends with "_out" or "_opt", |
- // strip the "--" and "_out/_opt" and add the plugin prefix. |
- return plugin_prefix + "gen-" + directive.substr(2, directive.size() - 6); |
-} |
} // namespace |
// A MultiFileErrorCollector that prints errors to stderr. |
@@ -345,7 +340,7 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector, |
// them all to disk on demand. |
class CommandLineInterface::GeneratorContextImpl : public GeneratorContext { |
public: |
- GeneratorContextImpl(const std::vector<const FileDescriptor*>& parsed_files); |
+ GeneratorContextImpl(const vector<const FileDescriptor*>& parsed_files); |
~GeneratorContextImpl(); |
// Write all files in the directory to disk at the given output location, |
@@ -361,14 +356,14 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext { |
void AddJarManifest(); |
// Get name of all output files. |
- void GetOutputFilenames(std::vector<string>* output_filenames); |
+ void GetOutputFilenames(vector<string>* output_filenames); |
// implements GeneratorContext -------------------------------------- |
io::ZeroCopyOutputStream* Open(const string& filename); |
io::ZeroCopyOutputStream* OpenForAppend(const string& filename); |
io::ZeroCopyOutputStream* OpenForInsert( |
const string& filename, const string& insertion_point); |
- void ListParsedFiles(std::vector<const FileDescriptor*>* output) { |
+ void ListParsedFiles(vector<const FileDescriptor*>* output) { |
*output = parsed_files_; |
} |
@@ -377,8 +372,8 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext { |
// map instead of hash_map so that files are written in order (good when |
// writing zips). |
- std::map<string, string*> files_; |
- const std::vector<const FileDescriptor*>& parsed_files_; |
+ map<string, string*> files_; |
+ const vector<const FileDescriptor*>& parsed_files_; |
bool had_error_; |
}; |
@@ -415,7 +410,7 @@ class CommandLineInterface::MemoryOutputStream |
// ------------------------------------------------------------------- |
CommandLineInterface::GeneratorContextImpl::GeneratorContextImpl( |
- const std::vector<const FileDescriptor*>& parsed_files) |
+ const vector<const FileDescriptor*>& parsed_files) |
: parsed_files_(parsed_files), |
had_error_(false) { |
} |
@@ -434,7 +429,7 @@ bool CommandLineInterface::GeneratorContextImpl::WriteAllToDisk( |
return false; |
} |
- for (std::map<string, string*>::const_iterator iter = files_.begin(); |
+ for (map<string, string*>::const_iterator iter = files_.begin(); |
iter != files_.end(); ++iter) { |
const string& relative_filename = iter->first; |
const char* data = iter->second->data(); |
@@ -522,7 +517,7 @@ bool CommandLineInterface::GeneratorContextImpl::WriteAllToZip( |
io::FileOutputStream stream(file_descriptor); |
ZipWriter zip_writer(&stream); |
- for (std::map<string, string*>::const_iterator iter = files_.begin(); |
+ for (map<string, string*>::const_iterator iter = files_.begin(); |
iter != files_.end(); ++iter) { |
zip_writer.Write(iter->first, *iter->second); |
} |
@@ -551,8 +546,8 @@ void CommandLineInterface::GeneratorContextImpl::AddJarManifest() { |
} |
void CommandLineInterface::GeneratorContextImpl::GetOutputFilenames( |
- std::vector<string>* output_filenames) { |
- for (std::map<string, string*>::iterator iter = files_.begin(); |
+ vector<string>* output_filenames) { |
+ for (map<string, string*>::iterator iter = files_.begin(); |
iter != files_.end(); ++iter) { |
output_filenames->push_back(iter->first); |
} |
@@ -619,7 +614,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { |
} else { |
// This was an OpenForInsert(). |
- // If the data doesn't end with a clean line break, add one. |
+ // If the data doens't end with a clean line break, add one. |
if (!data_.empty() && data_[data_.size() - 1] != '\n') { |
data_.push_back('\n'); |
} |
@@ -646,23 +641,18 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { |
return; |
} |
- if ((pos > 3) && (target->substr(pos - 3, 2) == "/*")) { |
- // Support for inline "/* @@protoc_insertion_point() */" |
- pos = pos - 3; |
+ // Seek backwards to the beginning of the line, which is where we will |
+ // insert the data. Note that this has the effect of pushing the insertion |
+ // point down, so the data is inserted before it. This is intentional |
+ // because it means that multiple insertions at the same point will end |
+ // up in the expected order in the final output. |
+ pos = target->find_last_of('\n', pos); |
+ if (pos == string::npos) { |
+ // Insertion point is on the first line. |
+ pos = 0; |
} else { |
- // Seek backwards to the beginning of the line, which is where we will |
- // insert the data. Note that this has the effect of pushing the |
- // insertion point down, so the data is inserted before it. This is |
- // intentional because it means that multiple insertions at the same point |
- // will end up in the expected order in the final output. |
- pos = target->find_last_of('\n', pos); |
- if (pos == string::npos) { |
- // Insertion point is on the first line. |
- pos = 0; |
- } else { |
- // Advance to character after '\n'. |
- ++pos; |
- } |
+ // Advance to character after '\n'. |
+ ++pos; |
} |
// Extract indent. |
@@ -711,7 +701,6 @@ CommandLineInterface::CommandLineInterface() |
: mode_(MODE_COMPILE), |
print_mode_(PRINT_NONE), |
error_format_(ERROR_FORMAT_GCC), |
- direct_dependencies_explicitly_set_(false), |
imports_in_descriptor_set_(false), |
source_info_in_descriptor_set_(false), |
disallow_services_(false), |
@@ -775,7 +764,7 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { |
ErrorPrinter error_collector(error_format_, &source_tree); |
Importer importer(&source_tree, &error_collector); |
- std::vector<const FileDescriptor*> parsed_files; |
+ vector<const FileDescriptor*> parsed_files; |
// Parse each file. |
for (int i = 0; i < input_files_.size(); i++) { |
@@ -792,24 +781,6 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { |
"--disallow_services was used." << endl; |
return 1; |
} |
- |
- // Enforce --direct_dependencies |
- if (direct_dependencies_explicitly_set_) { |
- bool indirect_imports = false; |
- for (int i = 0; i < parsed_file->dependency_count(); i++) { |
- if (direct_dependencies_.find(parsed_file->dependency(i)->name()) == |
- direct_dependencies_.end()) { |
- indirect_imports = true; |
- cerr << parsed_file->name() |
- << ": File is imported but not declared in " |
- << "--direct_dependencies: " |
- << parsed_file->dependency(i)->name() << std::endl; |
- } |
- } |
- if (indirect_imports) { |
- return 1; |
- } |
- } |
} |
// We construct a separate GeneratorContext for each output location. Note |
@@ -923,7 +894,6 @@ void CommandLineInterface::Clear() { |
executable_name_.clear(); |
proto_path_.clear(); |
input_files_.clear(); |
- direct_dependencies_.clear(); |
output_directives_.clear(); |
codec_type_.clear(); |
descriptor_set_name_.clear(); |
@@ -934,7 +904,6 @@ void CommandLineInterface::Clear() { |
imports_in_descriptor_set_ = false; |
source_info_in_descriptor_set_ = false; |
disallow_services_ = false; |
- direct_dependencies_explicitly_set_ = false; |
} |
bool CommandLineInterface::MakeInputsBeProtoPathRelative( |
@@ -985,7 +954,7 @@ CommandLineInterface::ParseArgumentStatus |
CommandLineInterface::ParseArguments(int argc, const char* const argv[]) { |
executable_name_ = argv[0]; |
- std::vector<string> arguments; |
+ vector<string> arguments; |
for (int i = 1; i < argc; ++i) { |
arguments.push_back(argv[i]); |
} |
@@ -1014,24 +983,12 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) { |
return status; |
} |
- // Make sure each plugin option has a matching plugin output. |
- for (map<string, string>::const_iterator i = plugin_parameters_.begin(); |
- i != plugin_parameters_.end(); ++i) { |
- if (plugins_.find(i->first) == plugins_.end()) { |
- std::cerr << "Unknown flag: " |
- // strip prefix + "gen-" and add back "_opt" |
- << "--" + i->first.substr(plugin_prefix_.size() + 4) + "_opt" |
- << std::endl; |
- return PARSE_ARGUMENT_FAIL; |
- } |
- } |
- |
// If no --proto_path was given, use the current working directory. |
if (proto_path_.empty()) { |
// Don't use make_pair as the old/default standard library on Solaris |
// doesn't support it without explicit template parameters, which are |
// incompatible with C++0x's make_pair. |
- proto_path_.push_back(std::pair<string, string>("", ".")); |
+ proto_path_.push_back(pair<string, string>("", ".")); |
} |
// Check some errror cases. |
@@ -1154,7 +1111,7 @@ CommandLineInterface::InterpretArgument(const string& name, |
// Java's -classpath (and some other languages) delimits path components |
// with colons. Let's accept that syntax too just to make things more |
// intuitive. |
- std::vector<string> parts = Split( |
+ vector<string> parts = Split( |
value, kPathSeparator, true); |
for (int i = 0; i < parts.size(); i++) { |
@@ -1179,36 +1136,16 @@ 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. |
- if (access(parts[i].c_str(), F_OK) < 0) { |
- cerr << disk_path << ": warning: directory does not exist." << endl; |
- } else { |
- virtual_path = ""; |
- disk_path = parts[i]; |
- } |
+ std::cerr << disk_path << ": warning: directory does not exist." |
+ << std::endl; |
} |
// Don't use make_pair as the old/default standard library on Solaris |
// doesn't support it without explicit template parameters, which are |
// incompatible with C++0x's make_pair. |
- proto_path_.push_back(std::pair<string, string>(virtual_path, disk_path)); |
- } |
- |
- } else if (name == "--direct_dependencies") { |
- if (direct_dependencies_explicitly_set_) { |
- std::cerr << name << " may only be passed once. To specify multiple " |
- "direct dependencies, pass them all as a single " |
- "parameter separated by ':'." |
- << std::endl; |
- return PARSE_ARGUMENT_FAIL; |
+ proto_path_.push_back(pair<string, string>(virtual_path, disk_path)); |
} |
- direct_dependencies_explicitly_set_ = true; |
- std::vector<string> direct = Split( |
- value, ":", true); |
- GOOGLE_DCHECK(direct_dependencies_.empty()); |
- direct_dependencies_.insert(direct.begin(), direct.end()); |
- |
} else if (name == "-o" || name == "--descriptor_set_out") { |
if (!descriptor_set_name_.empty()) { |
std::cerr << name << " may only be passed once." << std::endl; |
@@ -1356,22 +1293,15 @@ CommandLineInterface::InterpretArgument(const string& name, |
(plugin_prefix_.empty() || !HasSuffixString(name, "_out"))) { |
// Check if it's a generator option flag. |
generator_info = FindOrNull(generators_by_option_name_, name); |
- if (generator_info != NULL) { |
+ if (generator_info == NULL) { |
+ std::cerr << "Unknown flag: " << name << std::endl; |
+ return PARSE_ARGUMENT_FAIL; |
+ } else { |
string* parameters = &generator_parameters_[generator_info->flag_name]; |
if (!parameters->empty()) { |
parameters->append(","); |
} |
parameters->append(value); |
- } else if (HasPrefixString(name, "--") && HasSuffixString(name, "_opt")) { |
- string* parameters = |
- &plugin_parameters_[PluginName(plugin_prefix_, name)]; |
- if (!parameters->empty()) { |
- parameters->append(","); |
- } |
- parameters->append(value); |
- } else { |
- std::cerr << "Unknown flag: " << name << std::endl; |
- return PARSE_ARGUMENT_FAIL; |
} |
} else { |
// It's an output flag. Add it to the output directives. |
@@ -1479,7 +1409,7 @@ void CommandLineInterface::PrintHelpText() { |
} |
bool CommandLineInterface::GenerateOutput( |
- const std::vector<const FileDescriptor*>& parsed_files, |
+ const vector<const FileDescriptor*>& parsed_files, |
const OutputDirective& output_directive, |
GeneratorContext* generator_context) { |
// Call the generator. |
@@ -1490,16 +1420,12 @@ bool CommandLineInterface::GenerateOutput( |
HasSuffixString(output_directive.name, "_out")) |
<< "Bad name for plugin generator: " << output_directive.name; |
- string plugin_name = PluginName(plugin_prefix_ , output_directive.name); |
- string parameters = output_directive.parameter; |
- if (!plugin_parameters_[plugin_name].empty()) { |
- if (!parameters.empty()) { |
- parameters.append(","); |
- } |
- parameters.append(plugin_parameters_[plugin_name]); |
- } |
+ // Strip the "--" and "_out" and add the plugin prefix. |
+ string plugin_name = plugin_prefix_ + "gen-" + |
+ output_directive.name.substr(2, output_directive.name.size() - 6); |
+ |
if (!GeneratePluginOutput(parsed_files, plugin_name, |
- parameters, |
+ output_directive.parameter, |
generator_context, &error)) { |
std::cerr << output_directive.name << ": " << error << std::endl; |
return false; |
@@ -1513,11 +1439,24 @@ bool CommandLineInterface::GenerateOutput( |
} |
parameters.append(generator_parameters_[output_directive.name]); |
} |
- if (!output_directive.generator->GenerateAll( |
- parsed_files, parameters, generator_context, &error)) { |
- // Generator returned an error. |
- std::cerr << output_directive.name << ": " << error << std::endl; |
- return false; |
+ if (output_directive.generator->HasGenerateAll()) { |
+ if (!output_directive.generator->GenerateAll( |
+ parsed_files, parameters, generator_context, &error)) { |
+ // Generator returned an error. |
+ std::cerr << output_directive.name << ": " |
+ << ": " << error << std::endl; |
+ return false; |
+ } |
+ } else { |
+ for (int i = 0; i < parsed_files.size(); i++) { |
+ if (!output_directive.generator->Generate(parsed_files[i], parameters, |
+ generator_context, &error)) { |
+ // Generator returned an error. |
+ std::cerr << output_directive.name << ": " << parsed_files[i]->name() |
+ << ": " << error << std::endl; |
+ return false; |
+ } |
+ } |
} |
} |
@@ -1525,12 +1464,12 @@ bool CommandLineInterface::GenerateOutput( |
} |
bool CommandLineInterface::GenerateDependencyManifestFile( |
- const std::vector<const FileDescriptor*>& parsed_files, |
+ const vector<const FileDescriptor*>& parsed_files, |
const GeneratorContextMap& output_directories, |
DiskSourceTree* source_tree) { |
FileDescriptorSet file_set; |
- std::set<const FileDescriptor*> already_seen; |
+ set<const FileDescriptor*> already_seen; |
for (int i = 0; i < parsed_files.size(); i++) { |
GetTransitiveDependencies(parsed_files[i], |
false, |
@@ -1539,12 +1478,12 @@ bool CommandLineInterface::GenerateDependencyManifestFile( |
file_set.mutable_file()); |
} |
- std::vector<string> output_filenames; |
+ vector<string> output_filenames; |
for (GeneratorContextMap::const_iterator iter = output_directories.begin(); |
iter != output_directories.end(); ++iter) { |
const string& location = iter->first; |
GeneratorContextImpl* directory = iter->second; |
- std::vector<string> relative_output_filenames; |
+ vector<string> relative_output_filenames; |
directory->GetOutputFilenames(&relative_output_filenames); |
for (int i = 0; i < relative_output_filenames.size(); i++) { |
string output_filename = location + relative_output_filenames[i]; |
@@ -1597,7 +1536,7 @@ bool CommandLineInterface::GenerateDependencyManifestFile( |
} |
bool CommandLineInterface::GeneratePluginOutput( |
- const std::vector<const FileDescriptor*>& parsed_files, |
+ const vector<const FileDescriptor*>& parsed_files, |
const string& plugin_name, |
const string& parameter, |
GeneratorContext* generator_context, |
@@ -1610,7 +1549,7 @@ bool CommandLineInterface::GeneratePluginOutput( |
request.set_parameter(parameter); |
} |
- std::set<const FileDescriptor*> already_seen; |
+ set<const FileDescriptor*> already_seen; |
for (int i = 0; i < parsed_files.size(); i++) { |
request.add_file_to_generate(parsed_files[i]->name()); |
GetTransitiveDependencies(parsed_files[i], |
@@ -1619,13 +1558,6 @@ bool CommandLineInterface::GeneratePluginOutput( |
&already_seen, request.mutable_proto_file()); |
} |
- google::protobuf::compiler::Version* version = |
- request.mutable_compiler_version(); |
- version->set_major(GOOGLE_PROTOBUF_VERSION / 1000000); |
- version->set_minor(GOOGLE_PROTOBUF_VERSION / 1000 % 1000); |
- version->set_patch(GOOGLE_PROTOBUF_VERSION % 1000); |
- version->set_suffix(GOOGLE_PROTOBUF_VERSION_SUFFIX); |
- |
// Invoke the plugin. |
Subprocess subprocess; |
@@ -1747,11 +1679,11 @@ bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool) { |
} |
bool CommandLineInterface::WriteDescriptorSet( |
- const std::vector<const FileDescriptor*> parsed_files) { |
+ const vector<const FileDescriptor*> parsed_files) { |
FileDescriptorSet file_set; |
if (imports_in_descriptor_set_) { |
- std::set<const FileDescriptor*> already_seen; |
+ set<const FileDescriptor*> already_seen; |
for (int i = 0; i < parsed_files.size(); i++) { |
GetTransitiveDependencies(parsed_files[i], |
true, // Include json_name |
@@ -1759,7 +1691,7 @@ bool CommandLineInterface::WriteDescriptorSet( |
&already_seen, file_set.mutable_file()); |
} |
} else { |
- std::set<const FileDescriptor*> already_seen; |
+ set<const FileDescriptor*> already_seen; |
for (int i = 0; i < parsed_files.size(); i++) { |
if (!already_seen.insert(parsed_files[i]).second) { |
continue; |
@@ -1804,7 +1736,7 @@ void CommandLineInterface::GetTransitiveDependencies( |
const FileDescriptor* file, |
bool include_json_name, |
bool include_source_code_info, |
- std::set<const FileDescriptor*>* already_seen, |
+ set<const FileDescriptor*>* already_seen, |
RepeatedPtrField<FileDescriptorProto>* output) { |
if (!already_seen->insert(file).second) { |
// Already saw this file. Skip. |
@@ -1863,11 +1795,11 @@ namespace { |
// parameter will contain the direct children (when groups are ignored in the |
// tree) of the given descriptor for the caller to traverse. The declaration |
// order of the nested messages is also preserved. |
-typedef std::pair<int, int> FieldRange; |
-void GatherOccupiedFieldRanges( |
- const Descriptor* descriptor, std::set<FieldRange>* ranges, |
- std::vector<const Descriptor*>* nested_messages) { |
- std::set<const Descriptor*> groups; |
+typedef pair<int, int> FieldRange; |
+void GatherOccupiedFieldRanges(const Descriptor* descriptor, |
+ set<FieldRange>* ranges, |
+ vector<const Descriptor*>* nested_messages) { |
+ set<const Descriptor*> groups; |
for (int i = 0; i < descriptor->field_count(); ++i) { |
const FieldDescriptor* fd = descriptor->field(i); |
ranges->insert(FieldRange(fd->number(), fd->number() + 1)); |
@@ -1899,11 +1831,11 @@ void GatherOccupiedFieldRanges( |
// Actually prints the formatted free field numbers for given message name and |
// occupied ranges. |
void FormatFreeFieldNumbers(const string& name, |
- const std::set<FieldRange>& ranges) { |
+ const set<FieldRange>& ranges) { |
string output; |
StringAppendF(&output, "%-35s free:", name.c_str()); |
int next_free_number = 1; |
- for (std::set<FieldRange>::const_iterator i = ranges.begin(); |
+ for (set<FieldRange>::const_iterator i = ranges.begin(); |
i != ranges.end(); ++i) { |
// This happens when groups re-use parent field numbers, in which |
// case we skip the FieldRange entirely. |
@@ -1930,8 +1862,8 @@ void FormatFreeFieldNumbers(const string& name, |
void CommandLineInterface::PrintFreeFieldNumbers( |
const Descriptor* descriptor) { |
- std::set<FieldRange> ranges; |
- std::vector<const Descriptor*> nested_messages; |
+ set<FieldRange> ranges; |
+ vector<const Descriptor*> nested_messages; |
GatherOccupiedFieldRanges(descriptor, &ranges, &nested_messages); |
for (int i = 0; i < nested_messages.size(); ++i) { |