Clean code
This commit is contained in:
parent
2e32b8b569
commit
3edcbaf57a
@ -725,7 +725,7 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dependency_manifest_name_.empty()) {
|
if (!dependency_out_name_.empty()) {
|
||||||
if (!GenerateDependencyManifestFile(parsed_files, &source_tree)) {
|
if (!GenerateDependencyManifestFile(parsed_files, &source_tree)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -781,7 +781,7 @@ void CommandLineInterface::Clear() {
|
|||||||
output_directives_.clear();
|
output_directives_.clear();
|
||||||
codec_type_.clear();
|
codec_type_.clear();
|
||||||
descriptor_set_name_.clear();
|
descriptor_set_name_.clear();
|
||||||
dependency_manifest_name_.clear();
|
dependency_out_name_.clear();
|
||||||
|
|
||||||
mode_ = MODE_COMPILE;
|
mode_ = MODE_COMPILE;
|
||||||
print_mode_ = PRINT_NONE;
|
print_mode_ = PRINT_NONE;
|
||||||
@ -1020,7 +1020,7 @@ CommandLineInterface::InterpretArgument(const string& name,
|
|||||||
descriptor_set_name_ = value;
|
descriptor_set_name_ = value;
|
||||||
|
|
||||||
} else if (name == "--dependency_out") {
|
} else if (name == "--dependency_out") {
|
||||||
if (!dependency_manifest_name_.empty()) {
|
if (!dependency_out_name_.empty()) {
|
||||||
cerr << name << " may only be passed once." << endl;
|
cerr << name << " may only be passed once." << endl;
|
||||||
return PARSE_ARGUMENT_FAIL;
|
return PARSE_ARGUMENT_FAIL;
|
||||||
}
|
}
|
||||||
@ -1029,11 +1029,11 @@ CommandLineInterface::InterpretArgument(const string& name,
|
|||||||
return PARSE_ARGUMENT_FAIL;
|
return PARSE_ARGUMENT_FAIL;
|
||||||
}
|
}
|
||||||
if (mode_ != MODE_COMPILE) {
|
if (mode_ != MODE_COMPILE) {
|
||||||
cerr << "Cannot use --encode or --decode and generate a manifest at the "
|
cerr << "Cannot use --encode or --decode and --dependency_out=FILE at "
|
||||||
"same time." << endl;
|
"the same time." << endl;
|
||||||
return PARSE_ARGUMENT_FAIL;
|
return PARSE_ARGUMENT_FAIL;
|
||||||
}
|
}
|
||||||
dependency_manifest_name_ = value;
|
dependency_out_name_ = value;
|
||||||
|
|
||||||
} else if (name == "--include_imports") {
|
} else if (name == "--include_imports") {
|
||||||
if (imports_in_descriptor_set_) {
|
if (imports_in_descriptor_set_) {
|
||||||
@ -1309,44 +1309,44 @@ bool CommandLineInterface::GenerateOutput(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CommandLineInterface::GenerateDependencyManifestFile(
|
bool CommandLineInterface::GenerateDependencyManifestFile(
|
||||||
const vector<const FileDescriptor*> parsed_files,
|
const vector<const FileDescriptor*>& parsed_files,
|
||||||
DiskSourceTree * source_tree) {
|
DiskSourceTree* source_tree) {
|
||||||
FileDescriptorSet file_set;
|
FileDescriptorSet file_set;
|
||||||
|
|
||||||
set<const FileDescriptor*> already_seen;
|
set<const FileDescriptor*> already_seen;
|
||||||
for (int i = 0; i < parsed_files.size(); i++) {
|
for (int i = 0; i < parsed_files.size(); i++) {
|
||||||
GetTransitiveDependencies(parsed_files[i],
|
GetTransitiveDependencies(parsed_files[i],
|
||||||
false,
|
false,
|
||||||
&already_seen, file_set.mutable_file());
|
&already_seen,
|
||||||
|
file_set.mutable_file());
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
do {
|
do {
|
||||||
fd = open(dependency_manifest_name_.c_str(),
|
fd = open(dependency_out_name_.c_str(),
|
||||||
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
|
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
|
||||||
} while (fd < 0 && errno == EINTR);
|
} while (fd < 0 && errno == EINTR);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror(dependency_manifest_name_.c_str());
|
perror(dependency_out_name_.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
io::FileOutputStream out(fd);
|
io::FileOutputStream out(fd);
|
||||||
io::Printer printer(&out, '$');
|
io::Printer printer(&out, '$');
|
||||||
|
|
||||||
string output_filename = dependency_manifest_name_;
|
if (dependency_out_name_.compare(0, 1, "/") != 0) {
|
||||||
if (output_filename.compare(0, 1, "/") != 0) {
|
|
||||||
// Convert relative path to absolute path before print.
|
// Convert relative path to absolute path before print.
|
||||||
printer.Print("$working_directory$/$output_filename$:",
|
printer.Print("$working_directory$/$output_filename$:",
|
||||||
"working_directory", get_current_dir_name(),
|
"working_directory", get_current_dir_name(),
|
||||||
"output_filename",output_filename);
|
"output_filename", dependency_out_name_);
|
||||||
} else {
|
} else {
|
||||||
printer.Print("$output_filename$:",
|
printer.Print("$output_filename$:",
|
||||||
"output_filename",output_filename);
|
"output_filename", dependency_out_name_);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < file_set.file_size(); i++) {
|
for (int i = 0; i < file_set.file_size(); i++) {
|
||||||
const FileDescriptorProto& file = file_set.file(i);
|
const FileDescriptorProto& file = file_set.file(i);
|
||||||
string virtual_file = file.name();
|
const string& virtual_file = file.name();
|
||||||
string disk_file;
|
string disk_file;
|
||||||
if (source_tree &&
|
if (source_tree &&
|
||||||
source_tree->VirtualFileToDiskFile(virtual_file, &disk_file)) {
|
source_tree->VirtualFileToDiskFile(virtual_file, &disk_file)) {
|
||||||
|
@ -247,10 +247,10 @@ class LIBPROTOC_EXPORT CommandLineInterface {
|
|||||||
// Implements the --descriptor_set_out option.
|
// Implements the --descriptor_set_out option.
|
||||||
bool WriteDescriptorSet(const vector<const FileDescriptor*> parsed_files);
|
bool WriteDescriptorSet(const vector<const FileDescriptor*> parsed_files);
|
||||||
|
|
||||||
// Implements the --manifest-file option
|
// Implements the --dependency_out option
|
||||||
bool GenerateDependencyManifestFile(
|
bool GenerateDependencyManifestFile(
|
||||||
const vector<const FileDescriptor*> parsed_files,
|
const vector<const FileDescriptor*>& parsed_files,
|
||||||
DiskSourceTree * source_tree);
|
DiskSourceTree* source_tree);
|
||||||
|
|
||||||
// Get all transitive dependencies of the given file (including the file
|
// Get all transitive dependencies of the given file (including the file
|
||||||
// itself), adding them to the given list of FileDescriptorProtos. The
|
// itself), adding them to the given list of FileDescriptorProtos. The
|
||||||
@ -360,7 +360,7 @@ class LIBPROTOC_EXPORT CommandLineInterface {
|
|||||||
|
|
||||||
// If --dependency_out was given, this is the filename to which the input file
|
// If --dependency_out was given, this is the filename to which the input file
|
||||||
// should be written. Otherwise, empty.
|
// should be written. Otherwise, empty.
|
||||||
string dependency_manifest_name_;
|
string dependency_out_name_;
|
||||||
|
|
||||||
// True if --include_imports was given, meaning that we should
|
// True if --include_imports was given, meaning that we should
|
||||||
// write all transitive dependencies to the DescriptorSet. Otherwise, only
|
// write all transitive dependencies to the DescriptorSet. Otherwise, only
|
||||||
|
Loading…
Reference in New Issue
Block a user