Chromium Code Reviews| 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 <fstream> | 7 #include <fstream> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 } | 136 } |
| 137 | 137 |
| 138 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain, | 138 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain, |
| 139 default_toolchain_targets, file, depfile); | 139 default_toolchain_targets, file, depfile); |
| 140 return gen.Run(err); | 140 return gen.Run(err); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void NinjaBuildWriter::WriteNinjaRules() { | 143 void NinjaBuildWriter::WriteNinjaRules() { |
| 144 out_ << "rule gn\n"; | 144 out_ << "rule gn\n"; |
| 145 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; | 145 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; |
| 146 out_ << " description = Regenerating ninja files\n\n"; | 146 out_ << " description = Regenerating ninja files\n"; |
| 147 out_ << " restat = 1\n\n"; | |
| 147 | 148 |
| 148 // This rule will regenerate the ninja files when any input file has changed. | 149 // This rule will regenerate the ninja files when any input file has changed, |
| 149 out_ << "build build.ninja: gn\n" | 150 // or is missing. |
| 151 out_ << "build build.ninja"; | |
| 152 | |
| 153 // Other files read by the build. | |
| 154 std::vector<SourceFile> written_files = g_scheduler->GetWrittenFiles(); | |
| 155 for (const auto& written_file : written_files) | |
| 156 out_ << " " << FilePathToUTF8(build_settings_->GetFullPath(written_file)); | |
|
Peter Mayo
2015/07/28 22:37:37
GetFullPath caused the drive specifier issue, but
| |
| 157 | |
| 158 out_ << ": gn\n" | |
| 150 << " generator = 1\n" | 159 << " generator = 1\n" |
| 151 << " depfile = build.ninja.d\n"; | 160 << " depfile = build.ninja.d\n"; |
| 152 | 161 |
| 153 // Input build files. These go in the ".d" file. If we write them as | 162 // Input build files. These go in the ".d" file. If we write them as |
| 154 // dependencies in the .ninja file itself, ninja will expect the files to | 163 // dependencies in the .ninja file itself, ninja will expect the files to |
| 155 // exist and will error if they don't. When files are listed in a depfile, | 164 // exist and will error if they don't. When files are listed in a depfile, |
| 156 // missing files are ignored. | 165 // missing files are ignored. |
| 157 dep_out_ << "build.ninja:"; | 166 dep_out_ << "build.ninja:"; |
| 158 std::vector<base::FilePath> input_files; | 167 std::vector<base::FilePath> input_files; |
| 159 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); | 168 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); |
| 160 for (const auto& input_file : input_files) | 169 for (const auto& input_file : input_files) |
| 161 dep_out_ << " " << FilePathToUTF8(input_file); | 170 dep_out_ << " " << FilePathToUTF8(input_file); |
|
Peter Mayo
2015/07/28 22:37:37
This could also cause quoting issues.
| |
| 162 | 171 |
| 163 // Other files read by the build. | 172 // Other files read by the build. |
| 164 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies(); | 173 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies(); |
| 165 for (const auto& other_file : other_files) | 174 for (const auto& other_file : other_files) |
| 166 dep_out_ << " " << FilePathToUTF8(other_file); | 175 dep_out_ << " " << FilePathToUTF8(other_file); |
|
Peter Mayo
2015/07/28 22:37:37
There are also potential quoting issues lurking he
| |
| 167 | 176 |
| 168 out_ << std::endl; | 177 out_ << std::endl; |
| 169 } | 178 } |
| 170 | 179 |
| 171 void NinjaBuildWriter::WriteLinkPool() { | 180 void NinjaBuildWriter::WriteLinkPool() { |
| 172 out_ << "pool link_pool\n" | 181 out_ << "pool link_pool\n" |
| 173 << " depth = " << default_toolchain_->concurrent_links() << std::endl | 182 << " depth = " << default_toolchain_->concurrent_links() << std::endl |
| 174 << std::endl; | 183 << std::endl; |
| 175 } | 184 } |
| 176 | 185 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 EscapeOptions ninja_escape; | 322 EscapeOptions ninja_escape; |
| 314 ninja_escape.mode = ESCAPE_NINJA; | 323 ninja_escape.mode = ESCAPE_NINJA; |
| 315 | 324 |
| 316 // Escape for special chars Ninja will handle. | 325 // Escape for special chars Ninja will handle. |
| 317 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr); | 326 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr); |
| 318 | 327 |
| 319 out_ << "build " << escaped << ": phony "; | 328 out_ << "build " << escaped << ": phony "; |
| 320 path_output_.WriteFile(out_, target_file); | 329 path_output_.WriteFile(out_, target_file); |
| 321 out_ << std::endl; | 330 out_ << std::endl; |
| 322 } | 331 } |
| OLD | NEW |