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_ACTION_TARGET_WRITER_H_ | 5 #ifndef TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_ |
6 #define TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_ | 6 #define TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "tools/gn/ninja_target_writer.h" | 12 #include "tools/gn/ninja_target_writer.h" |
13 | 13 |
14 class FileTemplate; | |
15 class OutputFile; | 14 class OutputFile; |
16 | 15 |
17 // Writes a .ninja file for a action target type. | 16 // Writes a .ninja file for a action target type. |
18 class NinjaActionTargetWriter : public NinjaTargetWriter { | 17 class NinjaActionTargetWriter : public NinjaTargetWriter { |
19 public: | 18 public: |
20 NinjaActionTargetWriter(const Target* target, | 19 NinjaActionTargetWriter(const Target* target, |
21 const Toolchain* toolchain, | 20 const Toolchain* toolchain, |
22 std::ostream& out); | 21 std::ostream& out); |
23 virtual ~NinjaActionTargetWriter(); | 22 virtual ~NinjaActionTargetWriter(); |
24 | 23 |
25 virtual void Run() OVERRIDE; | 24 virtual void Run() OVERRIDE; |
26 | 25 |
27 private: | 26 private: |
28 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, | 27 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, |
29 WriteOutputFilesForBuildLine); | 28 WriteOutputFilesForBuildLine); |
30 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, | 29 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, |
31 WriteOutputFilesForBuildLineWithDepfile); | 30 WriteOutputFilesForBuildLineWithDepfile); |
32 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, | 31 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, |
33 WriteArgsSubstitutions); | 32 WriteArgsSubstitutions); |
34 | 33 |
35 bool has_sources() const { return !target_->sources().empty(); } | 34 bool has_sources() const { return !target_->sources().empty(); } |
36 | 35 |
37 // Writes the Ninja rule for invoking the script. | 36 // Writes the Ninja rule for invoking the script. |
38 // | 37 // |
39 // Returns the name of the custom rule generated. This will be based on the | 38 // Returns the name of the custom rule generated. This will be based on the |
40 // target name, and will include the string "$unique_name" if there are | 39 // target name, and will include the string "$unique_name" if there are |
41 // multiple inputs. | 40 // multiple inputs. |
42 std::string WriteRuleDefinition(const FileTemplate& args_template); | 41 std::string WriteRuleDefinition(); |
43 | 42 |
44 // Writes the rules for compiling each source, writing all output files | 43 // Writes the rules for compiling each source, writing all output files |
45 // to the given vector. | 44 // to the given vector. |
46 // | 45 // |
47 // implicit_deps is a precomputed string of all ninja files that are common | 46 // implicit_deps is a precomputed string of all ninja files that are common |
48 // to each build step, it starts with a "|" if it's nonempty. | 47 // to each build step, it starts with a "|" if it's nonempty. |
49 void WriteSourceRules(const std::string& custom_rule_name, | 48 void WriteSourceRules(const std::string& custom_rule_name, |
50 const std::string& implicit_deps, | 49 const std::string& implicit_deps, |
51 const FileTemplate& args_template, | |
52 std::vector<OutputFile>* output_files); | 50 std::vector<OutputFile>* output_files); |
53 | 51 |
54 // Writes the Ninja variables that expand the substitutions required by the | |
55 // arguments for the given source file. | |
56 void WriteArgsSubstitutions(const SourceFile& source, | |
57 const FileTemplate& args_template); | |
58 | |
59 // Writes the .stamp rule that names this target and collects all invocations | 52 // Writes the .stamp rule that names this target and collects all invocations |
60 // of the script into one thing that other targets can depend on. | 53 // of the script into one thing that other targets can depend on. |
61 void WriteStamp(const std::vector<OutputFile>& output_files); | 54 void WriteStamp(const std::vector<OutputFile>& output_files); |
62 | 55 |
63 // Writes the output files generated by the output template for the given | 56 // Writes the output files generated by the output template for the given |
64 // source file. This will start with a space and will not include a newline. | 57 // source file. This will start with a space and will not include a newline. |
65 // Appends the output files to the given vector. | 58 // Appends the output files to the given vector. |
66 void WriteOutputFilesForBuildLine(const FileTemplate& output_template, | 59 void WriteOutputFilesForBuildLine(const SourceFile& source, |
67 const SourceFile& source, | |
68 std::vector<OutputFile>* output_files); | 60 std::vector<OutputFile>* output_files); |
69 | 61 |
70 void WriteDepfile(const SourceFile& source); | 62 void WriteDepfile(const SourceFile& source); |
71 | 63 |
72 // Returns the FileTemplate for the depfile variable. | |
73 FileTemplate GetDepfileTemplate() const; | |
74 | |
75 // Path output writer that doesn't do any escaping or quoting. It does, | 64 // Path output writer that doesn't do any escaping or quoting. It does, |
76 // however, convert slashes. Used for | 65 // however, convert slashes. Used for |
77 // computing intermediate strings. | 66 // computing intermediate strings. |
78 PathOutput path_output_no_escaping_; | 67 PathOutput path_output_no_escaping_; |
79 | 68 |
80 DISALLOW_COPY_AND_ASSIGN(NinjaActionTargetWriter); | 69 DISALLOW_COPY_AND_ASSIGN(NinjaActionTargetWriter); |
81 }; | 70 }; |
82 | 71 |
83 #endif // TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_ | 72 #endif // TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_ |
OLD | NEW |