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_TOOLCHAIN_H_ 6 #define TOOLS_GN_TOOLCHAIN_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/strings/string_piece.h" 10 #include "tools/gn/item.h" 11 12 // Holds information on a specific toolchain. This data is filled in when we 13 // encounter a toolchain definition. 14 // 15 // This class is an Item so it can participate in dependency management. In 16 // particular, when a target uses a toolchain, it should have a dependency on 17 // that toolchain's object so that we can be sure we loaded the toolchain 18 // before generating the build for that target. 19 // 20 // Note on threadsafety: The label of the toolchain never changes so can 21 // safetly be accessed from any thread at any time (we do this when asking for 22 // the toolchain name). But the values in the toolchain do, so these can't 23 // be accessed until this Item is resolved. 24 class Toolchain : public Item { 25 public: 26 enum ToolType { 27 TYPE_NONE = 0, 28 TYPE_CC, 29 TYPE_CXX, 30 TYPE_OBJC, 31 TYPE_OBJCXX, 32 TYPE_ASM, 33 TYPE_ALINK, 34 TYPE_SOLINK, 35 TYPE_LINK, 36 TYPE_STAMP, 37 TYPE_COPY, 38 39 TYPE_NUMTYPES // Must be last. 40 }; 41 42 static const char* kToolCc; 43 static const char* kToolCxx; 44 static const char* kToolObjC; 45 static const char* kToolObjCxx; 46 static const char* kToolAsm; 47 static const char* kToolAlink; 48 static const char* kToolSolink; 49 static const char* kToolLink; 50 static const char* kToolStamp; 51 static const char* kToolCopy; 52 53 struct Tool { 54 Tool(); 55 ~Tool(); 56 57 bool empty() const { 58 return command.empty() && depfile.empty() && deps.empty() && 59 description.empty() && pool.empty() && restat.empty() && 60 rspfile.empty() && rspfile_content.empty(); 61 } 62 63 std::string command; 64 std::string depfile; 65 std::string deps; 66 std::string description; 67 std::string pool; 68 std::string restat; 69 std::string rspfile; 70 std::string rspfile_content; 71 }; 72 73 Toolchain(const Label& label); 74 virtual ~Toolchain(); 75 76 // Item overrides. 77 virtual Toolchain* AsToolchain() OVERRIDE; 78 virtual const Toolchain* AsToolchain() const OVERRIDE; 79 80 // Returns TYPE_NONE on failure. 81 static ToolType ToolNameToType(const base::StringPiece& str); 82 static std::string ToolTypeToName(ToolType type); 83 84 const Tool& GetTool(ToolType type) const; 85 void SetTool(ToolType type, const Tool& t); 86 87 const std::string& environment() const { return environment_; } 88 void set_environment(const std::string& env) { environment_ = env; } 89 90 private: 91 Tool tools_[TYPE_NUMTYPES]; 92 93 std::string environment_; 94 }; 95 96 #endif // TOOLS_GN_TOOLCHAIN_H_ 97