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