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"
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
),
28 setup_complete_(false) {
31 Toolchain::~Toolchain() {
34 Toolchain
* Toolchain::AsToolchain() {
38 const Toolchain
* Toolchain::AsToolchain() const {
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
;
59 std::string
Toolchain::ToolTypeToName(ToolType 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
;
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());
87 tools_
[type
] = t
.Pass();
90 void Toolchain::ToolchainSetupComplete() {
91 // Collect required bits from all tools.
92 for (const auto& tool
: tools_
) {
94 substitution_bits_
.MergeFrom(tool
->substitution_bits());
97 setup_complete_
= true;
101 Toolchain::ToolType
Toolchain::GetToolTypeForSourceType(SourceFileType type
) {
127 const Tool
* Toolchain::GetToolForSourceType(SourceFileType type
) {
128 return tools_
[GetToolTypeForSourceType(type
)].get();
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()) {
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
:
147 case Target::COPY_FILES
:
149 case Target::ACTION_FOREACH
:
153 return Toolchain::TYPE_NONE
;
157 const Tool
* Toolchain::GetToolForTargetFinalOutput(const Target
* target
) const {
158 return tools_
[GetToolTypeForTargetFinalOutput(target
)].get();