| 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 NinjaTargetWriter::RunAndWriteFile(target, toolchain); | 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. |
| 35 } |
| 36 } |
| 37 |
| 38 if (!err.has_error()) |
| 39 NinjaTargetWriter::RunAndWriteFile(target, toolchain); |
| 27 g_scheduler->DecrementWorkCount(); | 40 g_scheduler->DecrementWorkCount(); |
| 28 } | 41 } |
| 29 | 42 |
| 30 // Called on the main thread. | 43 // Called on the main thread. |
| 31 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, | 44 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, |
| 32 scoped_refptr<Builder> builder, | 45 scoped_refptr<Builder> builder, |
| 33 const Item* item) { | 46 const BuilderRecord* record) { |
| 34 base::subtle::NoBarrier_AtomicIncrement(write_counter, 1); | 47 base::subtle::NoBarrier_AtomicIncrement(write_counter, 1); |
| 35 | 48 |
| 49 const Item* item = record->item(); |
| 36 const Target* target = item->AsTarget(); | 50 const Target* target = item->AsTarget(); |
| 37 if (target) { | 51 if (target) { |
| 38 const Toolchain* toolchain = | 52 const Toolchain* toolchain = |
| 39 builder->GetToolchain(target->settings()->toolchain_label()); | 53 builder->GetToolchain(target->settings()->toolchain_label()); |
| 40 DCHECK(toolchain); | 54 DCHECK(toolchain); |
| 55 |
| 56 // Collect all dependencies. |
| 57 std::vector<const Item*> deps; |
| 58 for (BuilderRecord::BuilderRecordSet::const_iterator iter = |
| 59 record->all_deps().begin(); |
| 60 iter != record->all_deps().end(); |
| 61 ++iter) |
| 62 deps.push_back((*iter)->item()); |
| 63 |
| 41 g_scheduler->IncrementWorkCount(); | 64 g_scheduler->IncrementWorkCount(); |
| 42 g_scheduler->ScheduleWork( | 65 g_scheduler->ScheduleWork( |
| 43 base::Bind(&BackgroundDoWrite, target, toolchain)); | 66 base::Bind(&BackgroundDoWrite, target, toolchain, deps)); |
| 44 } | 67 } |
| 45 } | 68 } |
| 46 | 69 |
| 47 } // namespace | 70 } // namespace |
| 48 | 71 |
| 49 const char kGen[] = "gen"; | 72 const char kGen[] = "gen"; |
| 50 const char kGen_HelpShort[] = | 73 const char kGen_HelpShort[] = |
| 51 "gen: Generate ninja files."; | 74 "gen: Generate ninja files."; |
| 52 const char kGen_Help[] = | 75 const char kGen_Help[] = |
| 53 "gn gen: Generate ninja files.\n" | 76 "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()) + | 131 setup->scheduler().input_file_manager()->GetInputFileCount()) + |
| 109 " files in " + | 132 " files in " + |
| 110 base::IntToString(elapsed_time.InMilliseconds()) + "ms\n"; | 133 base::IntToString(elapsed_time.InMilliseconds()) + "ms\n"; |
| 111 OutputString(stats); | 134 OutputString(stats); |
| 112 } | 135 } |
| 113 | 136 |
| 114 return 0; | 137 return 0; |
| 115 } | 138 } |
| 116 | 139 |
| 117 } // namespace commands | 140 } // namespace commands |
| OLD | NEW |