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 "base/atomicops.h" | 5 #include "base/atomicops.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/timer/elapsed_timer.h" | 9 #include "base/timer/elapsed_timer.h" |
10 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
11 #include "tools/gn/commands.h" | 11 #include "tools/gn/commands.h" |
12 #include "tools/gn/ninja_target_writer.h" | 12 #include "tools/gn/ninja_target_writer.h" |
13 #include "tools/gn/ninja_writer.h" | 13 #include "tools/gn/ninja_writer.h" |
14 #include "tools/gn/scheduler.h" | 14 #include "tools/gn/scheduler.h" |
15 #include "tools/gn/setup.h" | 15 #include "tools/gn/setup.h" |
16 #include "tools/gn/standard_out.h" | 16 #include "tools/gn/standard_out.h" |
17 | 17 |
18 namespace commands { | 18 namespace commands { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Suppress output on success. | 22 // Suppress output on success. |
23 const char kSwitchQuiet[] = "q"; | 23 const char kSwitchQuiet[] = "q"; |
24 | 24 |
25 void BackgroundDoWrite(const Target* target, const Toolchain* toolchain) { | 25 void BackgroundDoWrite(const Target* target, |
26 const Toolchain* toolchain, | |
27 const std::vector<const Item*>& deps_for_visibility) { | |
28 // Validate visibility. | |
29 Err err; | |
30 for (size_t i = 0; i < deps_for_visibility.size(); i++) { | |
31 if (!Visibility::CheckItemVisibility(target, deps_for_visibility[i], | |
32 &err)) { | |
33 g_scheduler->FailWithError(err); | |
34 break; // Don't return early since we need DecrementWorkCount below. | |
scottmg
2014/04/01 06:18:35
Seems odd to RunAndWriteFile after an error?
| |
35 } | |
36 } | |
37 | |
26 NinjaTargetWriter::RunAndWriteFile(target, toolchain); | 38 NinjaTargetWriter::RunAndWriteFile(target, toolchain); |
27 g_scheduler->DecrementWorkCount(); | 39 g_scheduler->DecrementWorkCount(); |
28 } | 40 } |
29 | 41 |
30 // Called on the main thread. | 42 // Called on the main thread. |
31 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, | 43 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, |
32 scoped_refptr<Builder> builder, | 44 scoped_refptr<Builder> builder, |
33 const Item* item) { | 45 const BuilderRecord* record) { |
34 base::subtle::NoBarrier_AtomicIncrement(write_counter, 1); | 46 base::subtle::NoBarrier_AtomicIncrement(write_counter, 1); |
35 | 47 |
48 const Item* item = record->item(); | |
36 const Target* target = item->AsTarget(); | 49 const Target* target = item->AsTarget(); |
37 if (target) { | 50 if (target) { |
38 const Toolchain* toolchain = | 51 const Toolchain* toolchain = |
39 builder->GetToolchain(target->settings()->toolchain_label()); | 52 builder->GetToolchain(target->settings()->toolchain_label()); |
40 DCHECK(toolchain); | 53 DCHECK(toolchain); |
54 | |
55 // Collect all dependencies. | |
56 std::vector<const Item*> deps; | |
57 for (BuilderRecord::BuilderRecordSet::const_iterator iter = | |
58 record->all_deps().begin(); | |
59 iter != record->all_deps().end(); | |
60 ++iter) | |
61 deps.push_back((*iter)->item()); | |
62 | |
41 g_scheduler->IncrementWorkCount(); | 63 g_scheduler->IncrementWorkCount(); |
42 g_scheduler->ScheduleWork( | 64 g_scheduler->ScheduleWork( |
43 base::Bind(&BackgroundDoWrite, target, toolchain)); | 65 base::Bind(&BackgroundDoWrite, target, toolchain, deps)); |
44 } | 66 } |
45 } | 67 } |
46 | 68 |
47 } // namespace | 69 } // namespace |
48 | 70 |
49 const char kGen[] = "gen"; | 71 const char kGen[] = "gen"; |
50 const char kGen_HelpShort[] = | 72 const char kGen_HelpShort[] = |
51 "gen: Generate ninja files."; | 73 "gen: Generate ninja files."; |
52 const char kGen_Help[] = | 74 const char kGen_Help[] = |
53 "gn gen: Generate ninja files.\n" | 75 "gn gen: Generate ninja files.\n" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 setup->scheduler().input_file_manager()->GetInputFileCount()) + | 130 setup->scheduler().input_file_manager()->GetInputFileCount()) + |
109 " files in " + | 131 " files in " + |
110 base::IntToString(elapsed_time.InMilliseconds()) + "ms\n"; | 132 base::IntToString(elapsed_time.InMilliseconds()) + "ms\n"; |
111 OutputString(stats); | 133 OutputString(stats); |
112 } | 134 } |
113 | 135 |
114 return 0; | 136 return 0; |
115 } | 137 } |
116 | 138 |
117 } // namespace commands | 139 } // namespace commands |
OLD | NEW |