| 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 fcad6b61652b5e69ca388063a3eb6d7293425d98..8ab69d0227768ec35f641b6a22fa21cebdc27476 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,9 +50,7 @@
|
| #include <iostream>
|
| #include <ctype.h>
|
|
|
| -#ifdef GOOGLE_PROTOBUF_ARCH_SPARC
|
| #include <limits.h> //For PATH_MAX
|
| -#endif
|
|
|
| #include <memory>
|
| #ifndef _SHARED_PTR_H
|
| @@ -264,6 +262,12 @@ 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.
|
| @@ -614,7 +618,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
|
| } else {
|
| // This was an OpenForInsert().
|
|
|
| - // If the data doens't end with a clean line break, add one.
|
| + // If the data doesn't end with a clean line break, add one.
|
| if (!data_.empty() && data_[data_.size() - 1] != '\n') {
|
| data_.push_back('\n');
|
| }
|
| @@ -641,18 +645,23 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
|
| return;
|
| }
|
|
|
| - // 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;
|
| + if ((pos > 3) && (target->substr(pos - 3, 2) == "/*")) {
|
| + // Support for inline "/* @@protoc_insertion_point() */"
|
| + pos = pos - 3;
|
| } else {
|
| - // Advance to character after '\n'.
|
| - ++pos;
|
| + // 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;
|
| + }
|
| }
|
|
|
| // Extract indent.
|
| @@ -701,6 +710,7 @@ 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),
|
| @@ -781,6 +791,24 @@ 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
|
| @@ -894,6 +922,7 @@ 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();
|
| @@ -904,6 +933,7 @@ 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(
|
| @@ -983,6 +1013,18 @@ 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
|
| @@ -1136,8 +1178,13 @@ CommandLineInterface::InterpretArgument(const string& name,
|
|
|
| // Make sure disk path exists, warn otherwise.
|
| if (access(disk_path.c_str(), F_OK) < 0) {
|
| - std::cerr << disk_path << ": warning: directory does not exist."
|
| - << std::endl;
|
| + // 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];
|
| + }
|
| }
|
|
|
| // Don't use make_pair as the old/default standard library on Solaris
|
| @@ -1146,6 +1193,19 @@ CommandLineInterface::InterpretArgument(const string& name,
|
| proto_path_.push_back(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;
|
| + }
|
| +
|
| + direct_dependencies_explicitly_set_ = true;
|
| + 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;
|
| @@ -1293,15 +1353,22 @@ 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) {
|
| - std::cerr << "Unknown flag: " << name << std::endl;
|
| - return PARSE_ARGUMENT_FAIL;
|
| - } else {
|
| + if (generator_info != NULL) {
|
| 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.
|
| @@ -1420,12 +1487,16 @@ bool CommandLineInterface::GenerateOutput(
|
| HasSuffixString(output_directive.name, "_out"))
|
| << "Bad name for plugin generator: " << output_directive.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);
|
| -
|
| + 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]);
|
| + }
|
| if (!GeneratePluginOutput(parsed_files, plugin_name,
|
| - output_directive.parameter,
|
| + parameters,
|
| generator_context, &error)) {
|
| std::cerr << output_directive.name << ": " << error << std::endl;
|
| return false;
|
| @@ -1439,24 +1510,11 @@ bool CommandLineInterface::GenerateOutput(
|
| }
|
| parameters.append(generator_parameters_[output_directive.name]);
|
| }
|
| - 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;
|
| - }
|
| - }
|
| + 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;
|
| }
|
| }
|
|
|
|
|