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. 4 5 #ifndef TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_ 6 #define TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_ 7 8 #include <vector> 9 10 #include "base/gtest_prod_util.h" 11 #include "gn/ninja_target_writer.h" 12 13 class OutputFile; 14 15 // Writes a .ninja file for a action target type. 16 class NinjaActionTargetWriter : public NinjaTargetWriter { 17 public: 18 NinjaActionTargetWriter(const Target* target, std::ostream& out); 19 ~NinjaActionTargetWriter() override; 20 21 void Run() override; 22 23 private: 24 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, 25 WriteOutputFilesForBuildLine); 26 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, 27 WriteOutputFilesForBuildLineWithDepfile); 28 FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, WriteArgsSubstitutions); 29 30 // Writes the Ninja rule for invoking the script. 31 // 32 // Returns the name of the custom rule generated. This will be based on the 33 // target name, and will include the string "$unique_name" if there are 34 // multiple inputs. 35 std::string WriteRuleDefinition(); 36 37 // Writes the rules for compiling each source, writing all output files 38 // to the given vector. 39 // 40 // input_deps are the dependencies common to all build steps. 41 void WriteSourceRules(const std::string& custom_rule_name, 42 const std::vector<OutputFile>& input_deps, 43 const std::vector<OutputFile>& order_only_deps, 44 std::vector<OutputFile>* output_files); 45 46 // Writes the output files generated by the output template for the given 47 // source file. This will start with a space and will not include a newline. 48 // Appends the output files to the given vector. 49 void WriteOutputFilesForBuildLine(const SourceFile& source, 50 std::vector<OutputFile>* output_files); 51 52 void WriteDepfile(const SourceFile& source); 53 54 // Writes variables that we make available to all actions, irrespective 55 // of whether they're associated with a specific source file. 56 void WriteNinjaVariablesForAction(); 57 58 // Path output writer that doesn't do any escaping or quoting. It does, 59 // however, convert slashes. Used for 60 // computing intermediate strings. 61 PathOutput path_output_no_escaping_; 62 63 NinjaActionTargetWriter(const NinjaActionTargetWriter&) = delete; 64 NinjaActionTargetWriter& operator=(const NinjaActionTargetWriter&) = delete; 65 }; 66 67 #endif // TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_ 68