4ab54124f9fe31368181336235dc51858fcbeac7
[platform/framework/web/crosswalk.git] / src / tools / gn / toolchain.h
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.
4
5 #ifndef TOOLS_GN_TOOLCHAIN_H_
6 #define TOOLS_GN_TOOLCHAIN_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/strings/string_piece.h"
10 #include "tools/gn/item.h"
11 #include "tools/gn/label_ptr.h"
12 #include "tools/gn/scope.h"
13 #include "tools/gn/value.h"
14
15 // Holds information on a specific toolchain. This data is filled in when we
16 // encounter a toolchain definition.
17 //
18 // 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
20 // that toolchain's object so that we can be sure we loaded the toolchain
21 // before generating the build for that target.
22 //
23 // 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
25 // the toolchain name). But the values in the toolchain do, so these can't
26 // be accessed until this Item is resolved.
27 class Toolchain : public Item {
28  public:
29   enum ToolType {
30     TYPE_NONE = 0,
31     TYPE_CC,
32     TYPE_CXX,
33     TYPE_OBJC,
34     TYPE_OBJCXX,
35     TYPE_RC,
36     TYPE_ASM,
37     TYPE_ALINK,
38     TYPE_SOLINK,
39     TYPE_LINK,
40     TYPE_STAMP,
41     TYPE_COPY,
42
43     TYPE_NUMTYPES  // Must be last.
44   };
45
46   static const char* kToolCc;
47   static const char* kToolCxx;
48   static const char* kToolObjC;
49   static const char* kToolObjCxx;
50   static const char* kToolRc;
51   static const char* kToolAsm;
52   static const char* kToolAlink;
53   static const char* kToolSolink;
54   static const char* kToolLink;
55   static const char* kToolStamp;
56   static const char* kToolCopy;
57
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);
75   virtual ~Toolchain();
76
77   // Item overrides.
78   virtual Toolchain* AsToolchain() OVERRIDE;
79   virtual const Toolchain* AsToolchain() const OVERRIDE;
80
81   // Returns TYPE_NONE on failure.
82   static ToolType ToolNameToType(const base::StringPiece& str);
83   static std::string ToolTypeToName(ToolType type);
84
85   const Tool& GetTool(ToolType type) const;
86   void SetTool(ToolType type, const Tool& t);
87
88   // Targets that must be resolved before compiling any targets.
89   const LabelTargetVector& deps() const { return deps_; }
90   LabelTargetVector& deps() { return deps_; }
91
92   // 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
94   // allows a toolchain to override the OS type of the default toolchain or
95   // pass in other settings.
96   Scope::KeyValueMap& args() { return args_; }
97   const Scope::KeyValueMap& args() const { return args_; }
98
99  private:
100   Tool tools_[TYPE_NUMTYPES];
101
102   LabelTargetVector deps_;
103   Scope::KeyValueMap args_;
104 };
105
106 #endif  // TOOLS_GN_TOOLCHAIN_H_