aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/command_line_interface.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/command_line_interface.cc')
-rw-r--r--src/google/protobuf/compiler/command_line_interface.cc119
1 files changed, 65 insertions, 54 deletions
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index a1f3bafc..80056774 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -396,7 +396,7 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext {
private:
friend class MemoryOutputStream;
- // map instead of hash_map so that files are written in order (good when
+ // map instead of unordered_map so that files are written in order (good when
// writing zips).
std::map<string, string*> files_;
const std::vector<const FileDescriptor*>& parsed_files_;
@@ -750,7 +750,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
// Now copy in the data.
string::size_type data_pos = 0;
- char* target_ptr = string_as_array(target) + pos;
+ char* target_ptr = ::google::protobuf::string_as_array(target) + pos;
while (data_pos < data_.size()) {
// Copy indent.
memcpy(target_ptr, indent_.data(), indent_.size());
@@ -767,7 +767,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
}
GOOGLE_CHECK_EQ(target_ptr,
- string_as_array(target) + pos + data_.size() + indent_size);
+ ::google::protobuf::string_as_array(target) + pos + data_.size() + indent_size);
}
}
}
@@ -989,6 +989,7 @@ bool CommandLineInterface::InitializeDiskSourceTree(
if (!MakeInputsBeProtoPathRelative(source_tree)) {
return false;
}
+
return true;
}
@@ -1040,15 +1041,15 @@ bool CommandLineInterface::ParseInputFiles(
std::vector<const FileDescriptor*>* parsed_files) {
// Parse each file.
- for (int i = 0; i < input_files_.size(); i++) {
+ for (const auto& input_file : input_files_) {
// Import the file.
- descriptor_pool->AddUnusedImportTrackFile(input_files_[i]);
+ descriptor_pool->AddUnusedImportTrackFile(input_file);
const FileDescriptor* parsed_file =
- descriptor_pool->FindFileByName(input_files_[i]);
+ descriptor_pool->FindFileByName(input_file);
descriptor_pool->ClearUnusedImportTrackFiles();
if (parsed_file == NULL) {
if (!descriptor_set_in_names_.empty()) {
- std::cerr << input_files_[i] << ": " << strerror(ENOENT) << std::endl;
+ std::cerr << input_file << ": " << strerror(ENOENT) << std::endl;
}
return false;
}
@@ -1097,6 +1098,7 @@ void CommandLineInterface::Clear() {
descriptor_set_out_name_.clear();
dependency_out_name_.clear();
+
mode_ = MODE_COMPILE;
print_mode_ = PRINT_NONE;
imports_in_descriptor_set_ = false;
@@ -1105,64 +1107,73 @@ void CommandLineInterface::Clear() {
direct_dependencies_explicitly_set_ = false;
}
-bool CommandLineInterface::MakeInputsBeProtoPathRelative(
- DiskSourceTree* source_tree) {
- for (int i = 0; i < input_files_.size(); i++) {
- // If the input file path is not a physical file path, it must be a virtual
- // path.
- if (access(input_files_[i].c_str(), F_OK) < 0) {
+bool CommandLineInterface::MakeProtoProtoPathRelative(
+ DiskSourceTree* source_tree, string* proto) {
+ // If the input file path is not a physical file path, it must be a virtual
+ // path.
+ if (access(proto->c_str(), F_OK) < 0) {
+ string disk_file;
+ if (source_tree->VirtualFileToDiskFile(*proto, &disk_file)) {
+ return true;
+ } else {
+ std::cerr << *proto << ": " << strerror(ENOENT) << std::endl;
+ return false;
+ }
+ }
+ string virtual_file, shadowing_disk_file;
+ switch (source_tree->DiskFileToVirtualFile(
+ *proto, &virtual_file, &shadowing_disk_file)) {
+ case DiskSourceTree::SUCCESS:
+ *proto = virtual_file;
+ break;
+ case DiskSourceTree::SHADOWED:
+ std::cerr << *proto
+ << ": Input is shadowed in the --proto_path by \""
+ << shadowing_disk_file
+ << "\". Either use the latter file as your input or reorder "
+ "the --proto_path so that the former file's location "
+ "comes first." << std::endl;
+ return false;
+ case DiskSourceTree::CANNOT_OPEN:
+ std::cerr << *proto << ": " << strerror(errno) << std::endl;
+ return false;
+ case DiskSourceTree::NO_MAPPING: {
+ // Try to interpret the path as a virtual path.
string disk_file;
- if (source_tree->VirtualFileToDiskFile(input_files_[i], &disk_file)) {
- return true;
+ if (source_tree->VirtualFileToDiskFile(*proto, &disk_file)) {
+ return true;
} else {
- std::cerr << input_files_[i] << ": " << strerror(ENOENT) << std::endl;
+ // The input file path can't be mapped to any --proto_path and it also
+ // can't be interpreted as a virtual path.
+ std::cerr
+ << *proto
+ << ": File does not reside within any path "
+ "specified using --proto_path (or -I). You must specify a "
+ "--proto_path which encompasses this file. Note that the "
+ "proto_path must be an exact prefix of the .proto file "
+ "names -- protoc is too dumb to figure out when two paths "
+ "(e.g. absolute and relative) are equivalent (it's harder "
+ "than you think)."
+ << std::endl;
return false;
}
}
- string virtual_file, shadowing_disk_file;
- switch (source_tree->DiskFileToVirtualFile(
- input_files_[i], &virtual_file, &shadowing_disk_file)) {
- case DiskSourceTree::SUCCESS:
- input_files_[i] = virtual_file;
- break;
- case DiskSourceTree::SHADOWED:
- std::cerr << input_files_[i]
- << ": Input is shadowed in the --proto_path by \""
- << shadowing_disk_file
- << "\". Either use the latter file as your input or reorder "
- "the --proto_path so that the former file's location "
- "comes first." << std::endl;
- return false;
- case DiskSourceTree::CANNOT_OPEN:
- std::cerr << input_files_[i] << ": " << strerror(errno) << std::endl;
- return false;
- case DiskSourceTree::NO_MAPPING: {
- // Try to interpret the path as a virtual path.
- string disk_file;
- if (source_tree->VirtualFileToDiskFile(input_files_[i], &disk_file)) {
- return true;
- } else {
- // The input file path can't be mapped to any --proto_path and it also
- // can't be interpreted as a virtual path.
- std::cerr
- << input_files_[i]
- << ": File does not reside within any path "
- "specified using --proto_path (or -I). You must specify a "
- "--proto_path which encompasses this file. Note that the "
- "proto_path must be an exact prefix of the .proto file "
- "names -- protoc is too dumb to figure out when two paths "
- "(e.g. absolute and relative) are equivalent (it's harder "
- "than you think)."
- << std::endl;
- return false;
- }
- }
+ }
+ return true;
+}
+
+bool CommandLineInterface::MakeInputsBeProtoPathRelative(
+ DiskSourceTree* source_tree) {
+ for (auto& input_file : input_files_) {
+ if (!MakeProtoProtoPathRelative(source_tree, &input_file)) {
+ return false;
}
}
return true;
}
+
bool CommandLineInterface::ExpandArgumentFile(const string& file,
std::vector<string>* arguments) {
// The argument file is searched in the working directory only. We don't