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/setup.h" | 5 #include "tools/gn/setup.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 base::FilePath::StringType ending_in2 = FILE_PATH_LITERAL("depot_tools"); | 146 base::FilePath::StringType ending_in2 = FILE_PATH_LITERAL("depot_tools"); |
147 | 147 |
148 base::FilePath found = GetPathEndingIn(components, ending_in1); | 148 base::FilePath found = GetPathEndingIn(components, ending_in1); |
149 if (!found.empty()) | 149 if (!found.empty()) |
150 return found; | 150 return found; |
151 return GetPathEndingIn(components, ending_in2); | 151 return GetPathEndingIn(components, ending_in2); |
152 } | 152 } |
153 | 153 |
154 } // namespace | 154 } // namespace |
155 | 155 |
| 156 // CommonSetup ----------------------------------------------------------------- |
| 157 |
| 158 CommonSetup::CommonSetup() |
| 159 : check_for_bad_items_(true) { |
| 160 } |
| 161 |
| 162 CommonSetup::CommonSetup(const CommonSetup& other) |
| 163 : build_settings_(other.build_settings_), |
| 164 check_for_bad_items_(other.check_for_bad_items_) { |
| 165 } |
| 166 |
| 167 CommonSetup::~CommonSetup() { |
| 168 } |
| 169 |
| 170 void CommonSetup::RunPreMessageLoop() { |
| 171 // Load the root build file. |
| 172 build_settings_.toolchain_manager().StartLoadingUnlocked( |
| 173 SourceFile("//BUILD.gn")); |
| 174 } |
| 175 |
| 176 bool CommonSetup::RunPostMessageLoop() { |
| 177 Err err; |
| 178 if (check_for_bad_items_) { |
| 179 err = build_settings_.item_tree().CheckForBadItems(); |
| 180 if (err.has_error()) { |
| 181 err.PrintToStdout(); |
| 182 return false; |
| 183 } |
| 184 } |
| 185 |
| 186 if (!build_settings_.build_args().VerifyAllOverridesUsed(&err)) { |
| 187 err.PrintToStdout(); |
| 188 return false; |
| 189 } |
| 190 |
| 191 // Write out tracing and timing if requested. |
| 192 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 193 if (cmdline->HasSwitch(kTimeSwitch)) |
| 194 PrintLongHelp(SummarizeTraces()); |
| 195 if (cmdline->HasSwitch(kTracelogSwitch)) |
| 196 SaveTraces(cmdline->GetSwitchValuePath(kTracelogSwitch)); |
| 197 |
| 198 return true; |
| 199 } |
| 200 |
| 201 // Setup ----------------------------------------------------------------------- |
| 202 |
156 Setup::Setup() | 203 Setup::Setup() |
157 : check_for_bad_items_(true), | 204 : CommonSetup(), |
158 empty_toolchain_(Label()), | 205 empty_toolchain_(Label()), |
159 empty_settings_(&empty_build_settings_, &empty_toolchain_, std::string()), | 206 empty_settings_(&empty_build_settings_, &empty_toolchain_, std::string()), |
160 dotfile_scope_(&empty_settings_) { | 207 dotfile_scope_(&empty_settings_) { |
161 } | 208 } |
162 | 209 |
163 Setup::~Setup() { | 210 Setup::~Setup() { |
164 } | 211 } |
165 | 212 |
166 bool Setup::DoSetup() { | 213 bool Setup::DoSetup() { |
167 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 214 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
(...skipping 23 matching lines...) Expand all Loading... |
191 build_settings_.SetBuildDir(SourceDir(build_path_8)); | 238 build_settings_.SetBuildDir(SourceDir(build_path_8)); |
192 } else { | 239 } else { |
193 // Default output dir. | 240 // Default output dir. |
194 build_settings_.SetBuildDir(SourceDir("//out/gn/")); | 241 build_settings_.SetBuildDir(SourceDir("//out/gn/")); |
195 } | 242 } |
196 | 243 |
197 return true; | 244 return true; |
198 } | 245 } |
199 | 246 |
200 bool Setup::Run() { | 247 bool Setup::Run() { |
201 // Load the root build file and start runnung. | 248 RunPreMessageLoop(); |
202 build_settings_.toolchain_manager().StartLoadingUnlocked( | |
203 SourceFile("//BUILD.gn")); | |
204 if (!scheduler_.Run()) | 249 if (!scheduler_.Run()) |
205 return false; | 250 return false; |
206 | 251 return RunPostMessageLoop(); |
207 Err err; | |
208 if (check_for_bad_items_) { | |
209 err = build_settings_.item_tree().CheckForBadItems(); | |
210 if (err.has_error()) { | |
211 err.PrintToStdout(); | |
212 return false; | |
213 } | |
214 } | |
215 | |
216 if (!build_settings_.build_args().VerifyAllOverridesUsed(&err)) { | |
217 err.PrintToStdout(); | |
218 return false; | |
219 } | |
220 | |
221 // Write out tracing and timing if requested. | |
222 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | |
223 if (cmdline->HasSwitch(kTimeSwitch)) | |
224 PrintLongHelp(SummarizeTraces()); | |
225 if (cmdline->HasSwitch(kTracelogSwitch)) | |
226 SaveTraces(cmdline->GetSwitchValuePath(kTracelogSwitch)); | |
227 | |
228 return true; | |
229 } | 252 } |
230 | 253 |
231 bool Setup::FillArguments(const CommandLine& cmdline) { | 254 bool Setup::FillArguments(const CommandLine& cmdline) { |
232 std::string args = cmdline.GetSwitchValueASCII(kSwitchArgs); | 255 std::string args = cmdline.GetSwitchValueASCII(kSwitchArgs); |
233 if (args.empty()) | 256 if (args.empty()) |
234 return true; // Nothing to set. | 257 return true; // Nothing to set. |
235 | 258 |
236 args_input_file_.reset(new InputFile(SourceFile())); | 259 args_input_file_.reset(new InputFile(SourceFile())); |
237 args_input_file_->SetContents(args); | 260 args_input_file_->SetContents(args); |
238 args_input_file_->set_friendly_name("the command-line \"--args\" settings"); | 261 args_input_file_->set_friendly_name("the command-line \"--args\" settings"); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 return false; | 411 return false; |
389 } else if (!build_config_value->VerifyTypeIs(Value::STRING, &err)) { | 412 } else if (!build_config_value->VerifyTypeIs(Value::STRING, &err)) { |
390 err.PrintToStdout(); | 413 err.PrintToStdout(); |
391 return false; | 414 return false; |
392 } | 415 } |
393 build_settings_.set_build_config_file( | 416 build_settings_.set_build_config_file( |
394 SourceFile(build_config_value->string_value())); | 417 SourceFile(build_config_value->string_value())); |
395 | 418 |
396 return true; | 419 return true; |
397 } | 420 } |
| 421 |
| 422 // DependentSetup -------------------------------------------------------------- |
| 423 |
| 424 DependentSetup::DependentSetup(const Setup& main_setup) |
| 425 : CommonSetup(main_setup) { |
| 426 } |
| 427 |
| 428 DependentSetup::~DependentSetup() { |
| 429 } |
| 430 |
| 431 void DependentSetup::RunPreMessageLoop() { |
| 432 CommonSetup::RunPreMessageLoop(); |
| 433 } |
| 434 |
| 435 bool DependentSetup::RunPostMessageLoop() { |
| 436 return CommonSetup::RunPostMessageLoop(); |
| 437 } |
| 438 |
OLD | NEW |