OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/ninja_target_writer.h" | 5 #include "tools/gn/ninja_target_writer.h" |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 settings->build_settings()))); | 52 settings->build_settings()))); |
53 | 53 |
54 if (g_scheduler->verbose_logging()) | 54 if (g_scheduler->verbose_logging()) |
55 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file)); | 55 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file)); |
56 | 56 |
57 file_util::CreateDirectory(ninja_file.DirName()); | 57 file_util::CreateDirectory(ninja_file.DirName()); |
58 | 58 |
59 // It's rediculously faster to write to a string and then write that to | 59 // It's rediculously faster to write to a string and then write that to |
60 // disk in one operation than to use an fstream here. | 60 // disk in one operation than to use an fstream here. |
61 std::stringstream file; | 61 std::stringstream file; |
62 if (file.fail()) { | |
63 g_scheduler->FailWithError( | |
64 Err(Location(), "Error writing ninja file.", | |
65 "Unable to open \"" + FilePathToUTF8(ninja_file) + "\"\n" | |
66 "for writing.")); | |
67 return; | |
68 } | |
69 | 62 |
70 // Call out to the correct sub-type of writer. | 63 // Call out to the correct sub-type of writer. |
71 if (target->output_type() == Target::COPY_FILES) { | 64 if (target->output_type() == Target::COPY_FILES) { |
72 NinjaCopyTargetWriter writer(target, file); | 65 NinjaCopyTargetWriter writer(target, file); |
73 writer.Run(); | 66 writer.Run(); |
74 } else if (target->output_type() == Target::CUSTOM) { | 67 } else if (target->output_type() == Target::CUSTOM) { |
75 NinjaScriptTargetWriter writer(target, file); | 68 NinjaScriptTargetWriter writer(target, file); |
76 writer.Run(); | 69 writer.Run(); |
77 } else if (target->output_type() == Target::GROUP) { | 70 } else if (target->output_type() == Target::GROUP) { |
78 NinjaGroupTargetWriter writer(target, file); | 71 NinjaGroupTargetWriter writer(target, file); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 const Target::FileList& outputs = target_->script_values().outputs(); | 126 const Target::FileList& outputs = target_->script_values().outputs(); |
134 std::vector<std::string> output_template_args; | 127 std::vector<std::string> output_template_args; |
135 for (size_t i = 0; i < outputs.size(); i++) { | 128 for (size_t i = 0; i < outputs.size(); i++) { |
136 // All outputs should be in the output dir. | 129 // All outputs should be in the output dir. |
137 output_template_args.push_back( | 130 output_template_args.push_back( |
138 RemovePrefix(outputs[i].value(), | 131 RemovePrefix(outputs[i].value(), |
139 settings_->build_settings()->build_dir().value())); | 132 settings_->build_settings()->build_dir().value())); |
140 } | 133 } |
141 return FileTemplate(output_template_args); | 134 return FileTemplate(output_template_args); |
142 } | 135 } |
OLD | NEW |