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_build_writer.h" | 5 #include "tools/gn/ninja_build_writer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <fstream> | 9 #include <fstream> |
10 #include <map> | 10 #include <map> |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 Err* err) { | 160 Err* err) { |
161 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, "build.ninja"); | 161 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, "build.ninja"); |
162 | 162 |
163 std::stringstream file; | 163 std::stringstream file; |
164 std::stringstream depfile; | 164 std::stringstream depfile; |
165 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain, | 165 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain, |
166 default_toolchain_targets, file, depfile); | 166 default_toolchain_targets, file, depfile); |
167 if (!gen.Run(err)) | 167 if (!gen.Run(err)) |
168 return false; | 168 return false; |
169 | 169 |
| 170 // Unconditionally write the build.ninja. Ninja's build-out-of-date checking |
| 171 // will re-run GN when any build input is newer than build.ninja, so any time |
| 172 // the build is updated, build.ninja's timestamp needs to updated also, even |
| 173 // if the contents haven't been changed. |
170 base::FilePath ninja_file_name(build_settings->GetFullPath( | 174 base::FilePath ninja_file_name(build_settings->GetFullPath( |
171 SourceFile(build_settings->build_dir().value() + "build.ninja"))); | 175 SourceFile(build_settings->build_dir().value() + "build.ninja"))); |
| 176 base::CreateDirectory(ninja_file_name.DirName()); |
| 177 std::string ninja_contents = file.str(); |
| 178 if (base::WriteFile(ninja_file_name, ninja_contents.data(), |
| 179 static_cast<int>(ninja_contents.size())) != |
| 180 static_cast<int>(ninja_contents.size())) |
| 181 return false; |
| 182 |
| 183 // Dep file listing build dependencies. |
172 base::FilePath dep_file_name(build_settings->GetFullPath( | 184 base::FilePath dep_file_name(build_settings->GetFullPath( |
173 SourceFile(build_settings->build_dir().value() + "build.ninja.d"))); | 185 SourceFile(build_settings->build_dir().value() + "build.ninja.d"))); |
174 base::CreateDirectory(ninja_file_name.DirName()); | 186 std::string dep_contents = depfile.str(); |
175 | 187 if (base::WriteFile(dep_file_name, dep_contents.data(), |
176 if (!WriteFileIfChanged(ninja_file_name, file.str(), err) || | 188 static_cast<int>(dep_contents.size())) != |
177 !WriteFileIfChanged(dep_file_name, depfile.str(), err)) | 189 static_cast<int>(dep_contents.size())) |
178 return false; | 190 return false; |
179 | 191 |
180 return true; | 192 return true; |
181 } | 193 } |
182 | 194 |
183 void NinjaBuildWriter::WriteNinjaRules() { | 195 void NinjaBuildWriter::WriteNinjaRules() { |
184 out_ << "rule gn\n"; | 196 out_ << "rule gn\n"; |
185 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; | 197 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; |
186 out_ << " description = Regenerating ninja files\n\n"; | 198 out_ << " description = Regenerating ninja files\n\n"; |
187 | 199 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 EscapeOptions ninja_escape; | 403 EscapeOptions ninja_escape; |
392 ninja_escape.mode = ESCAPE_NINJA; | 404 ninja_escape.mode = ESCAPE_NINJA; |
393 | 405 |
394 // Escape for special chars Ninja will handle. | 406 // Escape for special chars Ninja will handle. |
395 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr); | 407 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr); |
396 | 408 |
397 out_ << "build " << escaped << ": phony "; | 409 out_ << "build " << escaped << ": phony "; |
398 path_output_.WriteFile(out_, target->dependency_output_file()); | 410 path_output_.WriteFile(out_, target->dependency_output_file()); |
399 out_ << std::endl; | 411 out_ << std::endl; |
400 } | 412 } |
OLD | NEW |