@ -2520,6 +2520,7 @@ bool CommandLineInterface::GenerateDependencyManifestFile(
output_filenames . push_back ( descriptor_set_out_name_ ) ;
}
// Create the depfile, even if it will be empty.
int fd ;
do {
fd = open ( dependency_out_name_ . c_str ( ) ,
@ -2531,30 +2532,34 @@ bool CommandLineInterface::GenerateDependencyManifestFile(
return false ;
}
io : : FileOutputStream out ( fd ) ;
io : : Printer printer ( & out , ' $ ' ) ;
// Only write to the depfile if there is at least one output_filename.
// Otherwise, the depfile will be malformed.
if ( ! output_filenames . empty ( ) ) {
io : : FileOutputStream out ( fd ) ;
io : : Printer printer ( & out , ' $ ' ) ;
for ( int i = 0 ; i < output_filenames . size ( ) ; i + + ) {
printer . Print ( output_filenames [ i ] ) ;
if ( i = = output_filenames . size ( ) - 1 ) {
printer . Print ( " : " ) ;
} else {
printer . Print ( " \\ \n " ) ;
for ( size_t i = 0 ; i < output_filenames . size ( ) ; i + + ) {
printer . Print ( output_filenames [ i ] ) ;
if ( i = = output_filenames . size ( ) - 1 ) {
printer . Print ( " : " ) ;
} else {
printer . Print ( " \\ \n " ) ;
}
}
}
for ( int i = 0 ; i < file_set . file_size ( ) ; i + + ) {
const FileDescriptorProto & file = file_set . file ( i ) ;
const std : : string & virtual_file = file . name ( ) ;
std : : string disk_file ;
if ( source_tree & &
source_tree - > VirtualFileToDiskFile ( virtual_file , & disk_file ) ) {
printer . Print ( " $disk_file$ " , " disk_file " , disk_file ) ;
if ( i < file_set . file_size ( ) - 1 ) printer . Print ( " \\ \n " ) ;
} else {
std : : cerr < < " Unable to identify path for file " < < virtual_file
< < std : : endl ;
return false ;
for ( int i = 0 ; i < file_set . file_size ( ) ; i + + ) {
const FileDescriptorProto & file = file_set . file ( i ) ;
const std : : string & virtual_file = file . name ( ) ;
std : : string disk_file ;
if ( source_tree & &
source_tree - > VirtualFileToDiskFile ( virtual_file , & disk_file ) ) {
printer . Print ( " $disk_file$ " , " disk_file " , disk_file ) ;
if ( i < file_set . file_size ( ) - 1 ) printer . Print ( " \\ \n " ) ;
} else {
std : : cerr < < " Unable to identify path for file " < < virtual_file
< < std : : endl ;
return false ;
}
}
}