[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / gn / ninja_binary_target_writer.h
blobdb2b15d12afb8a610677f0fc1282fdc4d656869b
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.
5 #ifndef TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_
6 #define TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_
8 #include "base/macros.h"
9 #include "tools/gn/config_values.h"
10 #include "tools/gn/ninja_target_writer.h"
11 #include "tools/gn/toolchain.h"
12 #include "tools/gn/unique_vector.h"
14 struct EscapeOptions;
15 class SourceFileTypeSet;
17 // Writes a .ninja file for a binary target type (an executable, a shared
18 // library, or a static library).
19 class NinjaBinaryTargetWriter : public NinjaTargetWriter {
20 public:
21 class SourceFileTypeSet;
23 NinjaBinaryTargetWriter(const Target* target, std::ostream& out);
24 ~NinjaBinaryTargetWriter() override;
26 void Run() override;
28 private:
29 typedef std::set<OutputFile> OutputFileSet;
31 // Writes all flags for the compiler: includes, defines, cflags, etc.
32 void WriteCompilerVars(const SourceFileTypeSet& used_types);
34 // has_precompiled_headers is set when this substitution matches a tool type
35 // that supports precompiled headers, and this target supports precompiled
36 // headers. It doesn't indicate if the tool has precompiled headers (this
37 // will be looked up by this function).
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);
49 // Writes build lines required for precompiled headers. Any generated
50 // object files will be appended to the |object_files|. Any generated
51 // non-object files (for instance, .gch files from a GCC toolchain, are
52 // appended to |other_files|).
54 // input_dep is the stamp file collecting the dependencies required before
55 // compiling this target. It will be empty if there are no input deps.
56 void WritePCHCommands(const SourceFileTypeSet& used_types,
57 const OutputFile& input_dep,
58 std::vector<OutputFile>* object_files,
59 std::vector<OutputFile>* other_files);
61 // Writes a .pch compile build line for a language type.
62 void WritePCHCommand(SubstitutionType flag_type,
63 Toolchain::ToolType tool_type,
64 Tool::PrecompiledHeaderType header_type,
65 const OutputFile& input_dep,
66 std::vector<OutputFile>* object_files,
67 std::vector<OutputFile>* other_files);
69 void WriteGCCPCHCommand(SubstitutionType flag_type,
70 Toolchain::ToolType tool_type,
71 const OutputFile& order_only_dep,
72 std::vector<OutputFile>* gch_files);
74 void WriteWindowsPCHCommand(SubstitutionType flag_type,
75 Toolchain::ToolType tool_type,
76 const OutputFile& order_only_dep,
77 std::vector<OutputFile>* object_files);
79 // pch_deps are additional dependencies to run before the rule. They are
80 // expected to abide by the naming conventions specified by GetPCHOutputFiles.
82 // order_only_dep is the name of the stamp file that covers the dependencies
83 // that must be run before doing any compiles.
85 // The files produced by the compiler will be added to two output vectors.
86 void WriteSources(const std::vector<OutputFile>& pch_deps,
87 const OutputFile& order_only_dep,
88 std::vector<OutputFile>* object_files,
89 std::vector<SourceFile>* other_files);
91 // Writes a build line.
92 void WriteCompilerBuildLine(const SourceFile& source,
93 const std::vector<OutputFile>& extra_deps,
94 const OutputFile& order_only_dep,
95 Toolchain::ToolType tool_type,
96 const std::vector<OutputFile>& outputs);
98 void WriteLinkerStuff(const std::vector<OutputFile>& object_files,
99 const std::vector<SourceFile>& other_files);
100 void WriteLinkerFlags(const SourceFile* optional_def_file);
101 void WriteLibs();
102 void WriteOutputExtension();
103 void WriteSolibs(const std::vector<OutputFile>& solibs);
105 // Writes the stamp line for a source set. These are not linked.
106 void WriteSourceSetStamp(const std::vector<OutputFile>& object_files);
108 // Gets all target dependencies and classifies them, as well as accumulates
109 // object files from source sets we need to link.
110 void GetDeps(UniqueVector<OutputFile>* extra_object_files,
111 UniqueVector<const Target*>* linkable_deps,
112 UniqueVector<const Target*>* non_linkable_deps) const;
114 // Classifies the dependency as linkable or nonlinkable with the current
115 // target, adding it to the appropriate vector. If the dependency is a source
116 // set we should link in, the source set's object files will be appended to
117 // |extra_object_files|.
118 void ClassifyDependency(const Target* dep,
119 UniqueVector<OutputFile>* extra_object_files,
120 UniqueVector<const Target*>* linkable_deps,
121 UniqueVector<const Target*>* non_linkable_deps) const;
123 // Writes the implicit dependencies for the link or stamp line. This is
124 // the "||" and everything following it on the ninja line.
126 // The order-only dependencies are the non-linkable deps passed in as an
127 // argument, plus the data file depdencies in the target.
128 void WriteOrderOnlyDependencies(
129 const UniqueVector<const Target*>& non_linkable_deps);
131 // Returns the computed name of the Windows .pch file for the given
132 // tool type. The tool must support precompiled headers.
133 OutputFile GetWindowsPCHFile(Toolchain::ToolType tool_type) const;
135 // Checks for duplicates in the given list of output files. If any duplicates
136 // are found, throws an error and return false.
137 bool CheckForDuplicateObjectFiles(const std::vector<OutputFile>& files) const;
139 const Tool* tool_;
141 // Cached version of the prefix used for rule types for this toolchain.
142 std::string rule_prefix_;
144 DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter);
147 #endif // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_