Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: tools/gn/toolchain.h

Issue 440333002: Support more configurability in GN toolchains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef TOOLS_GN_TOOLCHAIN_H_ 5 #ifndef TOOLS_GN_TOOLCHAIN_H_
6 #define TOOLS_GN_TOOLCHAIN_H_ 6 #define TOOLS_GN_TOOLCHAIN_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
10 #include "tools/gn/item.h" 12 #include "tools/gn/item.h"
11 #include "tools/gn/label_ptr.h" 13 #include "tools/gn/label_ptr.h"
12 #include "tools/gn/scope.h" 14 #include "tools/gn/scope.h"
15 #include "tools/gn/source_file_type.h"
16 #include "tools/gn/substitution_type.h"
17 #include "tools/gn/tool.h"
13 #include "tools/gn/value.h" 18 #include "tools/gn/value.h"
14 19
15 // Holds information on a specific toolchain. This data is filled in when we 20 // Holds information on a specific toolchain. This data is filled in when we
16 // encounter a toolchain definition. 21 // encounter a toolchain definition.
17 // 22 //
18 // This class is an Item so it can participate in dependency management. In 23 // This class is an Item so it can participate in dependency management. In
19 // particular, when a target uses a toolchain, it should have a dependency on 24 // particular, when a target uses a toolchain, it should have a dependency on
20 // that toolchain's object so that we can be sure we loaded the toolchain 25 // that toolchain's object so that we can be sure we loaded the toolchain
21 // before generating the build for that target. 26 // before generating the build for that target.
22 // 27 //
23 // Note on threadsafety: The label of the toolchain never changes so can 28 // Note on threadsafety: The label of the toolchain never changes so can
24 // safetly be accessed from any thread at any time (we do this when asking for 29 // safetly be accessed from any thread at any time (we do this when asking for
jamesr 2014/08/19 19:30:42 typo 'safetly' -> 'safely'
25 // the toolchain name). But the values in the toolchain do, so these can't 30 // the toolchain name). But the values in the toolchain do, so these can't
26 // be accessed until this Item is resolved. 31 // be accessed until this Item is resolved.
27 class Toolchain : public Item { 32 class Toolchain : public Item {
28 public: 33 public:
29 enum ToolType { 34 enum ToolType {
30 TYPE_NONE = 0, 35 TYPE_NONE = 0,
31 TYPE_CC, 36 TYPE_CC,
32 TYPE_CXX, 37 TYPE_CXX,
33 TYPE_OBJC, 38 TYPE_OBJC,
34 TYPE_OBJCXX, 39 TYPE_OBJCXX,
(...skipping 13 matching lines...) Expand all
48 static const char* kToolObjC; 53 static const char* kToolObjC;
49 static const char* kToolObjCxx; 54 static const char* kToolObjCxx;
50 static const char* kToolRc; 55 static const char* kToolRc;
51 static const char* kToolAsm; 56 static const char* kToolAsm;
52 static const char* kToolAlink; 57 static const char* kToolAlink;
53 static const char* kToolSolink; 58 static const char* kToolSolink;
54 static const char* kToolLink; 59 static const char* kToolLink;
55 static const char* kToolStamp; 60 static const char* kToolStamp;
56 static const char* kToolCopy; 61 static const char* kToolCopy;
57 62
58 struct Tool {
59 Tool();
60 ~Tool();
61
62 std::string command;
63 std::string depfile;
64 std::string depsformat;
65 std::string description;
66 std::string lib_dir_prefix;
67 std::string lib_prefix;
68 std::string pool;
69 std::string restat;
70 std::string rspfile;
71 std::string rspfile_content;
72 };
73
74 Toolchain(const Settings* settings, const Label& label); 63 Toolchain(const Settings* settings, const Label& label);
75 virtual ~Toolchain(); 64 virtual ~Toolchain();
76 65
77 // Item overrides. 66 // Item overrides.
78 virtual Toolchain* AsToolchain() OVERRIDE; 67 virtual Toolchain* AsToolchain() OVERRIDE;
79 virtual const Toolchain* AsToolchain() const OVERRIDE; 68 virtual const Toolchain* AsToolchain() const OVERRIDE;
80 69
81 // Returns TYPE_NONE on failure. 70 // Returns TYPE_NONE on failure.
82 static ToolType ToolNameToType(const base::StringPiece& str); 71 static ToolType ToolNameToType(const base::StringPiece& str);
83 static std::string ToolTypeToName(ToolType type); 72 static std::string ToolTypeToName(ToolType type);
84 73
85 const Tool& GetTool(ToolType type) const; 74 // Returns null if the tool hasn't been defined.
86 void SetTool(ToolType type, const Tool& t); 75 const Tool* GetTool(ToolType type) const;
76
77 // Set a tool. When all tools are configured, you should call
78 // ToolchainSetupComplete().
79 void SetTool(ToolType type, scoped_ptr<Tool> t);
80
81 // Does final setup on the toolchain once all tools are known.
82 void ToolchainSetupComplete();
87 83
88 // Targets that must be resolved before compiling any targets. 84 // Targets that must be resolved before compiling any targets.
89 const LabelTargetVector& deps() const { return deps_; } 85 const LabelTargetVector& deps() const { return deps_; }
90 LabelTargetVector& deps() { return deps_; } 86 LabelTargetVector& deps() { return deps_; }
91 87
92 // Specifies build argument overrides that will be set on the base scope. It 88 // Specifies build argument overrides that will be set on the base scope. It
93 // will be as if these arguments were passed in on the command line. This 89 // will be as if these arguments were passed in on the command line. This
94 // allows a toolchain to override the OS type of the default toolchain or 90 // allows a toolchain to override the OS type of the default toolchain or
95 // pass in other settings. 91 // pass in other settings.
96 Scope::KeyValueMap& args() { return args_; } 92 Scope::KeyValueMap& args() { return args_; }
97 const Scope::KeyValueMap& args() const { return args_; } 93 const Scope::KeyValueMap& args() const { return args_; }
98 94
95 // Returns the tool for compiling the given source file type.
96 static ToolType GetToolTypeForSourceType(SourceFileType type);
97 const Tool* GetToolForSourceType(SourceFileType type);
98
99 // Returns the tool that produces the final output for the given target type.
100 // This isn't necessarily the tool you would expect. For copy target, this
101 // will return the stamp tool ionstead since the final output of a copy
102 // target is to stamp the set of copies done so there is one output.
103 static ToolType GetToolTypeForTargetFinalOutput(const Target* target);
104 const Tool* GetToolForTargetFinalOutput(const Target* target) const;
105
106 const SubstitutionBits& substitution_bits() const {
107 DCHECK(setup_complete_);
108 return substitution_bits_;
109 }
110
99 private: 111 private:
100 Tool tools_[TYPE_NUMTYPES]; 112 scoped_ptr<Tool> tools_[TYPE_NUMTYPES];
113
114 bool setup_complete_;
115
116 // Substitutions used by the tools in this toolchain.
117 SubstitutionBits substitution_bits_;
101 118
102 LabelTargetVector deps_; 119 LabelTargetVector deps_;
103 Scope::KeyValueMap args_; 120 Scope::KeyValueMap args_;
104 }; 121 };
105 122
106 #endif // TOOLS_GN_TOOLCHAIN_H_ 123 #endif // TOOLS_GN_TOOLCHAIN_H_
OLDNEW
« tools/gn/tool.cc ('K') | « tools/gn/tool.cc ('k') | tools/gn/toolchain.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698