| 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/time/time.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 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 50 const char kGen_HelpShort[] = | 50 const char kGen_HelpShort[] = |
| 51 "gen: Generate ninja files."; | 51 "gen: Generate ninja files."; |
| 52 const char kGen_Help[] = | 52 const char kGen_Help[] = |
| 53 "gn gen\n" | 53 "gn gen\n" |
| 54 " Generates ninja files from the current tree.\n" | 54 " Generates ninja files from the current tree.\n" |
| 55 "\n" | 55 "\n" |
| 56 " See \"gn help\" for the common command-line switches.\n"; | 56 " See \"gn help\" for the common command-line switches.\n"; |
| 57 | 57 |
| 58 // Note: partially duplicated in command_gyp.cc. | 58 // Note: partially duplicated in command_gyp.cc. |
| 59 int RunGen(const std::vector<std::string>& args) { | 59 int RunGen(const std::vector<std::string>& args) { |
| 60 base::TimeTicks begin_time = base::TimeTicks::Now(); | 60 base::ElapsedTimer timer; |
| 61 | 61 |
| 62 // Deliberately leaked to avoid expensive process teardown. | 62 // Deliberately leaked to avoid expensive process teardown. |
| 63 Setup* setup = new Setup; | 63 Setup* setup = new Setup; |
| 64 if (!setup->DoSetup()) | 64 if (!setup->DoSetup()) |
| 65 return 1; | 65 return 1; |
| 66 | 66 |
| 67 // Cause the load to also generate the ninja files for each target. We wrap | 67 // Cause the load to also generate the ninja files for each target. We wrap |
| 68 // the writing to maintain a counter. | 68 // the writing to maintain a counter. |
| 69 base::subtle::Atomic32 write_counter = 0; | 69 base::subtle::Atomic32 write_counter = 0; |
| 70 setup->builder()->set_resolved_callback( | 70 setup->builder()->set_resolved_callback( |
| 71 base::Bind(&ItemResolvedCallback, &write_counter, | 71 base::Bind(&ItemResolvedCallback, &write_counter, |
| 72 scoped_refptr<Builder>(setup->builder()))); | 72 scoped_refptr<Builder>(setup->builder()))); |
| 73 | 73 |
| 74 // Do the actual load. This will also write out the target ninja files. | 74 // Do the actual load. This will also write out the target ninja files. |
| 75 if (!setup->Run()) | 75 if (!setup->Run()) |
| 76 return 1; | 76 return 1; |
| 77 | 77 |
| 78 // Write the root ninja files. | 78 // Write the root ninja files. |
| 79 if (!NinjaWriter::RunAndWriteFiles(&setup->build_settings(), | 79 if (!NinjaWriter::RunAndWriteFiles(&setup->build_settings(), |
| 80 setup->builder())) | 80 setup->builder())) |
| 81 return 1; | 81 return 1; |
| 82 | 82 |
| 83 base::TimeTicks end_time = base::TimeTicks::Now(); | 83 base::TimeDelta elapsed_time = timer.Elapsed(); |
| 84 | 84 |
| 85 if (!CommandLine::ForCurrentProcess()->HasSwitch(kSwitchQuiet)) { | 85 if (!CommandLine::ForCurrentProcess()->HasSwitch(kSwitchQuiet)) { |
| 86 OutputString("Done. ", DECORATION_GREEN); | 86 OutputString("Done. ", DECORATION_GREEN); |
| 87 | 87 |
| 88 std::string stats = "Wrote " + | 88 std::string stats = "Wrote " + |
| 89 base::IntToString(static_cast<int>(write_counter)) + | 89 base::IntToString(static_cast<int>(write_counter)) + |
| 90 " targets from " + | 90 " targets from " + |
| 91 base::IntToString( | 91 base::IntToString( |
| 92 setup->scheduler().input_file_manager()->GetInputFileCount()) + | 92 setup->scheduler().input_file_manager()->GetInputFileCount()) + |
| 93 " files in " + | 93 " files in " + |
| 94 base::IntToString((end_time - begin_time).InMilliseconds()) + "ms\n"; | 94 base::IntToString(elapsed_time.InMilliseconds()) + "ms\n"; |
| 95 OutputString(stats); | 95 OutputString(stats); |
| 96 } | 96 } |
| 97 | 97 |
| 98 return 0; | 98 return 0; |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace commands | 101 } // namespace commands |
| OLD | NEW |