Change next_proto member type.
[chromium-blink-merge.git] / tools / gn / toolchain.cc
blob341a48cf185c50ff9eaf1ba70ebeaf0cb9f5bd78
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.
5 #include "tools/gn/toolchain.h"
7 #include <string.h>
9 #include "base/logging.h"
10 #include "tools/gn/target.h"
11 #include "tools/gn/value.h"
13 const char* Toolchain::kToolCc = "cc";
14 const char* Toolchain::kToolCxx = "cxx";
15 const char* Toolchain::kToolObjC = "objc";
16 const char* Toolchain::kToolObjCxx = "objcxx";
17 const char* Toolchain::kToolRc = "rc";
18 const char* Toolchain::kToolAsm = "asm";
19 const char* Toolchain::kToolAlink = "alink";
20 const char* Toolchain::kToolSolink = "solink";
21 const char* Toolchain::kToolLink = "link";
22 const char* Toolchain::kToolStamp = "stamp";
23 const char* Toolchain::kToolCopy = "copy";
25 Toolchain::Toolchain(const Settings* settings, const Label& label)
26 : Item(settings, label),
27 concurrent_links_(0),
28 setup_complete_(false) {
31 Toolchain::~Toolchain() {
34 Toolchain* Toolchain::AsToolchain() {
35 return this;
38 const Toolchain* Toolchain::AsToolchain() const {
39 return this;
42 // static
43 Toolchain::ToolType Toolchain::ToolNameToType(const base::StringPiece& str) {
44 if (str == kToolCc) return TYPE_CC;
45 if (str == kToolCxx) return TYPE_CXX;
46 if (str == kToolObjC) return TYPE_OBJC;
47 if (str == kToolObjCxx) return TYPE_OBJCXX;
48 if (str == kToolRc) return TYPE_RC;
49 if (str == kToolAsm) return TYPE_ASM;
50 if (str == kToolAlink) return TYPE_ALINK;
51 if (str == kToolSolink) return TYPE_SOLINK;
52 if (str == kToolLink) return TYPE_LINK;
53 if (str == kToolStamp) return TYPE_STAMP;
54 if (str == kToolCopy) return TYPE_COPY;
55 return TYPE_NONE;
58 // static
59 std::string Toolchain::ToolTypeToName(ToolType type) {
60 switch (type) {
61 case TYPE_CC: return kToolCc;
62 case TYPE_CXX: return kToolCxx;
63 case TYPE_OBJC: return kToolObjC;
64 case TYPE_OBJCXX: return kToolObjCxx;
65 case TYPE_RC: return kToolRc;
66 case TYPE_ASM: return kToolAsm;
67 case TYPE_ALINK: return kToolAlink;
68 case TYPE_SOLINK: return kToolSolink;
69 case TYPE_LINK: return kToolLink;
70 case TYPE_STAMP: return kToolStamp;
71 case TYPE_COPY: return kToolCopy;
72 default:
73 NOTREACHED();
74 return std::string();
78 const Tool* Toolchain::GetTool(ToolType type) const {
79 DCHECK(type != TYPE_NONE);
80 return tools_[static_cast<size_t>(type)].get();
83 void Toolchain::SetTool(ToolType type, scoped_ptr<Tool> t) {
84 DCHECK(type != TYPE_NONE);
85 DCHECK(!tools_[type].get());
86 t->SetComplete();
87 tools_[type] = t.Pass();
90 void Toolchain::ToolchainSetupComplete() {
91 // Collect required bits from all tools.
92 for (size_t i = 0; i < TYPE_NUMTYPES; i++) {
93 if (tools_[i])
94 substitution_bits_.MergeFrom(tools_[i]->substitution_bits());
97 setup_complete_ = true;
100 // static
101 Toolchain::ToolType Toolchain::GetToolTypeForSourceType(SourceFileType type) {
102 switch (type) {
103 case SOURCE_C:
104 return TYPE_CC;
105 case SOURCE_CC:
106 return TYPE_CXX;
107 case SOURCE_M:
108 return TYPE_OBJC;
109 case SOURCE_MM:
110 return TYPE_OBJCXX;
111 case SOURCE_ASM:
112 case SOURCE_S:
113 return TYPE_ASM;
114 case SOURCE_RC:
115 return TYPE_RC;
116 case SOURCE_UNKNOWN:
117 case SOURCE_H:
118 case SOURCE_O:
119 return TYPE_NONE;
120 default:
121 NOTREACHED();
122 return TYPE_NONE;
126 const Tool* Toolchain::GetToolForSourceType(SourceFileType type) {
127 return tools_[GetToolTypeForSourceType(type)].get();
130 // static
131 Toolchain::ToolType Toolchain::GetToolTypeForTargetFinalOutput(
132 const Target* target) {
133 // The contents of this list might be suprising (i.e. stamp tool for copy
134 // rules). See the header for why.
135 switch (target->output_type()) {
136 case Target::GROUP:
137 return TYPE_STAMP;
138 case Target::EXECUTABLE:
139 return Toolchain::TYPE_LINK;
140 case Target::SHARED_LIBRARY:
141 return Toolchain::TYPE_SOLINK;
142 case Target::STATIC_LIBRARY:
143 return Toolchain::TYPE_ALINK;
144 case Target::SOURCE_SET:
145 return TYPE_STAMP;
146 case Target::COPY_FILES:
147 case Target::ACTION:
148 case Target::ACTION_FOREACH:
149 return TYPE_STAMP;
150 default:
151 NOTREACHED();
152 return Toolchain::TYPE_NONE;
156 const Tool* Toolchain::GetToolForTargetFinalOutput(const Target* target) const {
157 return tools_[GetToolTypeForTargetFinalOutput(target)].get();