OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "tools/gn/ninja_writer.h" | |
6 | |
7 #include "tools/gn/location.h" | |
8 #include "tools/gn/ninja_build_writer.h" | |
9 #include "tools/gn/ninja_toolchain_writer.h" | |
10 | |
11 | |
12 NinjaWriter::NinjaWriter(const BuildSettings* build_settings) | |
13 : build_settings_(build_settings) { | |
14 } | |
15 | |
16 NinjaWriter::~NinjaWriter() { | |
17 } | |
18 | |
19 // static | |
20 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings) { | |
21 NinjaWriter writer(build_settings); | |
22 return writer.WriteRootBuildfiles(); | |
23 } | |
24 | |
25 bool NinjaWriter::WriteRootBuildfiles() { | |
26 // Categorize all targets by toolchain. | |
27 typedef std::map<Label, std::vector<const Target*> > CategorizedMap; | |
28 CategorizedMap categorized; | |
29 | |
30 std::vector<const Target*> all_targets; | |
31 build_settings_->target_manager().GetAllTargets(&all_targets); | |
32 for (size_t i = 0; i < all_targets.size(); i++) { | |
33 categorized[all_targets[i]->label().GetToolchainLabel()].push_back( | |
34 all_targets[i]); | |
35 } | |
36 | |
37 Label default_label = | |
38 build_settings_->toolchain_manager().GetDefaultToolchainUnlocked(); | |
39 | |
40 // Write out the toolchain buildfiles, and also accumulate the set of | |
41 // all settings and find the list of targets in the default toolchain. | |
42 std::vector<const Settings*> all_settings; | |
43 const std::vector<const Target*>* default_targets = NULL; | |
44 for (CategorizedMap::const_iterator i = categorized.begin(); | |
45 i != categorized.end(); ++i) { | |
46 const Settings* settings; | |
47 { | |
48 base::AutoLock lock(build_settings_->item_tree().lock()); | |
49 Err ignored; | |
50 settings = | |
51 build_settings_->toolchain_manager().GetSettingsForToolchainLocked( | |
52 LocationRange(), i->first, &ignored); | |
53 } | |
54 if (i->first == default_label) | |
55 default_targets = &i->second; | |
56 all_settings.push_back(settings); | |
57 if (!NinjaToolchainWriter::RunAndWriteFile(settings, i->second)) | |
58 return false; | |
59 } | |
60 | |
61 // Write the root buildfile. | |
62 return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings, | |
63 *default_targets); | |
64 } | |
OLD | NEW |