* Changing crash report limitation logic to have more control over extreme cases.
[chromium-blink-merge.git] / tools / gn / ninja_binary_target_writer.h
blob5888ac59bbac22c0ddda4788c2f12ca0adebc1e3
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 given vector.
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);
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);
64 // extra_deps are additional dependencies to run before the rule.
66 // iorder_only_dep is the name of the stamp file that covers the dependencies
67 // that must be run before doing any compiles.
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,
73 std::vector<SourceFile>* other_files);
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);
82 void WriteLinkerStuff(const std::vector<OutputFile>& object_files,
83 const std::vector<SourceFile>& other_files);
84 void WriteLinkerFlags(const SourceFile* optional_def_file);
85 void WriteLibs();
86 void WriteOutputExtension();
87 void WriteSolibs(const std::vector<OutputFile>& solibs);
89 // Writes the stamp line for a source set. These are not linked.
90 void WriteSourceSetStamp(const std::vector<OutputFile>& object_files);
92 // Gets all target dependencies and classifies them, as well as accumulates
93 // object files from source sets we need to link.
94 void GetDeps(UniqueVector<OutputFile>* extra_object_files,
95 UniqueVector<const Target*>* linkable_deps,
96 UniqueVector<const Target*>* non_linkable_deps) const;
98 // Classifies the dependency as linkable or nonlinkable with the current
99 // target, adding it to the appropriate vector. If the dependency is a source
100 // set we should link in, the source set's object files will be appended to
101 // |extra_object_files|.
102 void ClassifyDependency(const Target* dep,
103 UniqueVector<OutputFile>* extra_object_files,
104 UniqueVector<const Target*>* linkable_deps,
105 UniqueVector<const Target*>* non_linkable_deps) const;
107 // Writes the implicit dependencies for the link or stamp line. This is
108 // the "||" and everything following it on the ninja line.
110 // The order-only dependencies are the non-linkable deps passed in as an
111 // argument, plus the data file depdencies in the target.
112 void WriteOrderOnlyDependencies(
113 const UniqueVector<const Target*>& non_linkable_deps);
115 // Returns the computed name of the Windows .pch file for the given
116 // tool type. The tool must support precompiled headers.
117 OutputFile GetWindowsPCHFile(Toolchain::ToolType tool_type) const;
119 // Checks for duplicates in the given list of output files. If any duplicates
120 // are found, throws an error and return false.
121 bool CheckForDuplicateObjectFiles(const std::vector<OutputFile>& files) const;
123 const Tool* tool_;
125 // Cached version of the prefix used for rule types for this toolchain.
126 std::string rule_prefix_;
128 DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter);
131 #endif // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_