41 #include <sys/types.h>
63 #include <mach-o/dyld.h>
87 #include <google/protobuf/port_def.inc>
95 #define O_BINARY _O_BINARY
97 #define O_BINARY 0 // If this isn't defined, the platform doesn't need it.
106 using google::protobuf::io::win32::close;
107 using google::protobuf::io::win32::mkdir;
108 using google::protobuf::io::win32::open;
109 using google::protobuf::io::win32::setmode;
110 using google::protobuf::io::win32::write;
113 static const char* kDefaultDirectDependenciesViolationMsg =
114 "File is imported but not declared in --direct_dependencies: %s";
120 #if defined(_WIN32) || defined(__CYGWIN__)
121 return text.size() >= 3 && text[1] ==
':' && isalpha(text[0]) &&
122 (text[2] ==
'/' || text[2] ==
'\\') && text.find_last_of(
':') == 1;
128 void SetFdToTextMode(
int fd) {
130 if (setmode(fd, _O_TEXT) == -1) {
138 void SetFdToBinaryMode(
int fd) {
140 if (setmode(fd, _O_BINARY) == -1) {
149 if (!
path->empty() &&
path->at(
path->size() - 1) !=
'/') {
150 path->push_back(
'/');
155 if (
path.empty())
return true;
173 std::vector<std::string> parts =
174 Split(filename,
"/\\",
true);
176 for (
int i = 0;
i < parts.size() - 1;
i++) {
177 path_so_far += parts[
i];
178 if (mkdir(path_so_far.c_str(), 0777) != 0) {
179 if (
errno != EEXIST) {
180 std::cerr << filename <<
": while trying to create directory "
196 #elif defined(__APPLE__)
201 uint32_t
size =
sizeof(dirtybuffer);
202 if (_NSGetExecutablePath(dirtybuffer, &
size) == 0) {
203 realpath(dirtybuffer,
buffer);
223 return access(file_path.c_str(), F_OK) != -1;
228 void AddDefaultProtoPaths(
229 std::vector<std::pair<std::string, std::string> >* paths) {
234 if (!GetProtocAbsolutePath(&
path)) {
238 size_t pos =
path.find_last_of(
"/\\");
239 if (pos == std::string::npos || pos == 0) {
244 if (IsInstalledProtoPath(
path)) {
245 paths->push_back(std::pair<std::string, std::string>(
"",
path));
249 if (IsInstalledProtoPath(
path +
"/include")) {
251 std::pair<std::string, std::string>(
"",
path +
"/include"));
255 pos =
path.find_last_of(
"/\\");
256 if (pos == std::string::npos || pos == 0) {
260 if (IsInstalledProtoPath(
path +
"/include")) {
262 std::pair<std::string, std::string>(
"",
path +
"/include"));
267 string PluginName(
const std::string& plugin_prefix,
271 return plugin_prefix +
"gen-" + directive.substr(2, directive.size() - 6);
280 public DescriptorPool::ErrorCollector {
341 out <<
":" << (line + 1) <<
":" << (column + 1);
344 out <<
"(" << (line + 1) <<
") : " <<
type
345 <<
" in column=" << (column + 1);
350 if (
type ==
"warning") {
351 out <<
": warning: " <<
message << std::endl;
353 out <<
": " <<
message << std::endl;
400 std::map<std::string, std::string*>
files_;
426 void UpdateMetadata(
size_t insertion_offset,
size_t insertion_length);
440 std::unique_ptr<io::StringOutputStream>
inner_;
446 const std::vector<const FileDescriptor*>& parsed_files)
447 : parsed_files_(parsed_files), had_error_(
false) {}
459 if (!VerifyDirectoryExists(
prefix)) {
463 for (std::map<std::string, std::string*>::const_iterator iter =
465 iter !=
files_.end(); ++iter) {
466 const std::string& relative_filename = iter->first;
467 const char*
data = iter->second->data();
468 int size = iter->second->size();
470 if (!TryCreateParentDirectory(
prefix, relative_filename)) {
479 open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY, 0666);
480 }
while (file_descriptor < 0 &&
errno ==
EINTR);
482 if (file_descriptor < 0) {
492 write_result = write(file_descriptor,
data,
size);
495 if (write_result <= 0) {
506 if (write_result < 0) {
510 std::cerr << filename <<
": write() returned zero?" << std::endl;
515 data += write_result;
516 size -= write_result;
519 if (close(file_descriptor) != 0) {
539 open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY, 0666);
540 }
while (file_descriptor < 0 &&
errno ==
EINTR);
542 if (file_descriptor < 0) {
552 for (std::map<std::string, std::string*>::const_iterator iter =
554 iter !=
files_.end(); ++iter) {
555 zip_writer.
Write(iter->first, *iter->second);
560 if (
stream.GetErrno() != 0) {
561 std::cerr << filename <<
": " <<
strerror(
stream.GetErrno()) << std::endl;
565 std::cerr << filename <<
": " <<
strerror(
stream.GetErrno()) << std::endl;
573 if (*map_slot ==
NULL) {
575 "Manifest-Version: 1.0\n"
576 "Created-By: 1.6.0 (protoc)\n"
582 std::vector<std::string>* output_filenames) {
583 for (std::map<std::string, std::string*>::iterator iter =
files_.begin();
584 iter !=
files_.end(); ++iter) {
585 output_filenames->push_back(iter->first);
611 : directory_(directory),
613 append_mode_(append_mode),
614 inner_(new io::StringOutputStream(&
data_)) {}
619 : directory_(directory),
621 insertion_point_(insertion_point),
622 inner_(new io::StringOutputStream(&
data_)) {}
625 size_t insertion_offset,
size_t insertion_length) {
626 std::map<std::string, std::string*>::iterator meta_file =
627 directory_->files_.find(filename_ +
".meta");
628 if (meta_file == directory_->files_.end() || !meta_file->second) {
634 bool is_text_format =
false;
635 if (!
metadata.ParseFromString(*encoded_data)) {
638 std::cerr << filename_
639 <<
".meta: Could not parse metadata as wire or text format."
646 is_text_format =
true;
648 for (
int i = 0;
i <
metadata.annotation_size(); ++
i) {
650 if (annotation->
begin() >= insertion_offset) {
652 annotation->
set_end(annotation->
end() + insertion_length);
655 if (is_text_format) {
658 metadata.SerializeToString(encoded_data);
667 std::string** map_slot = &directory_->files_[filename_];
669 if (insertion_point_.empty()) {
671 if (*map_slot !=
NULL) {
673 (*map_slot)->append(
data_);
675 std::cerr << filename_ <<
": Tried to write the same file twice."
677 directory_->had_error_ =
true;
683 (*map_slot)->swap(
data_);
689 data_.push_back(
'\n');
693 if (*map_slot ==
NULL) {
694 std::cerr << filename_
695 <<
": Tried to insert into file that doesn't exist."
697 directory_->had_error_ =
true;
705 std::string::size_type pos =
target->find(magic_string);
707 if (pos == std::string::npos) {
708 std::cerr << filename_ <<
": insertion point \"" << insertion_point_
709 <<
"\" not found." << std::endl;
710 directory_->had_error_ =
true;
714 if ((pos > 3) && (
target->substr(pos - 3, 2) ==
"/*")) {
723 pos =
target->find_last_of(
'\n', pos);
724 if (pos == std::string::npos) {
735 target->find_first_not_of(
" \t", pos) - pos);
737 if (indent_.empty()) {
740 UpdateMetadata(pos,
data_.size());
744 for (
int i = 0;
i <
data_.size();
i++) {
745 if (
data_[
i] ==
'\n') indent_size += indent_.size();
749 target->insert(pos,
data_.size() + indent_size,
'\0');
750 UpdateMetadata(pos,
data_.size() + indent_size);
753 std::string::size_type data_pos = 0;
755 while (data_pos <
data_.size()) {
757 memcpy(target_ptr, indent_.data(), indent_.size());
758 target_ptr += indent_.size();
763 std::string::size_type line_length =
764 data_.find_first_of(
'\n', data_pos) + 1 - data_pos;
765 memcpy(target_ptr,
data_.data() + data_pos, line_length);
766 target_ptr += line_length;
767 data_pos += line_length;
778 #if defined(_WIN32) && !defined(__CYGWIN__)
790 kDefaultDirectDependenciesViolationMsg),
834 std::vector<const FileDescriptor*> parsed_files;
835 std::unique_ptr<DiskSourceTree> disk_source_tree;
836 std::unique_ptr<ErrorPrinter> error_collector;
837 std::unique_ptr<DescriptorPool> descriptor_pool;
838 std::unique_ptr<SimpleDescriptorDatabase> descriptor_set_in_database;
839 std::unique_ptr<SourceTreeDescriptorDatabase> source_tree_database;
859 descriptor_pool.reset(
new DescriptorPool(descriptor_set_in_database.get(),
860 error_collector.get()));
864 descriptor_set_in_database.get())) {
868 error_collector.reset(
872 disk_source_tree.get(), descriptor_set_in_database.get()));
873 source_tree_database->RecordErrorsTo(error_collector.get());
876 source_tree_database.get(),
877 source_tree_database->GetValidationErrorCollector()));
880 descriptor_pool->EnforceWeakDependencies(
true);
897 AddTrailingSlash(&output_location);
901 if (*map_slot ==
NULL) {
914 for (GeneratorContextMap::iterator iter = output_directories.begin();
915 iter != output_directories.end(); ++iter) {
938 disk_source_tree.get())) {
956 file.
set_name(
"empty_message.proto");
970 if (error_collector->FoundErrors()) {
977 for (
int i = 0;
i < parsed_files.size(); ++
i) {
985 GOOGLE_LOG(
ERROR) <<
"If the code reaches here, it usually means a bug of "
986 "flag parsing in the CommandLineInterface.";
1027 bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd);
1028 if (close(fd) != 0) {
1040 for (
int j = 0; j < file_descriptor_set.
file_size(); j++) {
1042 if (
database->FindFileByName(file_descriptor_set.
file(j).name(),
1043 &previously_added_file_descriptor_proto)) {
1059 if (!
database->FindFileByName(input_file, &file_descriptor)) {
1060 std::cerr << input_file <<
": " <<
strerror(ENOENT) << std::endl;
1066 std::cerr << file_descriptor.
name()
1067 <<
": This file contains services, but "
1068 "--disallow_services was used."
1078 std::vector<const FileDescriptor*>* parsed_files) {
1087 if (parsed_file ==
NULL) {
1090 parsed_files->push_back(parsed_file);
1094 std::cerr << parsed_file->
name()
1095 <<
": This file contains services, but "
1096 "--disallow_services was used."
1103 bool indirect_imports =
false;
1107 indirect_imports =
true;
1108 std::cerr << parsed_file->
name() <<
": "
1115 if (indirect_imports) {
1151 bool in_fallback_database =
1152 fallback_database !=
nullptr &&
1157 if (
access(proto->c_str(), F_OK) < 0) {
1160 in_fallback_database) {
1163 std::cerr << *proto <<
": " <<
strerror(ENOENT) << std::endl;
1170 &shadowing_disk_file)) {
1172 *proto = virtual_file;
1175 std::cerr << *proto <<
": Input is shadowed in the --proto_path by \""
1176 << shadowing_disk_file
1177 <<
"\". Either use the latter file as your input or reorder "
1178 "the --proto_path so that the former file's location "
1183 if (in_fallback_database) {
1186 std::cerr << *proto <<
": " <<
strerror(
errno) << std::endl;
1192 in_fallback_database) {
1199 <<
": File does not reside within any path "
1200 "specified using --proto_path (or -I). You must specify a "
1201 "--proto_path which encompasses this file. Note that the "
1202 "proto_path must be an exact prefix of the .proto file "
1203 "names -- protoc is too dumb to figure out when two paths "
1204 "(e.g. absolute and relative) are equivalent (it's harder "
1218 fallback_database)) {
1228 const std::string& file, std::vector<std::string>* arguments) {
1231 std::ifstream file_stream(file.c_str());
1232 if (!file_stream.is_open()) {
1237 while (std::getline(file_stream, argument)) {
1238 arguments->push_back(argument);
1244 int argc,
const char*
const argv[]) {
1247 std::vector<std::string> arguments;
1248 for (
int i = 1;
i < argc; ++
i) {
1249 if (argv[
i][0] ==
'@') {
1251 std::cerr <<
"Failed to open argument file: " << (argv[
i] + 1)
1257 arguments.push_back(argv[
i]);
1261 if (arguments.empty()) {
1267 for (
int i = 0;
i < arguments.size(); ++
i) {
1272 if (
i + 1 == arguments.size() || arguments[
i + 1][0] ==
'-') {
1273 std::cerr <<
"Missing value for flag: " <<
name << std::endl;
1274 if (
name ==
"--decode") {
1275 std::cerr <<
"To decode an unknown message, use --decode_raw."
1290 bool foundUnknownPluginOption =
false;
1291 for (std::map<std::string, std::string>::const_iterator
i =
1297 bool foundImplicitPlugin =
false;
1298 for (std::vector<OutputDirective>::const_iterator j =
1301 if (j->generator ==
NULL) {
1303 if (plugin_name ==
i->first) {
1304 foundImplicitPlugin =
true;
1309 if (!foundImplicitPlugin) {
1310 std::cerr <<
"Unknown flag: "
1314 foundUnknownPluginOption =
true;
1317 if (foundUnknownPluginOption) {
1327 proto_path_.push_back(std::pair<std::string, std::string>(
"",
"."));
1333 std::cerr <<
"When using --decode_raw, no input files should be given."
1337 std::cerr <<
"Missing input file." << std::endl;
1342 std::cerr <<
"Missing output directives." << std::endl;
1346 std::cerr <<
"Can only use --dependency_out=FILE when generating code."
1352 <<
"Can only process one input file when using --dependency_out=FILE."
1357 std::cerr <<
"--include_imports only makes sense when combined with "
1358 "--descriptor_set_out."
1362 std::cerr <<
"--include_source_info only makes sense when combined with "
1363 "--descriptor_set_out."
1372 bool parsed_value =
false;
1374 if (arg[0] !=
'-') {
1377 parsed_value =
true;
1379 }
else if (arg[1] ==
'-') {
1382 const char* equals_pos = strchr(arg,
'=');
1383 if (equals_pos !=
NULL) {
1385 *
value = equals_pos + 1;
1386 parsed_value =
true;
1393 if (arg[1] ==
'\0') {
1398 parsed_value =
true;
1402 parsed_value = !
value->empty();
1414 if (*
name ==
"-h" || *
name ==
"--help" || *
name ==
"--disallow_services" ||
1415 *
name ==
"--include_imports" || *
name ==
"--include_source_info" ||
1416 *
name ==
"--version" || *
name ==
"--decode_raw" ||
1417 *
name ==
"--print_free_field_numbers") {
1433 if (
value.empty()) {
1435 <<
"You seem to have passed an empty string as one of the "
1438 <<
". This is actually "
1439 "sort of hard to do. Congrats. Unfortunately it is not valid "
1440 "input so the program is going to die now."
1447 }
else if (
name ==
"-I" ||
name ==
"--proto_path") {
1451 std::vector<std::string> parts =
Split(
1455 for (
int i = 0;
i < parts.size();
i++) {
1459 std::string::size_type equals_pos = parts[
i].find_first_of(
'=');
1460 if (equals_pos == std::string::npos) {
1462 disk_path = parts[
i];
1464 virtual_path = parts[
i].substr(0, equals_pos);
1465 disk_path = parts[
i].substr(equals_pos + 1);
1468 if (disk_path.empty()) {
1470 <<
"--proto_path passed empty directory name. (Use \".\" for "
1471 "current directory.)"
1477 if (
access(disk_path.c_str(), F_OK) < 0) {
1479 if (
access(parts[
i].c_str(), F_OK) < 0) {
1480 std::cerr << disk_path <<
": warning: directory does not exist."
1484 disk_path = parts[
i];
1492 std::pair<std::string, std::string>(virtual_path, disk_path));
1495 }
else if (
name ==
"--direct_dependencies") {
1498 <<
" may only be passed once. To specify multiple "
1499 "direct dependencies, pass them all as a single "
1500 "parameter separated by ':'."
1506 std::vector<std::string> direct =
1511 }
else if (
name ==
"--direct_dependencies_violation_msg") {
1514 }
else if (
name ==
"--descriptor_set_in") {
1517 <<
" may only be passed once. To specify multiple "
1518 "descriptor sets, pass them all as a single "
1519 "parameter separated by '"
1523 if (
value.empty()) {
1524 std::cerr <<
name <<
" requires a non-empty value." << std::endl;
1528 std::cerr <<
name <<
" cannot be used with --dependency_out."
1537 }
else if (
name ==
"-o" ||
name ==
"--descriptor_set_out") {
1539 std::cerr <<
name <<
" may only be passed once." << std::endl;
1542 if (
value.empty()) {
1543 std::cerr <<
name <<
" requires a non-empty value." << std::endl;
1548 <<
"Cannot use --encode or --decode and generate descriptors at the "
1555 }
else if (
name ==
"--dependency_out") {
1557 std::cerr <<
name <<
" may only be passed once." << std::endl;
1560 if (
value.empty()) {
1561 std::cerr <<
name <<
" requires a non-empty value." << std::endl;
1565 std::cerr <<
name <<
" cannot be used with --descriptor_set_in."
1571 }
else if (
name ==
"--include_imports") {
1573 std::cerr <<
name <<
" may only be passed once." << std::endl;
1578 }
else if (
name ==
"--include_source_info") {
1580 std::cerr <<
name <<
" may only be passed once." << std::endl;
1585 }
else if (
name ==
"-h" ||
name ==
"--help") {
1589 }
else if (
name ==
"--version") {
1597 }
else if (
name ==
"--disallow_services") {
1600 }
else if (
name ==
"--encode" ||
name ==
"--decode" ||
1601 name ==
"--decode_raw") {
1603 std::cerr <<
"Only one of --encode and --decode can be specified."
1608 std::cerr <<
"Cannot use " <<
name
1609 <<
" and generate code or descriptors at the same time."
1616 if (
value.empty() &&
name !=
"--decode_raw") {
1617 std::cerr <<
"Type name for " <<
name <<
" cannot be blank." << std::endl;
1618 if (
name ==
"--decode") {
1619 std::cerr <<
"To decode an unknown message, use --decode_raw."
1623 }
else if (!
value.empty() &&
name ==
"--decode_raw") {
1624 std::cerr <<
"--decode_raw does not take a parameter." << std::endl;
1630 }
else if (
name ==
"--error_format") {
1631 if (
value ==
"gcc") {
1633 }
else if (
value ==
"msvs") {
1636 std::cerr <<
"Unknown error format: " <<
value << std::endl;
1640 }
else if (
name ==
"--plugin") {
1642 std::cerr <<
"This compiler does not support plugins." << std::endl;
1649 std::string::size_type equals_pos =
value.find_first_of(
'=');
1650 if (equals_pos == std::string::npos) {
1652 std::string::size_type slash_pos =
value.find_last_of(
'/');
1653 if (slash_pos == std::string::npos) {
1654 plugin_name =
value;
1656 plugin_name =
value.substr(slash_pos + 1);
1660 plugin_name =
value.substr(0, equals_pos);
1666 }
else if (
name ==
"--print_free_field_numbers") {
1668 std::cerr <<
"Cannot use " <<
name
1669 <<
" and use --encode, --decode or print "
1670 <<
"other info at the same time." << std::endl;
1674 std::cerr <<
"Cannot use " <<
name
1675 <<
" and generate code or descriptors at the same time."
1685 if (generator_info ==
NULL &&
1689 if (generator_info !=
NULL) {
1704 std::cerr <<
"Unknown flag: " <<
name << std::endl;
1710 std::cerr <<
"Cannot use --encode, --decode or print .proto info and "
1711 "generate code at the same time."
1718 if (generator_info ==
NULL) {
1727 std::string::size_type colon_pos =
value.find_first_of(
':');
1747 <<
" [OPTION] PROTO_FILES\n"
1748 "Parse PROTO_FILES and generate output based on the options given:\n"
1749 " -IPATH, --proto_path=PATH Specify the directory in which to "
1751 " imports. May be specified multiple "
1753 " directories will be searched in order. "
1755 " given, the current working directory "
1757 " If not found in any of the these "
1759 " the --descriptor_set_in descriptors "
1761 " checked for required proto file.\n"
1762 " --version Show version info and exit.\n"
1763 " -h, --help Show this text and exit.\n"
1764 " --encode=MESSAGE_TYPE Read a text-format message of the "
1766 " from standard input and write it in "
1768 " to standard output. The message type "
1770 " be defined in PROTO_FILES or their "
1772 " --decode=MESSAGE_TYPE Read a binary message of the given "
1774 " standard input and write it in text "
1776 " to standard output. The message type "
1778 " be defined in PROTO_FILES or their "
1780 " --decode_raw Read an arbitrary protocol message "
1782 " standard input and write the raw "
1784 " pairs in text format to standard "
1786 " PROTO_FILES should be given when using "
1789 " --descriptor_set_in=FILES Specifies a delimited list of FILES\n"
1790 " each containing a FileDescriptorSet "
1792 " protocol buffer defined in "
1793 "descriptor.proto).\n"
1794 " The FileDescriptor for each of the "
1796 " provided will be loaded from these\n"
1797 " FileDescriptorSets. If a "
1799 " appears multiple times, the first "
1802 " -oFILE, Writes a FileDescriptorSet (a protocol "
1804 " --descriptor_set_out=FILE defined in descriptor.proto) "
1805 "containing all of\n"
1806 " the input files to FILE.\n"
1807 " --include_imports When using --descriptor_set_out, also "
1809 " all dependencies of the input files in "
1811 " set, so that the set is "
1813 " --include_source_info When using --descriptor_set_out, do "
1815 " SourceCodeInfo from the "
1816 "FileDescriptorProto.\n"
1817 " This results in vastly larger "
1818 "descriptors that\n"
1819 " include information about the "
1821 " location of each decl in the source "
1823 " well as surrounding comments.\n"
1824 " --dependency_out=FILE Write a dependency output file in the "
1826 " expected by make. This writes the "
1828 " set of input file paths to FILE\n"
1829 " --error_format=FORMAT Set the format in which to print "
1831 " FORMAT may be 'gcc' (the default) or "
1833 " (Microsoft Visual Studio format).\n"
1834 " --print_free_field_numbers Print the free field numbers of the "
1836 " defined in the given proto files. "
1838 " the same field number space with the "
1840 " message. Extension ranges are counted "
1842 " occupied fields numbers.\n"
1846 <<
" --plugin=EXECUTABLE Specifies a plugin executable to "
1848 " Normally, protoc searches the PATH "
1850 " plugins, but you may specify "
1852 " executables not in the path using "
1854 " Additionally, EXECUTABLE may be of "
1856 " NAME=PATH, in which case the given "
1858 " is mapped to the given executable "
1860 " the executable's own name differs."
1869 std::cout <<
" " << iter->first <<
"=OUT_DIR "
1872 << iter->second.help_text << std::endl;
1874 std::cout <<
" @<filename> Read options and filenames from "
1876 " relative file path is specified, "
1878 " will be searched in the working "
1880 " The --proto_path option will not "
1882 " this argument file is searched. "
1884 " the file will be expanded in the "
1886 " @<filename> as in the argument "
1888 " that shell expansion is not "
1890 " content of the file (i.e., you "
1892 " quotes, wildcards, escapes, "
1893 "commands, etc.).\n"
1894 " Each line corresponds to a "
1895 "single argument,\n"
1896 " even if it contains spaces."
1901 const std::vector<const FileDescriptor*>& parsed_files,
1910 <<
"Bad name for plugin generator: " << output_directive.
name;
1921 generator_context, &
error)) {
1922 std::cerr << output_directive.
name <<
": " <<
error << std::endl;
1935 generator_context, &
error)) {
1937 std::cerr << output_directive.
name <<
": " <<
error << std::endl;
1946 const std::vector<const FileDescriptor*>& parsed_files,
1951 std::set<const FileDescriptor*> already_seen;
1952 for (
int i = 0;
i < parsed_files.size();
i++) {
1957 std::vector<std::string> output_filenames;
1958 for (GeneratorContextMap::const_iterator iter = output_directories.begin();
1959 iter != output_directories.end(); ++iter) {
1962 std::vector<std::string> relative_output_filenames;
1964 for (
int i = 0;
i < relative_output_filenames.size();
i++) {
1966 if (output_filename.compare(0, 2,
"./") == 0) {
1967 output_filename = output_filename.substr(2);
1969 output_filenames.push_back(output_filename);
1976 O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY, 0666);
1987 for (
int i = 0;
i < output_filenames.size();
i++) {
1988 printer.
Print(output_filenames[
i].c_str());
1989 if (
i == output_filenames.size() - 1) {
1992 printer.
Print(
" \\\n");
2002 printer.
Print(
" $disk_file$",
"disk_file", disk_file);
2005 std::cerr <<
"Unable to identify path for file " << virtual_file
2015 const std::vector<const FileDescriptor*>& parsed_files,
2018 CodeGeneratorRequest request;
2024 if (!processed_parameter.empty()) {
2025 request.set_parameter(processed_parameter);
2029 std::set<const FileDescriptor*> already_seen;
2030 for (
int i = 0;
i < parsed_files.size();
i++) {
2031 request.add_file_to_generate(parsed_files[
i]->
name());
2035 &already_seen, request.mutable_proto_file());
2039 request.mutable_compiler_version();
2040 version->set_major(PROTOBUF_VERSION / 1000000);
2041 version->set_minor(PROTOBUF_VERSION / 1000 % 1000);
2042 version->set_patch(PROTOBUF_VERSION % 1000);
2043 version->set_suffix(PROTOBUF_VERSION_SUFFIX);
2048 if (
plugins_.count(plugin_name) > 0) {
2062 std::unique_ptr<io::ZeroCopyOutputStream> current_output;
2064 const CodeGeneratorResponse::File& output_file =
response.file(
i);
2066 if (!output_file.insertion_point().empty()) {
2071 current_output.reset();
2073 filename, output_file.insertion_point()));
2074 }
else if (!output_file.name().empty()) {
2078 current_output.reset();
2079 current_output.reset(generator_context->
Open(output_file.name()));
2080 }
else if (current_output ==
NULL) {
2082 "$0: First file chunk returned by plugin did not specify a file "
2108 std::cerr <<
"Type not defined: " <<
codec_type_ << std::endl;
2116 SetFdToTextMode(STDIN_FILENO);
2117 SetFdToBinaryMode(STDOUT_FILENO);
2119 SetFdToBinaryMode(STDIN_FILENO);
2120 SetFdToTextMode(STDOUT_FILENO);
2130 parser.RecordErrorsTo(&error_collector);
2131 parser.AllowPartialMessage(
true);
2134 std::cerr <<
"Failed to parse input." << std::endl;
2139 if (!
message->ParsePartialFromZeroCopyStream(&in)) {
2140 std::cerr <<
"Failed to parse input." << std::endl;
2145 if (!
message->IsInitialized()) {
2146 std::cerr <<
"warning: Input message is missing required fields: "
2147 <<
message->InitializationErrorString() << std::endl;
2152 if (!
message->SerializePartialToZeroCopyStream(&out)) {
2153 std::cerr <<
"output: I/O error." << std::endl;
2159 std::cerr <<
"output: I/O error." << std::endl;
2168 const std::vector<const FileDescriptor*>& parsed_files) {
2171 std::set<const FileDescriptor*> already_seen;
2177 std::set<const FileDescriptor*> to_output;
2178 to_output.insert(parsed_files.begin(), parsed_files.end());
2179 for (
int i = 0;
i < parsed_files.size();
i++) {
2184 if (to_output.find(dependency) == to_output.end()) {
2185 already_seen.insert(dependency);
2190 for (
int i = 0;
i < parsed_files.size();
i++) {
2200 O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY, 0666);
2209 if (!file_set.SerializeToZeroCopyStream(&out)) {
2226 bool include_source_code_info,
2227 std::set<const FileDescriptor*>* already_seen,
2229 if (!already_seen->insert(file).second) {
2237 include_source_code_info, already_seen,
output);
2242 file->
CopyTo(new_descriptor);
2243 if (include_json_name) {
2246 if (include_source_code_info) {
2285 void GatherOccupiedFieldRanges(
2287 std::vector<const Descriptor*>* nested_messages) {
2288 std::set<const Descriptor*> groups;
2296 for (
int i = 0;
i <
descriptor->extension_range_count(); ++
i) {
2300 for (
int i = 0;
i <
descriptor->reserved_range_count(); ++
i) {
2308 if (groups.find(nested_desc) != groups.end()) {
2309 GatherOccupiedFieldRanges(nested_desc, ranges, nested_messages);
2311 nested_messages->push_back(nested_desc);
2320 const std::set<FieldRange>& ranges) {
2323 int next_free_number = 1;
2324 for (std::set<FieldRange>::const_iterator
i = ranges.begin();
2325 i != ranges.end(); ++
i) {
2328 if (next_free_number >=
i->second)
continue;
2330 if (next_free_number < i->
first) {
2331 if (next_free_number + 1 ==
i->first) {
2339 next_free_number =
i->second;
2344 std::cout <<
output << std::endl;
2350 std::set<FieldRange> ranges;
2351 std::vector<const Descriptor*> nested_messages;
2352 GatherOccupiedFieldRanges(
descriptor, &ranges, &nested_messages);
2354 for (
int i = 0;
i < nested_messages.size(); ++
i) {
2357 FormatFreeFieldNumbers(
descriptor->full_name(), ranges);