- add sources.
[platform/framework/web/crosswalk.git] / src / tools / gn / settings.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_SETTINGS_H_
6 #define TOOLS_GN_SETTINGS_H_
7
8 #include "base/files/file_path.h"
9 #include "tools/gn/build_settings.h"
10 #include "tools/gn/import_manager.h"
11 #include "tools/gn/output_file.h"
12 #include "tools/gn/scope.h"
13 #include "tools/gn/source_dir.h"
14 #include "tools/gn/toolchain.h"
15
16 // Holds the settings for one toolchain invocation. There will be one
17 // Settings object for each toolchain type, each referring to the same
18 // BuildSettings object for shared stuff.
19 //
20 // The Settings object is const once it is constructed, which allows us to
21 // use it from multiple threads during target generation without locking (which
22 // is important, because it gets used a lot).
23 //
24 // The Toolchain object holds the set of stuff that is set by the toolchain
25 // declaration, which obviously needs to be set later when we actually parse
26 // the file with the toolchain declaration in it.
27 class Settings {
28  public:
29   enum TargetOS {
30     UNKNOWN,
31     LINUX,
32     MAC,
33     WIN
34   };
35
36   // Constructs a toolchain settings. The output_subdir_name is the name we
37   // should use for the subdirectory in the build output directory for this
38   // toolchain's outputs. It should have no slashes in it. The default
39   // toolchain should use an empty string.
40   Settings(const BuildSettings* build_settings,
41            const std::string& output_subdir_name);
42   ~Settings();
43
44   const BuildSettings* build_settings() const { return build_settings_; }
45
46   const Label& toolchain_label() const { return toolchain_label_; }
47   void set_toolchain_label(const Label& l) { toolchain_label_ = l; }
48
49   // Indicates if this corresponds to the default toolchain.
50   bool is_default() const { return is_default_; }
51   void set_is_default(bool id) { is_default_ = id; }
52
53   bool IsMac() const { return target_os_ == MAC; }
54   bool IsLinux() const { return target_os_ == LINUX; }
55   bool IsWin() const { return target_os_ == WIN; }
56
57   TargetOS target_os() const { return target_os_; }
58   void set_target_os(TargetOS t) { target_os_ = t; }
59
60   const OutputFile& toolchain_output_subdir() const {
61     return toolchain_output_subdir_;
62   }
63   const SourceDir& toolchain_output_dir() const {
64     return toolchain_output_dir_;
65   }
66
67   // Directory for generated files.
68   const SourceDir& toolchain_gen_dir() const {
69     return toolchain_gen_dir_;
70   }
71
72   // The import manager caches the result of executing imported files in the
73   // context of a given settings object.
74   //
75   // See the ItemTree getter in GlobalSettings for why this doesn't return a
76   // const pointer.
77   ImportManager& import_manager() const { return import_manager_; }
78
79   const Scope* base_config() const { return &base_config_; }
80   Scope* base_config() { return &base_config_; }
81
82   // Set to true when every target we encounter should be generated. False
83   // means that only targets that have a dependency from (directly or
84   // indirectly) some magic root node are actually generated. See the comments
85   // on ItemTree for more.
86   bool greedy_target_generation() const {
87     return greedy_target_generation_;
88   }
89   void set_greedy_target_generation(bool gtg) {
90     greedy_target_generation_ = gtg;
91   }
92
93  private:
94   const BuildSettings* build_settings_;
95
96   Label toolchain_label_;
97   bool is_default_;
98
99   TargetOS target_os_;
100
101   mutable ImportManager import_manager_;
102
103   // The subdirectory inside the build output for this toolchain. For the
104   // default toolchain, this will be empty (since the deafult toolchain's
105   // output directory is the same as the build directory). When nonempty, this
106   // is guaranteed to end in a slash.
107   OutputFile toolchain_output_subdir_;
108
109   // Full source file path to the toolchain output directory.
110   SourceDir toolchain_output_dir_;
111
112   SourceDir toolchain_gen_dir_;
113
114   Scope base_config_;
115
116   bool greedy_target_generation_;
117
118   DISALLOW_COPY_AND_ASSIGN(Settings);
119 };
120
121 #endif  // TOOLS_GN_SETTINGS_H_