Chromium Code Reviews| Index: tools/gn/ninja_binary_target_writer.cc |
| diff --git a/tools/gn/ninja_binary_target_writer.cc b/tools/gn/ninja_binary_target_writer.cc |
| index 88a6eb2d546ac6e025a52df9f1d322091a27b864..36fb4522a7ba11127f4b2c9bafbb7d8a7512f08a 100644 |
| --- a/tools/gn/ninja_binary_target_writer.cc |
| +++ b/tools/gn/ninja_binary_target_writer.cc |
| @@ -80,12 +80,13 @@ void NinjaBinaryTargetWriter::Run() { |
| WriteCompilerVars(); |
| std::vector<OutputFile> obj_files; |
| - WriteSources(&obj_files); |
| + std::vector<SourceFile> other_files; |
| + WriteSources(&obj_files, &other_files); |
| if (target_->output_type() == Target::SOURCE_SET) |
| WriteSourceSetStamp(obj_files); |
| else |
| - WriteLinkerStuff(obj_files); |
| + WriteLinkerStuff(obj_files, other_files); |
| } |
| void NinjaBinaryTargetWriter::WriteCompilerVars() { |
| @@ -134,7 +135,8 @@ void NinjaBinaryTargetWriter::WriteCompilerVars() { |
| } |
| void NinjaBinaryTargetWriter::WriteSources( |
| - std::vector<OutputFile>* object_files) { |
| + std::vector<OutputFile>* object_files, |
| + std::vector<SourceFile>* other_files) { |
| object_files->reserve(target_->sources().size()); |
| OutputFile input_dep = |
| @@ -145,9 +147,11 @@ void NinjaBinaryTargetWriter::WriteSources( |
| std::vector<OutputFile> tool_outputs; // Prevent reallocation in loop. |
| for (const auto& source : target_->sources()) { |
| Toolchain::ToolType tool_type = Toolchain::TYPE_NONE; |
| - if (!GetOutputFilesForSource(target_, source, |
| - &tool_type, &tool_outputs)) |
| + if (!GetOutputFilesForSource(target_, source, &tool_type, &tool_outputs)) { |
| + if (GetSourceFileType(source) == SOURCE_DEF) |
| + other_files->push_back(source); |
| continue; // No output for this source. |
| + } |
| if (tool_type != Toolchain::TYPE_NONE) { |
| out_ << "build"; |
| @@ -195,7 +199,8 @@ void NinjaBinaryTargetWriter::WriteSources( |
| } |
| void NinjaBinaryTargetWriter::WriteLinkerStuff( |
| - const std::vector<OutputFile>& object_files) { |
| + const std::vector<OutputFile>& object_files, |
| + const std::vector<SourceFile>& other_files) { |
| std::vector<OutputFile> output_files; |
| SubstitutionWriter::ApplyListToLinkerAsOutputFile( |
| target_, tool_, tool_->outputs(), &output_files); |
| @@ -245,6 +250,20 @@ void NinjaBinaryTargetWriter::WriteLinkerStuff( |
| } |
| } |
| + const SourceFile* def_file = nullptr; |
| +#if defined(OS_WIN) |
|
brettw
2015/05/27 17:26:59
I think we can run this on non-Windows as well. I'
|
| + if (!other_files.empty()) { |
| + for (const SourceFile& src_file : other_files) { |
| + if (GetSourceFileType(src_file) == SOURCE_DEF) { |
| + def_file = &src_file; |
| + implicit_deps.push_back( |
| + OutputFile(settings_->build_settings(), src_file)); |
| + break; // Only one def file is allowed. |
| + } |
| + } |
| + } |
| +#endif // OS_WIN |
| + |
| // Append implicit dependencies collected above. |
| if (!implicit_deps.empty()) { |
| out_ << " |"; |
| @@ -270,13 +289,14 @@ void NinjaBinaryTargetWriter::WriteLinkerStuff( |
| out_ << std::endl; |
| // These go in the inner scope of the link line. |
| - WriteLinkerFlags(); |
| + WriteLinkerFlags(def_file); |
| + |
| WriteLibs(); |
| WriteOutputExtension(); |
| WriteSolibs(solibs); |
| } |
| -void NinjaBinaryTargetWriter::WriteLinkerFlags() { |
| +void NinjaBinaryTargetWriter::WriteLinkerFlags(const SourceFile* def_file) { |
| out_ << " ldflags ="; |
| // First the ldflags from the target and its config. |
| @@ -299,6 +319,14 @@ void NinjaBinaryTargetWriter::WriteLinkerFlags() { |
| PathOutput::DIR_NO_LAST_SLASH); |
| } |
| } |
| + |
| +#if defined(OS_WIN) |
|
brettw
2015/05/27 17:27:00
Ditto. I think we can always just do this.
|
| + if (def_file) { |
| + out_ << " /DEF:"; |
| + path_output_.WriteFile(out_, *def_file); |
| + } |
| +#endif // OS_WIN |
| + |
| out_ << std::endl; |
| } |