Add ICU message format support
[chromium-blink-merge.git] / tools / gn / toolchain.cc
blobcdd70c02f5546740fdf6adb3c4bd0929f21090ea
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 (const auto& tool : tools_) {
93 if (tool)
94 substitution_bits_.MergeFrom(tool->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_CPP:
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 case SOURCE_DEF:
120 return TYPE_NONE;
121 default:
122 NOTREACHED();
123 return TYPE_NONE;
127 const Tool* Toolchain::GetToolForSourceType(SourceFileType type) {
128 return tools_[GetToolTypeForSourceType(type)].get();
131 // static
132 Toolchain::ToolType Toolchain::GetToolTypeForTargetFinalOutput(
133 const Target* target) {
134 // The contents of this list might be suprising (i.e. stamp tool for copy
135 // rules). See the header for why.
136 switch (target->output_type()) {
137 case Target::GROUP:
138 return TYPE_STAMP;
139 case Target::EXECUTABLE:
140 return Toolchain::TYPE_LINK;
141 case Target::SHARED_LIBRARY:
142 return Toolchain::TYPE_SOLINK;
143 case Target::STATIC_LIBRARY:
144 return Toolchain::TYPE_ALINK;
145 case Target::SOURCE_SET:
146 return TYPE_STAMP;
147 case Target::COPY_FILES:
148 case Target::ACTION:
149 case Target::ACTION_FOREACH:
150 return TYPE_STAMP;
151 default:
152 NOTREACHED();
153 return Toolchain::TYPE_NONE;
157 const Tool* Toolchain::GetToolForTargetFinalOutput(const Target* target) const {
158 return tools_[GetToolTypeForTargetFinalOutput(target)].get();