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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "tools/gn/config_values.h" |
9 #include "tools/gn/ninja_target_writer.h" | 10 #include "tools/gn/ninja_target_writer.h" |
10 #include "tools/gn/toolchain.h" | 11 #include "tools/gn/toolchain.h" |
11 #include "tools/gn/unique_vector.h" | 12 #include "tools/gn/unique_vector.h" |
12 | 13 |
| 14 struct EscapeOptions; |
| 15 |
13 // Writes a .ninja file for a binary target type (an executable, a shared | 16 // Writes a .ninja file for a binary target type (an executable, a shared |
14 // library, or a static library). | 17 // library, or a static library). |
15 class NinjaBinaryTargetWriter : public NinjaTargetWriter { | 18 class NinjaBinaryTargetWriter : public NinjaTargetWriter { |
16 public: | 19 public: |
17 NinjaBinaryTargetWriter(const Target* target, | 20 NinjaBinaryTargetWriter(const Target* target, std::ostream& out); |
18 const Toolchain* toolchain, | |
19 std::ostream& out); | |
20 virtual ~NinjaBinaryTargetWriter(); | 21 virtual ~NinjaBinaryTargetWriter(); |
21 | 22 |
22 virtual void Run() OVERRIDE; | 23 virtual void Run() OVERRIDE; |
23 | 24 |
24 private: | 25 private: |
25 typedef std::set<OutputFile> OutputFileSet; | 26 typedef std::set<OutputFile> OutputFileSet; |
26 | 27 |
27 void WriteCompilerVars(); | 28 void WriteCompilerVars(); |
28 void WriteSources(std::vector<OutputFile>* object_files); | 29 void WriteSources(std::vector<OutputFile>* object_files); |
29 void WriteLinkerStuff(const std::vector<OutputFile>& object_files); | 30 void WriteLinkerStuff(const std::vector<OutputFile>& object_files); |
30 void WriteLinkerFlags(const Toolchain::Tool& tool, | 31 void WriteLinkerFlags(); |
31 const OutputFile& windows_manifest); | 32 void WriteLibs(); |
32 void WriteLibs(const Toolchain::Tool& tool); | 33 void WriteOutputExtension(); |
33 | 34 void WriteSolibs(const std::vector<OutputFile>& solibs); |
34 // Writes the build line for linking the target. Includes newline. | |
35 void WriteLinkCommand(const OutputFile& external_output_file, | |
36 const OutputFile& internal_output_file, | |
37 const std::vector<OutputFile>& object_files); | |
38 | 35 |
39 // Writes the stamp line for a source set. These are not linked. | 36 // Writes the stamp line for a source set. These are not linked. |
40 void WriteSourceSetStamp(const std::vector<OutputFile>& object_files); | 37 void WriteSourceSetStamp(const std::vector<OutputFile>& object_files); |
41 | 38 |
42 // Gets all target dependencies and classifies them, as well as accumulates | 39 // Gets all target dependencies and classifies them, as well as accumulates |
43 // object files from source sets we need to link. | 40 // object files from source sets we need to link. |
44 void GetDeps(UniqueVector<OutputFile>* extra_object_files, | 41 void GetDeps(UniqueVector<OutputFile>* extra_object_files, |
45 UniqueVector<const Target*>* linkable_deps, | 42 UniqueVector<const Target*>* linkable_deps, |
46 UniqueVector<const Target*>* non_linkable_deps) const; | 43 UniqueVector<const Target*>* non_linkable_deps) const; |
47 | 44 |
48 // Classifies the dependency as linkable or nonlinkable with the current | 45 // Classifies the dependency as linkable or nonlinkable with the current |
49 // target, adding it to the appropriate vector. If the dependency is a source | 46 // target, adding it to the appropriate vector. If the dependency is a source |
50 // set we should link in, the source set's object files will be appended to | 47 // set we should link in, the source set's object files will be appended to |
51 // |extra_object_files|. | 48 // |extra_object_files|. |
52 void ClassifyDependency(const Target* dep, | 49 void ClassifyDependency(const Target* dep, |
53 UniqueVector<OutputFile>* extra_object_files, | 50 UniqueVector<OutputFile>* extra_object_files, |
54 UniqueVector<const Target*>* linkable_deps, | 51 UniqueVector<const Target*>* linkable_deps, |
55 UniqueVector<const Target*>* non_linkable_deps) const; | 52 UniqueVector<const Target*>* non_linkable_deps) const; |
56 | 53 |
57 // Writes the implicit dependencies for the link or stamp line. This is | 54 // Writes the implicit dependencies for the link or stamp line. This is |
58 // the "||" and everything following it on the ninja line. | 55 // the "||" and everything following it on the ninja line. |
59 // | 56 // |
60 // The implicit dependencies are the non-linkable deps passed in as an | 57 // The order-only dependencies are the non-linkable deps passed in as an |
61 // argument, plus the data file depdencies in the target. | 58 // argument, plus the data file depdencies in the target. |
62 void WriteImplicitDependencies( | 59 void WriteOrderOnlyDependencies( |
63 const UniqueVector<const Target*>& non_linkable_deps); | 60 const UniqueVector<const Target*>& non_linkable_deps); |
64 | 61 |
65 Toolchain::ToolType tool_type_; | 62 // Computes the set of output files resulting from compiling the given source |
| 63 // file. If the file can be compiled and the tool exists, fills the outputs in |
| 64 // and writes the tool type to computed_tool_type. If the file is not |
| 65 // compilable, returns false. |
| 66 // |
| 67 // The target that the source belongs to is passed as an argument. In the |
| 68 // case of linking to source sets, this can be different than the target |
| 69 // this class is currently writing. |
| 70 // |
| 71 // The function can succeed with a "NONE" tool type for object files which are |
| 72 // just passed to the output. The output will always be overwritten, not |
| 73 // appended to. |
| 74 bool GetOutputFilesForSource(const Target* target, |
| 75 const SourceFile& source, |
| 76 Toolchain::ToolType* computed_tool_type, |
| 77 std::vector<OutputFile>* outputs) const; |
| 78 |
| 79 const Tool* tool_; |
66 | 80 |
67 DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter); | 81 DISALLOW_COPY_AND_ASSIGN(NinjaBinaryTargetWriter); |
68 }; | 82 }; |
69 | 83 |
70 #endif // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ | 84 #endif // TOOLS_GN_NINJA_BINARY_TARGET_WRITER_H_ |
71 | 85 |
OLD | NEW |