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