Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: tools/gn/command_gen.cc

Issue 56433003: GN threading refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/command_desc.cc ('k') | tools/gn/command_gyp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/time/time.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 TargetResolvedCallback(base::subtle::Atomic32* write_counter, 25 void BackgroundDoWrite(const Target* target, const Toolchain* toolchain) {
26 const Target* target) { 26 NinjaTargetWriter::RunAndWriteFile(target, toolchain);
27 g_scheduler->DecrementWorkCount();
28 }
29
30 // Called on the main thread.
31 void ItemResolvedCallback(base::subtle::Atomic32* write_counter,
32 scoped_refptr<Builder> builder,
33 const Item* item) {
27 base::subtle::NoBarrier_AtomicIncrement(write_counter, 1); 34 base::subtle::NoBarrier_AtomicIncrement(write_counter, 1);
28 NinjaTargetWriter::RunAndWriteFile(target); 35
36 const Target* target = item->AsTarget();
37 if (target) {
38 const Toolchain* toolchain =
39 builder->GetToolchain(target->settings()->toolchain_label());
40 DCHECK(toolchain);
41 g_scheduler->IncrementWorkCount();
42 g_scheduler->ScheduleWork(
43 base::Bind(&BackgroundDoWrite, target, toolchain));
44 }
29 } 45 }
30 46
31 } // namespace 47 } // namespace
32 48
33 const char kGen[] = "gen"; 49 const char kGen[] = "gen";
34 const char kGen_HelpShort[] = 50 const char kGen_HelpShort[] =
35 "gen: Generate ninja files."; 51 "gen: Generate ninja files.";
36 const char kGen_Help[] = 52 const char kGen_Help[] =
37 "gn gen\n" 53 "gn gen\n"
38 " Generates ninja files from the current tree.\n" 54 " Generates ninja files from the current tree.\n"
39 "\n" 55 "\n"
40 " See \"gn help\" for the common command-line switches.\n"; 56 " See \"gn help\" for the common command-line switches.\n";
41 57
42 // Note: partially duplicated in command_gyp.cc. 58 // Note: partially duplicated in command_gyp.cc.
43 int RunGen(const std::vector<std::string>& args) { 59 int RunGen(const std::vector<std::string>& args) {
44 base::TimeTicks begin_time = base::TimeTicks::Now(); 60 base::TimeTicks begin_time = base::TimeTicks::Now();
45 61
46 // Deliberately leaked to avoid expensive process teardown. 62 // Deliberately leaked to avoid expensive process teardown.
47 Setup* setup = new Setup; 63 Setup* setup = new Setup;
48 if (!setup->DoSetup()) 64 if (!setup->DoSetup())
49 return 1; 65 return 1;
50 66
51 // 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
52 // the writing to maintain a counter. 68 // the writing to maintain a counter.
53 base::subtle::Atomic32 write_counter = 0; 69 base::subtle::Atomic32 write_counter = 0;
54 setup->build_settings().set_target_resolved_callback( 70 setup->builder()->set_resolved_callback(
55 base::Bind(&TargetResolvedCallback, &write_counter)); 71 base::Bind(&ItemResolvedCallback, &write_counter,
72 scoped_refptr<Builder>(setup->builder())));
56 73
57 // 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.
58 if (!setup->Run()) 75 if (!setup->Run())
59 return 1; 76 return 1;
60 77
61 // Write the root ninja files. 78 // Write the root ninja files.
62 if (!NinjaWriter::RunAndWriteFiles(&setup->build_settings())) 79 if (!NinjaWriter::RunAndWriteFiles(&setup->build_settings(),
80 setup->builder()))
63 return 1; 81 return 1;
64 82
65 base::TimeTicks end_time = base::TimeTicks::Now(); 83 base::TimeTicks end_time = base::TimeTicks::Now();
66 84
67 if (!CommandLine::ForCurrentProcess()->HasSwitch(kSwitchQuiet)) { 85 if (!CommandLine::ForCurrentProcess()->HasSwitch(kSwitchQuiet)) {
68 OutputString("Done. ", DECORATION_GREEN); 86 OutputString("Done. ", DECORATION_GREEN);
69 87
70 std::string stats = "Wrote " + 88 std::string stats = "Wrote " +
71 base::IntToString(static_cast<int>(write_counter)) + 89 base::IntToString(static_cast<int>(write_counter)) +
72 " targets from " + 90 " targets from " +
73 base::IntToString( 91 base::IntToString(
74 setup->scheduler().input_file_manager()->GetInputFileCount()) + 92 setup->scheduler().input_file_manager()->GetInputFileCount()) +
75 " files in " + 93 " files in " +
76 base::IntToString((end_time - begin_time).InMilliseconds()) + "ms\n"; 94 base::IntToString((end_time - begin_time).InMilliseconds()) + "ms\n";
77 OutputString(stats); 95 OutputString(stats);
78 } 96 }
79 97
80 return 0; 98 return 0;
81 } 99 }
82 100
83 } // namespace commands 101 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/command_desc.cc ('k') | tools/gn/command_gyp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698