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_BINARY_TARGET_WRITER_H_ | 5 #ifndef TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ |
6 #define TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ | 6 #define TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "tools/gn/config_values.h" | 9 #include "tools/gn/config_values.h" |
10 #include "tools/gn/ninja_target_writer.h" | 10 #include "tools/gn/ninja_target_writer.h" |
11 #include "tools/gn/toolchain.h" | 11 #include "tools/gn/toolchain.h" |
12 #include "tools/gn/unique_vector.h" | 12 #include "tools/gn/unique_vector.h" |
13 | 13 |
14 struct EscapeOptions; | 14 struct EscapeOptions; |
15 class SourceFileTypeSet; | |
15 | 16 |
16 // Writes a .ninja file for a binary target type (an executable, a shared | 17 // Writes a .ninja file for a binary target type (an executable, a shared |
17 // library, or a static library). | 18 // library, or a static library). |
18 class NinjaBinaryTargetWriter : public NinjaTargetWriter { | 19 class NinjaBinaryTargetWriter : public NinjaTargetWriter { |
19 public: | 20 public: |
21 class SourceFileTypeSet; | |
22 | |
20 NinjaBinaryTargetWriter(const Target* target, std::ostream& out); | 23 NinjaBinaryTargetWriter(const Target* target, std::ostream& out); |
21 ~NinjaBinaryTargetWriter() override; | 24 ~NinjaBinaryTargetWriter() override; |
22 | 25 |
23 void Run() override; | 26 void Run() override; |
24 | 27 |
25 private: | 28 private: |
26 typedef std::set<OutputFile> OutputFileSet; | 29 typedef std::set<OutputFile> OutputFileSet; |
27 | 30 |
28 void WriteCompilerVars(); | 31 // Writes all flags for the compiler: includes, defines, cflags, etc. |
29 void WriteSources(std::vector<OutputFile>* object_files, | 32 void WriteCompilerVars(const SourceFileTypeSet& used_types); |
33 | |
34 // has_precompiled_headers is set when this substitution matches a tool thpe | |
scottmg
2015/06/29 21:49:17
thpe->type
| |
35 // that supports precompiled headers, and this target support precompiled | |
scottmg
2015/06/29 21:49:17
second "support" -> "supports"
| |
36 // headers. It doesn't indicate if the tool has precompiled headers (this | |
37 // will be looked up by this function). | |
38 // | |
39 // The tool_type indicates the corresponding tool for flags that are | |
40 // tool-specific (e.g. "cflags_c"). For non-tool-specific flags (e.g. | |
41 // "defines") tool_type should be TYPE_NONE. | |
42 void WriteOneFlag( | |
43 SubstitutionType subst_enum, | |
44 bool has_precompiled_headers, | |
45 Toolchain::ToolType tool_type, | |
46 const std::vector<std::string>& (ConfigValues::* getter)() const, | |
47 EscapeOptions flag_escape_options); | |
48 | |
49 // Writes build lines required for precompiled headers. Any generated | |
50 // object files will be appended to the given vector. | |
51 // | |
52 // input_dep is the stamp file collecting the dependencies required before | |
53 // compiling this target. It will be empty if there are no input deps. | |
54 void WritePrecompiledHeaderCommands(const SourceFileTypeSet& used_types, | |
55 const OutputFile& input_dep, | |
56 std::vector<OutputFile>* object_files); | |
57 | |
58 // Writes a Windows .pch compile build line for a language type. | |
59 void WriteWindowsPCHCommand(SubstitutionType flag_type, | |
60 Toolchain::ToolType tool_type, | |
61 const OutputFile& input_dep, | |
62 std::vector<OutputFile>* object_files); | |
63 | |
64 // extra_deps are additional dependencies to run before the rule. | |
65 // | |
66 // iorder_only_dep is the name of the stamp file that covers the dependencies | |
67 // that must be run before doing any compiles. | |
68 // | |
69 // The files produced by the compiler will be added to two output vectors. | |
70 void WriteSources(const std::vector<OutputFile>& extra_deps, | |
71 const OutputFile& order_only_dep, | |
72 std::vector<OutputFile>* object_files, | |
30 std::vector<SourceFile>* other_files); | 73 std::vector<SourceFile>* other_files); |
74 | |
75 // Writes a build line. | |
76 void WriteCompilerBuildLine(const SourceFile& source, | |
77 const std::vector<OutputFile>& extra_deps, | |
78 const OutputFile& order_only_dep, | |
79 Toolchain::ToolType tool_type, | |
80 const std::vector<OutputFile>& outputs); | |
81 | |
31 void WriteLinkerStuff(const std::vector<OutputFile>& object_files, | 82 void WriteLinkerStuff(const std::vector<OutputFile>& object_files, |
32 const std::vector<SourceFile>& other_files); | 83 const std::vector<SourceFile>& other_files); |
33 void WriteLinkerFlags(const SourceFile* optional_def_file); | 84 void WriteLinkerFlags(const SourceFile* optional_def_file); |
34 void WriteLibs(); | 85 void WriteLibs(); |
35 void WriteOutputExtension(); | 86 void WriteOutputExtension(); |
36 void WriteSolibs(const std::vector<OutputFile>& solibs); | 87 void WriteSolibs(const std::vector<OutputFile>& solibs); |
37 | 88 |
38 // Writes the stamp line for a source set. These are not linked. | 89 // Writes the stamp line for a source set. These are not linked. |
39 void WriteSourceSetStamp(const std::vector<OutputFile>& object_files); | 90 void WriteSourceSetStamp(const std::vector<OutputFile>& object_files); |
40 | 91 |
(...skipping 13 matching lines...) Expand all Loading... | |
54 UniqueVector<const Target*>* non_linkable_deps) const; | 105 UniqueVector<const Target*>* non_linkable_deps) const; |
55 | 106 |
56 // Writes the implicit dependencies for the link or stamp line. This is | 107 // Writes the implicit dependencies for the link or stamp line. This is |
57 // the "||" and everything following it on the ninja line. | 108 // the "||" and everything following it on the ninja line. |
58 // | 109 // |
59 // The order-only dependencies are the non-linkable deps passed in as an | 110 // The order-only dependencies are the non-linkable deps passed in as an |
60 // argument, plus the data file depdencies in the target. | 111 // argument, plus the data file depdencies in the target. |
61 void WriteOrderOnlyDependencies( | 112 void WriteOrderOnlyDependencies( |
62 const UniqueVector<const Target*>& non_linkable_deps); | 113 const UniqueVector<const Target*>& non_linkable_deps); |
63 | 114 |
64 // Computes the set of output files resulting from compiling the given source | 115 // Returns the computed name of the Windows .pch file for the given |
65 // file. If the file can be compiled and the tool exists, fills the outputs in | 116 // tool type. The tool must support precompiled headers. |
66 // and writes the tool type to computed_tool_type. If the file is not | 117 OutputFile GetWindowsPCHFile(Toolchain::ToolType tool_type) const; |
67 // compilable, returns false. | |
68 // | |
69 // The target that the source belongs to is passed as an argument. In the | |
70 // case of linking to source sets, this can be different than the target | |
71 // this class is currently writing. | |
72 // | |
73 // The function can succeed with a "NONE" tool type for object files which are | |
74 // just passed to the output. The output will always be overwritten, not | |
75 // appended to. | |
76 bool GetOutputFilesForSource(const Target* target, | |
77 const SourceFile& source, | |
78 Toolchain::ToolType* computed_tool_type, | |
79 std::vector<OutputFile>* outputs) const; | |
80 | 118 |
81 const Tool* tool_; | 119 const Tool* tool_; |
82 | 120 |
121 // Cached version of the prefix used for rule types for this toolchain. | |
122 std::string rule_prefix_; | |
123 | |
83 DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter); | 124 DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter); |
84 }; | 125 }; |
85 | 126 |
86 #endif // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ | 127 #endif // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ |
87 | 128 |
OLD | NEW |