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 #include <algorithm> | 8 #include <algorithm> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <utility> | 10 #include <utility> |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return try_this_file; | 130 return try_this_file; |
131 | 131 |
132 base::FilePath with_no_slash = current_dir.StripTrailingSeparators(); | 132 base::FilePath with_no_slash = current_dir.StripTrailingSeparators(); |
133 base::FilePath up_one_dir = with_no_slash.DirName(); | 133 base::FilePath up_one_dir = with_no_slash.DirName(); |
134 if (up_one_dir == current_dir) | 134 if (up_one_dir == current_dir) |
135 return base::FilePath(); // Got to the top. | 135 return base::FilePath(); // Got to the top. |
136 | 136 |
137 return FindDotFile(up_one_dir); | 137 return FindDotFile(up_one_dir); |
138 } | 138 } |
139 | 139 |
| 140 void ForwardItemDefinedToBuilderInMainThread( |
| 141 Builder* builder_call_on_main_thread_only, |
| 142 std::unique_ptr<Item> item) { |
| 143 builder_call_on_main_thread_only->ItemDefined(std::move(item)); |
| 144 |
| 145 // Pair to the Increment in ItemDefinedCallback. |
| 146 g_scheduler->DecrementWorkCount(); |
| 147 } |
| 148 |
140 // Called on any thread. Post the item to the builder on the main thread. | 149 // Called on any thread. Post the item to the builder on the main thread. |
141 void ItemDefinedCallback( | 150 void ItemDefinedCallback( |
142 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 151 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
143 Builder* builder_call_on_main_thread_only, | 152 Builder* builder_call_on_main_thread_only, |
144 std::unique_ptr<Item> item) { | 153 std::unique_ptr<Item> item) { |
145 DCHECK(item); | 154 DCHECK(item); |
| 155 |
| 156 // Increment the work count for the duration of defining the item with the |
| 157 // builder. Otherwise finishing this callback will race finishing loading |
| 158 // files. If there is no other pending work at any point in the middle of |
| 159 // this call completing on the main thread, the 'Complete' function will |
| 160 // be signaled and we'll stop running with an incomplete build. |
| 161 g_scheduler->IncrementWorkCount(); |
146 task_runner->PostTask( | 162 task_runner->PostTask( |
147 FROM_HERE, | 163 FROM_HERE, |
148 base::Bind(&Builder::ItemDefined, | 164 base::Bind(&ForwardItemDefinedToBuilderInMainThread, |
149 base::Unretained(builder_call_on_main_thread_only), | 165 base::Unretained(builder_call_on_main_thread_only), |
150 base::Passed(&item))); | 166 base::Passed(&item))); |
151 } | 167 } |
152 | 168 |
153 void DecrementWorkCount() { | 169 void DecrementWorkCount() { |
154 g_scheduler->DecrementWorkCount(); | 170 g_scheduler->DecrementWorkCount(); |
155 } | 171 } |
156 | 172 |
157 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
158 | 174 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 if (!scheduler_.Run()) | 330 if (!scheduler_.Run()) |
315 return false; | 331 return false; |
316 return RunPostMessageLoop(); | 332 return RunPostMessageLoop(); |
317 } | 333 } |
318 | 334 |
319 SourceFile Setup::GetBuildArgFile() const { | 335 SourceFile Setup::GetBuildArgFile() const { |
320 return SourceFile(build_settings_.build_dir().value() + kBuildArgFileName); | 336 return SourceFile(build_settings_.build_dir().value() + kBuildArgFileName); |
321 } | 337 } |
322 | 338 |
323 void Setup::RunPreMessageLoop() { | 339 void Setup::RunPreMessageLoop() { |
| 340 // Will be decremented with the loader is drained. |
| 341 g_scheduler->IncrementWorkCount(); |
| 342 |
324 // Load the root build file. | 343 // Load the root build file. |
325 loader_->Load(root_build_file_, LocationRange(), Label()); | 344 loader_->Load(root_build_file_, LocationRange(), Label()); |
326 | |
327 // Will be decremented with the loader is drained. | |
328 g_scheduler->IncrementWorkCount(); | |
329 } | 345 } |
330 | 346 |
331 bool Setup::RunPostMessageLoop() { | 347 bool Setup::RunPostMessageLoop() { |
332 Err err; | 348 Err err; |
333 if (!builder_.CheckForBadItems(&err)) { | 349 if (!builder_.CheckForBadItems(&err)) { |
334 err.PrintToStdout(); | 350 err.PrintToStdout(); |
335 return false; | 351 return false; |
336 } | 352 } |
337 | 353 |
338 if (!build_settings_.build_args().VerifyAllOverridesUsed(&err)) { | 354 if (!build_settings_.build_args().VerifyAllOverridesUsed(&err)) { |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 if (err.has_error()) { | 749 if (err.has_error()) { |
734 err.PrintToStdout(); | 750 err.PrintToStdout(); |
735 return false; | 751 return false; |
736 } | 752 } |
737 } | 753 } |
738 build_settings_.set_exec_script_whitelist(std::move(whitelist)); | 754 build_settings_.set_exec_script_whitelist(std::move(whitelist)); |
739 } | 755 } |
740 | 756 |
741 return true; | 757 return true; |
742 } | 758 } |
OLD | NEW |