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