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 #ifndef TOOLS_GN_NINJA_BUILD_WRITER_H_ | 5 #ifndef TOOLS_GN_NINJA_BUILD_WRITER_H_ |
6 #define TOOLS_GN_NINJA_BUILD_WRITER_H_ | 6 #define TOOLS_GN_NINJA_BUILD_WRITER_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "tools/gn/path_output.h" | 13 #include "tools/gn/path_output.h" |
14 | 14 |
15 class Builder; | 15 class Builder; |
16 class BuildSettings; | 16 class BuildSettings; |
17 class Err; | 17 class Err; |
18 class Pool; | 18 class Pool; |
19 class Settings; | 19 class Settings; |
20 class Target; | 20 class Target; |
21 class Toolchain; | 21 class Toolchain; |
22 | 22 |
23 // Generates the toplevel "build.ninja" file. This references the individual | 23 // Generates the toplevel "build.ninja" file. This references the individual |
24 // toolchain files and lists all input .gn files as dependencies of the | 24 // toolchain files and lists all input .gn files as dependencies of the |
25 // build itself. | 25 // build itself. |
26 class NinjaBuildWriter { | 26 class NinjaBuildWriter { |
27 public: | 27 public: |
28 NinjaBuildWriter( | 28 NinjaBuildWriter(const BuildSettings* settings, |
29 const BuildSettings* settings, | 29 const std::unordered_map<const Settings*, const Toolchain*>& |
30 const std::map<const Settings*, const Toolchain*>& used_toolchains, | 30 used_toolchains, |
31 const Toolchain* default_toolchain, | 31 const Toolchain* default_toolchain, |
32 const std::vector<const Target*>& default_toolchain_targets, | 32 const std::vector<const Target*>& default_toolchain_targets, |
33 std::ostream& out, | 33 std::ostream& out, |
34 std::ostream& dep_out); | 34 std::ostream& dep_out); |
35 ~NinjaBuildWriter(); | 35 ~NinjaBuildWriter(); |
36 | 36 |
37 // The design of this class is that this static factory function takes the | 37 // The design of this class is that this static factory function takes the |
38 // Builder, extracts the relevant information, and passes it to the class | 38 // Builder, extracts the relevant information, and passes it to the class |
39 // constructor. The class itself doesn't depend on the Builder at all which | 39 // constructor. The class itself doesn't depend on the Builder at all which |
40 // makes testing much easier (tests integrating various functions along with | 40 // makes testing much easier (tests integrating various functions along with |
41 // the Builder get very complicated). | 41 // the Builder get very complicated). |
42 static bool RunAndWriteFile( | 42 static bool RunAndWriteFile( |
43 const BuildSettings* settings, | 43 const BuildSettings* settings, |
44 const Builder& builder, | 44 const Builder& builder, |
45 Err* err); | 45 Err* err); |
46 | 46 |
47 bool Run(Err* err); | 47 bool Run(Err* err); |
48 | 48 |
49 private: | 49 private: |
50 void WriteNinjaRules(); | 50 void WriteNinjaRules(); |
51 void WriteAllPools(); | 51 void WriteAllPools(); |
52 void WriteSubninjas(); | 52 void WriteSubninjas(); |
53 bool WritePhonyAndAllRules( | 53 bool WritePhonyAndAllRules( |
54 Err* err); | 54 Err* err); |
55 | 55 |
56 void WritePhonyRule(const Target* target, const std::string& phony_name); | 56 void WritePhonyRule(const Target* target, const std::string& phony_name); |
57 | 57 |
58 const BuildSettings* build_settings_; | 58 const BuildSettings* build_settings_; |
59 | 59 |
60 const std::map<const Settings*, const Toolchain*>& used_toolchains_; | 60 const std::unordered_map<const Settings*, const Toolchain*>& used_toolchains_; |
61 const Toolchain* default_toolchain_; | 61 const Toolchain* default_toolchain_; |
62 const std::vector<const Target*>& default_toolchain_targets_; | 62 const std::vector<const Target*>& default_toolchain_targets_; |
63 | 63 |
64 std::ostream& out_; | 64 std::ostream& out_; |
65 std::ostream& dep_out_; | 65 std::ostream& dep_out_; |
66 PathOutput path_output_; | 66 PathOutput path_output_; |
67 | 67 |
68 DISALLOW_COPY_AND_ASSIGN(NinjaBuildWriter); | 68 DISALLOW_COPY_AND_ASSIGN(NinjaBuildWriter); |
69 }; | 69 }; |
70 | 70 |
71 #endif // TOOLS_GN_NINJA_BUILD_WRITER_H_ | 71 #endif // TOOLS_GN_NINJA_BUILD_WRITER_H_ |
72 | 72 |
OLD | NEW |