| 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 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 default_toolchain_targets, file, depfile); | 129 default_toolchain_targets, file, depfile); |
| 130 gen.Run(); | 130 gen.Run(); |
| 131 return true; | 131 return true; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void NinjaBuildWriter::WriteNinjaRules() { | 134 void NinjaBuildWriter::WriteNinjaRules() { |
| 135 out_ << "rule gn\n"; | 135 out_ << "rule gn\n"; |
| 136 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; | 136 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; |
| 137 out_ << " description = Regenerating ninja files\n\n"; | 137 out_ << " description = Regenerating ninja files\n\n"; |
| 138 | 138 |
| 139 // This rule will regenerate the ninja files when any input file has changed. |
| 139 out_ << "build build.ninja: gn\n" | 140 out_ << "build build.ninja: gn\n" |
| 140 << " depfile = build.ninja.d\n"; | 141 << " depfile = build.ninja.d\n"; |
| 141 | 142 |
| 143 // Provide a way to force regenerating ninja files if the user is suspicious |
| 144 // something is out-of-date. This will be "ninja refresh". |
| 145 out_ << "\nbuild refresh: gn\n"; |
| 146 |
| 147 // Provide a way to see what flags are associated with this build: |
| 148 // This will be "ninja show". |
| 149 const CommandLine& our_cmdline = *CommandLine::ForCurrentProcess(); |
| 150 std::string args = our_cmdline.GetSwitchValueASCII("args"); |
| 151 out_ << "rule echo\n"; |
| 152 out_ << " command = echo $text\n"; |
| 153 out_ << " description = ECHO $desc\n"; |
| 154 out_ << "build show: echo\n"; |
| 155 out_ << " desc = build arguments:\n"; |
| 156 out_ << " text = " << (args.empty() ? std::string("<default args>") : args) |
| 157 << "\n"; |
| 158 |
| 142 // Input build files. These go in the ".d" file. If we write them as | 159 // Input build files. These go in the ".d" file. If we write them as |
| 143 // dependencies in the .ninja file itself, ninja will expect the files to | 160 // dependencies in the .ninja file itself, ninja will expect the files to |
| 144 // exist and will error if they don't. When files are listed in a depfile, | 161 // exist and will error if they don't. When files are listed in a depfile, |
| 145 // missing files are ignored. | 162 // missing files are ignored. |
| 146 dep_out_ << "build.ninja:"; | 163 dep_out_ << "build.ninja:"; |
| 147 std::vector<base::FilePath> input_files; | 164 std::vector<base::FilePath> input_files; |
| 148 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); | 165 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); |
| 149 for (size_t i = 0; i < input_files.size(); i++) | 166 for (size_t i = 0; i < input_files.size(); i++) |
| 150 dep_out_ << " " << FilePathToUTF8(input_files[i]); | 167 dep_out_ << " " << FilePathToUTF8(input_files[i]); |
| 151 | 168 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 all_rules.append(" $\n "); | 203 all_rules.append(" $\n "); |
| 187 all_rules.append(target_file.value()); | 204 all_rules.append(target_file.value()); |
| 188 } | 205 } |
| 189 | 206 |
| 190 if (!all_rules.empty()) { | 207 if (!all_rules.empty()) { |
| 191 out_ << "\nbuild all: phony " << all_rules << std::endl; | 208 out_ << "\nbuild all: phony " << all_rules << std::endl; |
| 192 out_ << "default all" << std::endl; | 209 out_ << "default all" << std::endl; |
| 193 } | 210 } |
| 194 } | 211 } |
| 195 | 212 |
| OLD | NEW |