Change next_proto member type.
[chromium-blink-merge.git] / tools / gn / toolchain.h
blobc94d8ed5505bf585c666ee93f59cd020ab9796b4
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 #ifndef TOOLS_GN_TOOLCHAIN_H_
6 #define TOOLS_GN_TOOLCHAIN_H_
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_piece.h"
11 #include "tools/gn/item.h"
12 #include "tools/gn/label_ptr.h"
13 #include "tools/gn/scope.h"
14 #include "tools/gn/source_file_type.h"
15 #include "tools/gn/substitution_type.h"
16 #include "tools/gn/tool.h"
17 #include "tools/gn/value.h"
19 // Holds information on a specific toolchain. This data is filled in when we
20 // encounter a toolchain definition.
22 // This class is an Item so it can participate in dependency management. In
23 // particular, when a target uses a toolchain, it should have a dependency on
24 // that toolchain's object so that we can be sure we loaded the toolchain
25 // before generating the build for that target.
27 // Note on threadsafety: The label of the toolchain never changes so can
28 // safely be accessed from any thread at any time (we do this when asking for
29 // the toolchain name). But the values in the toolchain do, so these can't
30 // be accessed until this Item is resolved.
31 class Toolchain : public Item {
32 public:
33 enum ToolType {
34 TYPE_NONE = 0,
35 TYPE_CC,
36 TYPE_CXX,
37 TYPE_OBJC,
38 TYPE_OBJCXX,
39 TYPE_RC,
40 TYPE_ASM,
41 TYPE_ALINK,
42 TYPE_SOLINK,
43 TYPE_LINK,
44 TYPE_STAMP,
45 TYPE_COPY,
47 TYPE_NUMTYPES // Must be last.
50 static const char* kToolCc;
51 static const char* kToolCxx;
52 static const char* kToolObjC;
53 static const char* kToolObjCxx;
54 static const char* kToolRc;
55 static const char* kToolAsm;
56 static const char* kToolAlink;
57 static const char* kToolSolink;
58 static const char* kToolLink;
59 static const char* kToolStamp;
60 static const char* kToolCopy;
62 Toolchain(const Settings* settings, const Label& label);
63 ~Toolchain() override;
65 // Item overrides.
66 Toolchain* AsToolchain() override;
67 const Toolchain* AsToolchain() const override;
69 // Returns TYPE_NONE on failure.
70 static ToolType ToolNameToType(const base::StringPiece& str);
71 static std::string ToolTypeToName(ToolType type);
73 // Returns null if the tool hasn't been defined.
74 const Tool* GetTool(ToolType type) const;
76 // Set a tool. When all tools are configured, you should call
77 // ToolchainSetupComplete().
78 void SetTool(ToolType type, scoped_ptr<Tool> t);
80 // Does final setup on the toolchain once all tools are known.
81 void ToolchainSetupComplete();
83 // Targets that must be resolved before compiling any targets.
84 const LabelTargetVector& deps() const { return deps_; }
85 LabelTargetVector& deps() { return deps_; }
87 // Specifies build argument overrides that will be set on the base scope. It
88 // will be as if these arguments were passed in on the command line. This
89 // allows a toolchain to override the OS type of the default toolchain or
90 // pass in other settings.
91 Scope::KeyValueMap& args() { return args_; }
92 const Scope::KeyValueMap& args() const { return args_; }
94 // Returns the tool for compiling the given source file type.
95 static ToolType GetToolTypeForSourceType(SourceFileType type);
96 const Tool* GetToolForSourceType(SourceFileType type);
98 // Returns the tool that produces the final output for the given target type.
99 // This isn't necessarily the tool you would expect. For copy target, this
100 // will return the stamp tool ionstead since the final output of a copy
101 // target is to stamp the set of copies done so there is one output.
102 static ToolType GetToolTypeForTargetFinalOutput(const Target* target);
103 const Tool* GetToolForTargetFinalOutput(const Target* target) const;
105 const SubstitutionBits& substitution_bits() const {
106 DCHECK(setup_complete_);
107 return substitution_bits_;
110 void set_concurrent_links(int cl) { concurrent_links_ = cl; }
111 int concurrent_links() const { return concurrent_links_; }
113 private:
114 scoped_ptr<Tool> tools_[TYPE_NUMTYPES];
116 // How many links to run in parallel. Only the default toolchain's version of
117 // this variable applies.
118 int concurrent_links_;
120 bool setup_complete_;
122 // Substitutions used by the tools in this toolchain.
123 SubstitutionBits substitution_bits_;
125 LabelTargetVector deps_;
126 Scope::KeyValueMap args_;
129 #endif // TOOLS_GN_TOOLCHAIN_H_