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_TARGET_WRITER_H_ 6 #define TOOLS_GN_NINJA_TARGET_WRITER_H_ 7 8 #include <iosfwd> 9 10 #include "base/basictypes.h" 11 #include "tools/gn/path_output.h" 12 #include "tools/gn/substitution_type.h" 13 14 class FileTemplate; 15 class OutputFile; 16 class Settings; 17 class Target; 18 19 // Generates one target's ".ninja" file. The toplevel "build.ninja" file is 20 // generated by the NinjaBuildWriter. 21 class NinjaTargetWriter { 22 public: 23 NinjaTargetWriter(const Target* target, std::ostream& out); 24 virtual ~NinjaTargetWriter(); 25 26 static void RunAndWriteFile(const Target* target); 27 28 virtual void Run() = 0; 29 30 protected: 31 // Writes out the substitution values that are shared between the different 32 // types of tools (target gen dir, target label, etc.). Only the substitutions 33 // identified by the given bits will be written. 34 void WriteSharedVars(const SubstitutionBits& bits); 35 36 // Writes to the output stream a stamp rule for input dependencies, and 37 // returns the file to be appended to source rules that encodes the 38 // order-only dependencies for the current target. The returned OutputFile 39 // will be empty if there are no implicit dependencies and no extra target 40 // dependencies passed in. 41 OutputFile WriteInputDepsStampAndGetDep( 42 const std::vector<const Target*>& extra_hard_deps) const; 43 44 // Writes to the output file a final stamp rule for the target that stamps 45 // the given list of files. This function assumes the stamp is for the target 46 // as a whole so the stamp file is set as the target's dependency output. 47 void WriteStampForTarget(const std::vector<OutputFile>& deps, 48 const std::vector<OutputFile>& order_only_deps); 49 50 const Settings* settings_; // Non-owning. 51 const Target* target_; // Non-owning. 52 std::ostream& out_; 53 PathOutput path_output_; 54 55 private: 56 void WriteCopyRules(); 57 58 DISALLOW_COPY_AND_ASSIGN(NinjaTargetWriter); 59 }; 60 61 #endif // TOOLS_GN_NINJA_TARGET_WRITER_H_ 62