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/scope.h"
12#include "tools/gn/value.h"
13
14// Holds information on a specific toolchain. This data is filled in when we
15// encounter a toolchain definition.
16//
17// This class is an Item so it can participate in dependency management. In
18// particular, when a target uses a toolchain, it should have a dependency on
19// that toolchain's object so that we can be sure we loaded the toolchain
20// before generating the build for that target.
21//
22// Note on threadsafety: The label of the toolchain never changes so can
23// safetly be accessed from any thread at any time (we do this when asking for
24// the toolchain name). But the values in the toolchain do, so these can't
25// be accessed until this Item is resolved.
26class Toolchain : public Item {
27 public:
28  enum ToolType {
29    TYPE_NONE = 0,
30    TYPE_CC,
31    TYPE_CXX,
32    TYPE_OBJC,
33    TYPE_OBJCXX,
34    TYPE_RC,
35    TYPE_ASM,
36    TYPE_ALINK,
37    TYPE_SOLINK,
38    TYPE_LINK,
39    TYPE_STAMP,
40    TYPE_COPY,
41
42    TYPE_NUMTYPES  // Must be last.
43  };
44
45  static const char* kToolCc;
46  static const char* kToolCxx;
47  static const char* kToolObjC;
48  static const char* kToolObjCxx;
49  static const char* kToolRc;
50  static const char* kToolAsm;
51  static const char* kToolAlink;
52  static const char* kToolSolink;
53  static const char* kToolLink;
54  static const char* kToolStamp;
55  static const char* kToolCopy;
56
57  struct Tool {
58    Tool();
59    ~Tool();
60
61    std::string command;
62    std::string depfile;
63    std::string deps;
64    std::string description;
65    std::string lib_dir_prefix;
66    std::string lib_prefix;
67    std::string pool;
68    std::string restat;
69    std::string rspfile;
70    std::string rspfile_content;
71  };
72
73  Toolchain(const Settings* settings, const Label& label);
74  virtual ~Toolchain();
75
76  // Item overrides.
77  virtual Toolchain* AsToolchain() OVERRIDE;
78  virtual const Toolchain* AsToolchain() const OVERRIDE;
79
80  // Returns TYPE_NONE on failure.
81  static ToolType ToolNameToType(const base::StringPiece& str);
82  static std::string ToolTypeToName(ToolType type);
83
84  const Tool& GetTool(ToolType type) const;
85  void SetTool(ToolType type, const Tool& t);
86
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_; }
93
94 private:
95  Tool tools_[TYPE_NUMTYPES];
96
97  Scope::KeyValueMap args_;
98};
99
100#endif  // TOOLS_GN_TOOLCHAIN_H_
101