Roll src/third_party/skia ff271c2:b679ca8
[chromium-blink-merge.git] / tools / gn / setup.h
blob2e0e3677dd182bd66d43ac02840461fc7e3dc4b5
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_SETUP_H_
6 #define TOOLS_GN_SETUP_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "tools/gn/build_settings.h"
14 #include "tools/gn/builder.h"
15 #include "tools/gn/label_pattern.h"
16 #include "tools/gn/loader.h"
17 #include "tools/gn/scheduler.h"
18 #include "tools/gn/scope.h"
19 #include "tools/gn/settings.h"
20 #include "tools/gn/token.h"
21 #include "tools/gn/toolchain.h"
23 class InputFile;
24 class ParseNode;
26 namespace base {
27 class CommandLine;
30 extern const char kDotfile_Help[];
32 // Helper class to setup the build settings and environment for the various
33 // commands to run.
34 class Setup {
35 public:
36 Setup();
37 ~Setup();
39 // Configures the build for the current command line. On success returns
40 // true. On failure, prints the error and returns false.
42 // The parameter is the string the user specified for the build directory. We
43 // will try to interpret this as a SourceDir if possible, and will fail if is
44 // is malformed.
46 // With force_create = false, setup will fail if the build directory doesn't
47 // alreay exist with an args file in it. With force_create set to true, the
48 // directory will be created if necessary. Commands explicitly doing
49 // generation should set this to true to create it, but querying commands
50 // should set it to false to prevent creating oddly-named directories in case
51 // the user omits the build directory argument (which is easy to do).
52 bool DoSetup(const std::string& build_dir, bool force_create);
54 // Runs the load, returning true on success. On failure, prints the error
55 // and returns false. This includes both RunPreMessageLoop() and
56 // RunPostMessageLoop().
57 bool Run();
59 Scheduler& scheduler() { return scheduler_; }
61 // Returns the file used to store the build arguments. Note that the path
62 // might not exist.
63 SourceFile GetBuildArgFile() const;
65 // Sets whether the build arguments should be filled during setup from the
66 // command line/build argument file. This will be true by default. The use
67 // case for setting it to false is when editing build arguments, we don't
68 // want to rely on them being valid.
69 void set_fill_arguments(bool fa) { fill_arguments_ = fa; }
71 // When true (the default), Run() will check for unresolved dependencies and
72 // cycles upon completion. When false, such errors will be ignored.
73 void set_check_for_bad_items(bool s) { check_for_bad_items_ = s; }
75 // When true (the default), RunPostMessageLoop will check for overrides that
76 // were specified but not used. When false, such errors will be ignored.
77 void set_check_for_unused_overrides(bool s) {
78 check_for_unused_overrides_ = s;
81 // After a successful run, setting this will additionally cause the public
82 // headers to be checked. Defaults to false.
83 void set_check_public_headers(bool s) {
84 check_public_headers_ = s;
87 // Read from the .gn file, these are the targets to check. If the .gn file
88 // does not specify anything, this will be null. If the .gn file specifies
89 // the empty list, this will be non-null but empty.
90 const std::vector<LabelPattern>* check_patterns() const {
91 return check_patterns_.get();
94 BuildSettings& build_settings() { return build_settings_; }
95 Builder* builder() { return builder_.get(); }
96 LoaderImpl* loader() { return loader_.get(); }
98 // Name of the file in the root build directory that contains the build
99 // arguements.
100 static const char kBuildArgFileName[];
102 private:
103 // Performs the two sets of operations to run the generation before and after
104 // the message loop is run.
105 void RunPreMessageLoop();
106 bool RunPostMessageLoop();
108 // Fills build arguments. Returns true on success.
109 bool FillArguments(const base::CommandLine& cmdline);
111 // Fills the build arguments from the command line or from the build arg file.
112 bool FillArgsFromCommandLine(const std::string& args);
113 bool FillArgsFromFile();
115 // Given an already-loaded args_input_file_, parses and saves the resulting
116 // arguments. Backend for the different FillArgs variants.
117 bool FillArgsFromArgsInputFile();
119 // Writes the build arguments to the build arg file.
120 bool SaveArgsToFile();
122 // Fills the root directory into the settings. Returns true on success.
123 bool FillSourceDir(const base::CommandLine& cmdline);
125 // Fills the build directory given the value the user has specified.
126 // Must happen after FillSourceDir so we can resolve source-relative
127 // paths. If require_exists is false, it will fail if the dir doesn't exist.
128 bool FillBuildDir(const std::string& build_dir, bool require_exists);
130 // Fills the python path portion of the command line. On failure, sets
131 // it to just "python".
132 void FillPythonPath();
134 // Run config file.
135 bool RunConfigFile();
137 bool FillOtherConfig(const base::CommandLine& cmdline);
139 BuildSettings build_settings_;
140 scoped_refptr<LoaderImpl> loader_;
141 scoped_refptr<Builder> builder_;
143 SourceFile root_build_file_;
145 bool check_for_bad_items_;
146 bool check_for_unused_overrides_;
147 bool check_public_headers_;
149 // See getter for info.
150 scoped_ptr<std::vector<LabelPattern>> check_patterns_;
152 Scheduler scheduler_;
154 // These empty settings and toolchain are used to interpret the command line
155 // and dot file.
156 BuildSettings empty_build_settings_;
157 Settings empty_settings_;
158 Scope dotfile_scope_;
160 // State for invoking the dotfile.
161 base::FilePath dotfile_name_;
162 scoped_ptr<InputFile> dotfile_input_file_;
163 std::vector<Token> dotfile_tokens_;
164 scoped_ptr<ParseNode> dotfile_root_;
166 // Set to true when we should populate the build arguments from the command
167 // line or build argument file. See setter above.
168 bool fill_arguments_;
170 // State for invoking the command line args. We specifically want to keep
171 // this around for the entire run so that Values can blame to the command
172 // line when we issue errors about them.
173 scoped_ptr<InputFile> args_input_file_;
174 std::vector<Token> args_tokens_;
175 scoped_ptr<ParseNode> args_root_;
177 DISALLOW_COPY_AND_ASSIGN(Setup);
180 #endif // TOOLS_GN_SETUP_H_