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_GYP_TARGET_WRITER_H_ 6 #define TOOLS_GN_GYP_TARGET_WRITER_H_ 7 8 #include <iosfwd> 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "tools/gn/gyp_helper.h" 13 #include "tools/gn/path_output.h" 14 15 class BuilderRecord; 16 class Err; 17 class Settings; 18 class SourceFile; 19 class Target; 20 class Toolchain; 21 22 class GypTargetWriter { 23 public: 24 struct TargetGroup { 25 TargetGroup() 26 : debug(NULL), 27 release(NULL), 28 host_debug(NULL), 29 host_release(NULL), 30 debug64(NULL), 31 release64(NULL) { 32 } 33 const BuilderRecord* debug; 34 const BuilderRecord* release; 35 36 // When the main compile is targeting a different architecture, these will 37 // contain the builds with the host system's toolchain. Only supported on 38 // Linux. 39 const BuilderRecord* host_debug; 40 const BuilderRecord* host_release; 41 42 // On Windows, we do both 32-bit and 64-bit builds. Null on non-Windows. 43 const BuilderRecord* debug64; 44 const BuilderRecord* release64; 45 }; 46 47 GypTargetWriter(const Target* target, 48 const Toolchain* toolchain, 49 const SourceDir& gyp_dir, 50 std::ostream& out); 51 virtual ~GypTargetWriter(); 52 53 static void WriteFile(const SourceFile& gyp_file, 54 const std::vector<TargetGroup>& targets, 55 const Toolchain* debug_toolchain, 56 Err* err); 57 58 virtual void Run() = 0; 59 60 protected: 61 // Writes the given number of spaces to the output stream and returns it. 62 std::ostream& Indent(int spaces); 63 static std::ostream& Indent(std::ostream& out, int spaces); 64 65 static const int kExtraIndent = 2; 66 67 const Settings* settings_; // Non-owning. 68 const Target* target_; // Non-owning. 69 const Toolchain* toolchain_; // Toolchain corresponding to target_. 70 SourceDir gyp_dir_; // Dir of GYP file. 71 std::ostream& out_; 72 73 GypHelper helper_; 74 PathOutput path_output_; 75 76 private: 77 DISALLOW_COPY_AND_ASSIGN(GypTargetWriter); 78 }; 79 80 #endif // TOOLS_GN_GYP_TARGET_WRITER_H_ 81