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

Side by Side Diff: tools/gn/ninja_writer.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/ninja_writer.h ('k') | tools/gn/scheduler.h » ('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 "tools/gn/ninja_writer.h" 5 #include "tools/gn/ninja_writer.h"
6 6
7 #include "tools/gn/builder.h"
8 #include "tools/gn/loader.h"
7 #include "tools/gn/location.h" 9 #include "tools/gn/location.h"
8 #include "tools/gn/ninja_build_writer.h" 10 #include "tools/gn/ninja_build_writer.h"
9 #include "tools/gn/ninja_toolchain_writer.h" 11 #include "tools/gn/ninja_toolchain_writer.h"
10 12
11 NinjaWriter::NinjaWriter(const BuildSettings* build_settings) 13 NinjaWriter::NinjaWriter(const BuildSettings* build_settings,
12 : build_settings_(build_settings) { 14 Builder* builder)
15 : build_settings_(build_settings),
16 builder_(builder) {
13 } 17 }
14 18
15 NinjaWriter::~NinjaWriter() { 19 NinjaWriter::~NinjaWriter() {
16 } 20 }
17 21
18 // static 22 // static
19 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings) { 23 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings,
20 NinjaWriter writer(build_settings); 24 Builder* builder) {
25 NinjaWriter writer(build_settings, builder);
21 26
22 std::vector<const Settings*> all_settings; 27 std::vector<const Settings*> all_settings;
23 std::vector<const Target*> default_targets; 28 std::vector<const Target*> default_targets;
24 if (!writer.WriteToolchains(std::set<std::string>(), 29 if (!writer.WriteToolchains(&all_settings, &default_targets))
25 &all_settings, &default_targets))
26 return false; 30 return false;
27 return writer.WriteRootBuildfiles(all_settings, default_targets); 31 return writer.WriteRootBuildfiles(all_settings, default_targets);
28 } 32 }
29 33
30 // static 34 // static
31 bool NinjaWriter::RunAndWriteToolchainFiles( 35 bool NinjaWriter::RunAndWriteToolchainFiles(
32 const BuildSettings* build_settings, 36 const BuildSettings* build_settings,
33 const std::set<std::string>& skip_files, 37 Builder* builder,
34 std::vector<const Settings*>* all_settings) { 38 std::vector<const Settings*>* all_settings) {
35 NinjaWriter writer(build_settings); 39 NinjaWriter writer(build_settings, builder);
36 std::vector<const Target*> default_targets; 40 std::vector<const Target*> default_targets;
37 return writer.WriteToolchains(skip_files, all_settings, &default_targets); 41 return writer.WriteToolchains(all_settings, &default_targets);
38 } 42 }
39 43
40 bool NinjaWriter::WriteToolchains( 44 bool NinjaWriter::WriteToolchains(std::vector<const Settings*>* all_settings,
41 const std::set<std::string>& skip_files, 45 std::vector<const Target*>* default_targets) {
42 std::vector<const Settings*>* all_settings,
43 std::vector<const Target*>* default_targets) {
44 // Categorize all targets by toolchain. 46 // Categorize all targets by toolchain.
45 typedef std::map<Label, std::vector<const Target*> > CategorizedMap; 47 typedef std::map<Label, std::vector<const Target*> > CategorizedMap;
46 CategorizedMap categorized; 48 CategorizedMap categorized;
47 49
48 std::vector<const Target*> all_targets; 50 std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords();
49 build_settings_->target_manager().GetAllTargets(&all_targets); 51 for (size_t i = 0; i < all_records.size(); i++) {
50 if (all_targets.empty()) { 52 if (all_records[i]->type() == BuilderRecord::ITEM_TARGET &&
53 all_records[i]->should_generate()) {
54 categorized[all_records[i]->label().GetToolchainLabel()].push_back(
55 all_records[i]->item()->AsTarget());
56 }
57 }
58 if (categorized.empty()) {
51 Err(Location(), "No targets.", 59 Err(Location(), "No targets.",
52 "I could not find any targets to write, so I'm doing nothing.") 60 "I could not find any targets to write, so I'm doing nothing.")
53 .PrintToStdout(); 61 .PrintToStdout();
54 return false; 62 return false;
55 } 63 }
56 for (size_t i = 0; i < all_targets.size(); i++) {
57 categorized[all_targets[i]->label().GetToolchainLabel()].push_back(
58 all_targets[i]);
59 }
60 64
61 Label default_label = 65 Label default_label = builder_->loader()->GetDefaultToolchain();
62 build_settings_->toolchain_manager().GetDefaultToolchainUnlocked();
63 66
64 // Write out the toolchain buildfiles, and also accumulate the set of 67 // Write out the toolchain buildfiles, and also accumulate the set of
65 // all settings and find the list of targets in the default toolchain. 68 // all settings and find the list of targets in the default toolchain.
66 for (CategorizedMap::const_iterator i = categorized.begin(); 69 for (CategorizedMap::const_iterator i = categorized.begin();
67 i != categorized.end(); ++i) { 70 i != categorized.end(); ++i) {
68 const Settings* settings; 71 const Settings* settings =
69 { 72 builder_->loader()->GetToolchainSettings(i->first);
70 base::AutoLock lock(build_settings_->item_tree().lock()); 73 const Toolchain* toolchain = builder_->GetToolchain(i->first);
71 Err ignored; 74
72 settings =
73 build_settings_->toolchain_manager().GetSettingsForToolchainLocked(
74 LocationRange(), i->first, &ignored);
75 }
76 all_settings->push_back(settings); 75 all_settings->push_back(settings);
77 if (!NinjaToolchainWriter::RunAndWriteFile(settings, i->second, 76 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain,
78 skip_files)) { 77 i->second)) {
79 Err(Location(), 78 Err(Location(),
80 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout(); 79 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout();
81 return false; 80 return false;
82 } 81 }
83 } 82 }
84 83
85 *default_targets = categorized[ 84 *default_targets = categorized[default_label];
86 build_settings_->toolchain_manager().GetDefaultToolchainUnlocked()];
87 return true; 85 return true;
88 } 86 }
89 87
90 bool NinjaWriter::WriteRootBuildfiles( 88 bool NinjaWriter::WriteRootBuildfiles(
91 const std::vector<const Settings*>& all_settings, 89 const std::vector<const Settings*>& all_settings,
92 const std::vector<const Target*>& default_targets) { 90 const std::vector<const Target*>& default_targets) {
93 // Write the root buildfile. 91 // Write the root buildfile.
94 if (!NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings, 92 if (!NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings,
95 default_targets)) { 93 default_targets)) {
96 Err(Location(), 94 Err(Location(),
97 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout(); 95 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout();
98 return false; 96 return false;
99 } 97 }
100 return true; 98 return true;
101 } 99 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_writer.h ('k') | tools/gn/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698