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_SCRIPT_TARGET_WRITER_H_ | 5 #ifndef TOOLS_GN_NINJA_SCRIPT_TARGET_WRITER_H_ |
6 #define TOOLS_GN_NINJA_SCRIPT_TARGET_WRITER_H_ | 6 #define TOOLS_GN_NINJA_SCRIPT_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; | 14 class FileTemplate; |
15 class OutputFile; | 15 class OutputFile; |
16 | 16 |
17 // Writes a .ninja file for a custom script target type. | 17 // Writes a .ninja file for a custom script target type. |
18 class NinjaScriptTargetWriter : public NinjaTargetWriter { | 18 class NinjaScriptTargetWriter : public NinjaTargetWriter { |
19 public: | 19 public: |
20 NinjaScriptTargetWriter(const Target* target, std::ostream& out); | 20 NinjaScriptTargetWriter(const Target* target, std::ostream& out); |
21 virtual ~NinjaScriptTargetWriter(); | 21 virtual ~NinjaScriptTargetWriter(); |
22 | 22 |
23 virtual void Run() OVERRIDE; | 23 virtual void Run() OVERRIDE; |
24 | 24 |
25 private: | 25 private: |
26 FRIEND_TEST_ALL_PREFIXES(NinjaScriptTargetWriter, | 26 FRIEND_TEST_ALL_PREFIXES(NinjaScriptTargetWriter, |
27 WriteOutputFilesForBuildLine); | 27 WriteOutputFilesForBuildLine); |
28 FRIEND_TEST_ALL_PREFIXES(NinjaScriptTargetWriter, | 28 FRIEND_TEST_ALL_PREFIXES(NinjaScriptTargetWriter, |
| 29 WriteOutputFilesForBuildLineWithDepfile); |
| 30 FRIEND_TEST_ALL_PREFIXES(NinjaScriptTargetWriter, |
29 WriteArgsSubstitutions); | 31 WriteArgsSubstitutions); |
30 | 32 |
31 bool has_sources() const { return !target_->sources().empty(); } | 33 bool has_sources() const { return !target_->sources().empty(); } |
32 | 34 |
33 // Writes the Ninja rule for invoking the script. | 35 // Writes the Ninja rule for invoking the script. |
34 // | 36 // |
35 // Returns the name of the custom rule generated. This will be based on the | 37 // Returns the name of the custom rule generated. This will be based on the |
36 // target name, and will include the string "$unique_name" if there are | 38 // target name, and will include the string "$unique_name" if there are |
37 // multiple inputs. | 39 // multiple inputs. |
38 std::string WriteRuleDefinition(const FileTemplate& args_template); | 40 std::string WriteRuleDefinition(const FileTemplate& args_template); |
(...skipping 17 matching lines...) Expand all Loading... |
56 // of the script into one thing that other targets can depend on. | 58 // of the script into one thing that other targets can depend on. |
57 void WriteStamp(const std::vector<OutputFile>& output_files); | 59 void WriteStamp(const std::vector<OutputFile>& output_files); |
58 | 60 |
59 // Writes the output files generated by the output template for the given | 61 // Writes the output files generated by the output template for the given |
60 // source file. This will start with a space and will not include a newline. | 62 // source file. This will start with a space and will not include a newline. |
61 // Appends the output files to the given vector. | 63 // Appends the output files to the given vector. |
62 void WriteOutputFilesForBuildLine(const FileTemplate& output_template, | 64 void WriteOutputFilesForBuildLine(const FileTemplate& output_template, |
63 const SourceFile& source, | 65 const SourceFile& source, |
64 std::vector<OutputFile>* output_files); | 66 std::vector<OutputFile>* output_files); |
65 | 67 |
| 68 void WriteDepfile(const SourceFile& source); |
| 69 |
| 70 // Returns the FileTemplate for the depfile variable. |
| 71 FileTemplate GetDepfileTemplate() const; |
| 72 |
66 // Path output writer that doesn't do any escaping or quoting. It does, | 73 // Path output writer that doesn't do any escaping or quoting. It does, |
67 // however, convert slashes. Used for | 74 // however, convert slashes. Used for |
68 // computing intermediate strings. | 75 // computing intermediate strings. |
69 PathOutput path_output_no_escaping_; | 76 PathOutput path_output_no_escaping_; |
70 | 77 |
71 DISALLOW_COPY_AND_ASSIGN(NinjaScriptTargetWriter); | 78 DISALLOW_COPY_AND_ASSIGN(NinjaScriptTargetWriter); |
72 }; | 79 }; |
73 | 80 |
74 #endif // TOOLS_GN_NINJA_SCRIPT_TARGET_WRITER_H_ | 81 #endif // TOOLS_GN_NINJA_SCRIPT_TARGET_WRITER_H_ |
OLD | NEW |