| OLD | NEW |
| 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_SETUP_H_ | 5 #ifndef TOOLS_GN_SETUP_H_ |
| 6 #define TOOLS_GN_SETUP_H_ | 6 #define TOOLS_GN_SETUP_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 class InputFile; | 23 class InputFile; |
| 24 class ParseNode; | 24 class ParseNode; |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| 27 class CommandLine; | 27 class CommandLine; |
| 28 } | 28 } |
| 29 | 29 |
| 30 extern const char kDotfile_Help[]; | 30 extern const char kDotfile_Help[]; |
| 31 | 31 |
| 32 // Base class for code shared between Setup and DependentSetup. | 32 // Helper class to setup the build settings and environment for the various |
| 33 class CommonSetup { | 33 // commands to run. |
| 34 class Setup { |
| 34 public: | 35 public: |
| 35 virtual ~CommonSetup(); | 36 Setup(); |
| 37 ~Setup(); |
| 36 | 38 |
| 37 // Returns the scheduler. This is virtual since only the main setup has a | 39 // Configures the build for the current command line. On success returns |
| 38 // scheduler and the derived ones just store pointers. | 40 // true. On failure, prints the error and returns false. |
| 39 virtual Scheduler* GetScheduler() = 0; | 41 // |
| 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. |
| 45 // |
| 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); |
| 53 |
| 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(); |
| 58 |
| 59 Scheduler& scheduler() { return scheduler_; } |
| 60 |
| 61 // Returns the file used to store the build arguments. Note that the path |
| 62 // might not exist. |
| 63 SourceFile GetBuildArgFile() const; |
| 64 |
| 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; } |
| 40 | 70 |
| 41 // When true (the default), Run() will check for unresolved dependencies and | 71 // When true (the default), Run() will check for unresolved dependencies and |
| 42 // cycles upon completion. When false, such errors will be ignored. | 72 // cycles upon completion. When false, such errors will be ignored. |
| 43 void set_check_for_bad_items(bool s) { check_for_bad_items_ = s; } | 73 void set_check_for_bad_items(bool s) { check_for_bad_items_ = s; } |
| 44 | 74 |
| 45 // When true (the default), RunPostMessageLoop will check for overrides that | 75 // When true (the default), RunPostMessageLoop will check for overrides that |
| 46 // were specified but not used. When false, such errors will be ignored. | 76 // were specified but not used. When false, such errors will be ignored. |
| 47 void set_check_for_unused_overrides(bool s) { | 77 void set_check_for_unused_overrides(bool s) { |
| 48 check_for_unused_overrides_ = s; | 78 check_for_unused_overrides_ = s; |
| 49 } | 79 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 } | 92 } |
| 63 | 93 |
| 64 BuildSettings& build_settings() { return build_settings_; } | 94 BuildSettings& build_settings() { return build_settings_; } |
| 65 Builder* builder() { return builder_.get(); } | 95 Builder* builder() { return builder_.get(); } |
| 66 LoaderImpl* loader() { return loader_.get(); } | 96 LoaderImpl* loader() { return loader_.get(); } |
| 67 | 97 |
| 68 // Name of the file in the root build directory that contains the build | 98 // Name of the file in the root build directory that contains the build |
| 69 // arguements. | 99 // arguements. |
| 70 static const char kBuildArgFileName[]; | 100 static const char kBuildArgFileName[]; |
| 71 | 101 |
| 72 protected: | 102 private: |
| 73 CommonSetup(); | |
| 74 CommonSetup(const CommonSetup& other); | |
| 75 | |
| 76 // Performs the two sets of operations to run the generation before and after | 103 // Performs the two sets of operations to run the generation before and after |
| 77 // the message loop is run. | 104 // the message loop is run. |
| 78 void RunPreMessageLoop(); | 105 void RunPreMessageLoop(); |
| 79 bool RunPostMessageLoop(); | 106 bool RunPostMessageLoop(); |
| 80 | 107 |
| 81 BuildSettings build_settings_; | |
| 82 scoped_refptr<LoaderImpl> loader_; | |
| 83 scoped_refptr<Builder> builder_; | |
| 84 | |
| 85 SourceFile root_build_file_; | |
| 86 | |
| 87 bool check_for_bad_items_; | |
| 88 bool check_for_unused_overrides_; | |
| 89 bool check_public_headers_; | |
| 90 | |
| 91 // See getter for info. | |
| 92 scoped_ptr<std::vector<LabelPattern> > check_patterns_; | |
| 93 | |
| 94 private: | |
| 95 CommonSetup& operator=(const CommonSetup& other); // Disallow. | |
| 96 }; | |
| 97 | |
| 98 // Helper class to setup the build settings and environment for the various | |
| 99 // commands to run. | |
| 100 class Setup : public CommonSetup { | |
| 101 public: | |
| 102 Setup(); | |
| 103 ~Setup() override; | |
| 104 | |
| 105 // Configures the build for the current command line. On success returns | |
| 106 // true. On failure, prints the error and returns false. | |
| 107 // | |
| 108 // The parameter is the string the user specified for the build directory. We | |
| 109 // will try to interpret this as a SourceDir if possible, and will fail if is | |
| 110 // is malformed. | |
| 111 // | |
| 112 // With force_create = false, setup will fail if the build directory doesn't | |
| 113 // alreay exist with an args file in it. With force_create set to true, the | |
| 114 // directory will be created if necessary. Commands explicitly doing | |
| 115 // generation should set this to true to create it, but querying commands | |
| 116 // should set it to false to prevent creating oddly-named directories in case | |
| 117 // the user omits the build directory argument (which is easy to do). | |
| 118 bool DoSetup(const std::string& build_dir, bool force_create); | |
| 119 | |
| 120 // Runs the load, returning true on success. On failure, prints the error | |
| 121 // and returns false. This includes both RunPreMessageLoop() and | |
| 122 // RunPostMessageLoop(). | |
| 123 bool Run(); | |
| 124 | |
| 125 Scheduler& scheduler() { return scheduler_; } | |
| 126 | |
| 127 Scheduler* GetScheduler() override; | |
| 128 | |
| 129 // Returns the file used to store the build arguments. Note that the path | |
| 130 // might not exist. | |
| 131 SourceFile GetBuildArgFile() const; | |
| 132 | |
| 133 // Sets whether the build arguments should be filled during setup from the | |
| 134 // command line/build argument file. This will be true by default. The use | |
| 135 // case for setting it to false is when editing build arguments, we don't | |
| 136 // want to rely on them being valid. | |
| 137 void set_fill_arguments(bool fa) { fill_arguments_ = fa; } | |
| 138 | |
| 139 private: | |
| 140 // Fills build arguments. Returns true on success. | 108 // Fills build arguments. Returns true on success. |
| 141 bool FillArguments(const base::CommandLine& cmdline); | 109 bool FillArguments(const base::CommandLine& cmdline); |
| 142 | 110 |
| 143 // Fills the build arguments from the command line or from the build arg file. | 111 // Fills the build arguments from the command line or from the build arg file. |
| 144 bool FillArgsFromCommandLine(const std::string& args); | 112 bool FillArgsFromCommandLine(const std::string& args); |
| 145 bool FillArgsFromFile(); | 113 bool FillArgsFromFile(); |
| 146 | 114 |
| 147 // Given an already-loaded args_input_file_, parses and saves the resulting | 115 // Given an already-loaded args_input_file_, parses and saves the resulting |
| 148 // arguments. Backend for the different FillArgs variants. | 116 // arguments. Backend for the different FillArgs variants. |
| 149 bool FillArgsFromArgsInputFile(); | 117 bool FillArgsFromArgsInputFile(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 161 | 129 |
| 162 // Fills the python path portion of the command line. On failure, sets | 130 // Fills the python path portion of the command line. On failure, sets |
| 163 // it to just "python". | 131 // it to just "python". |
| 164 void FillPythonPath(); | 132 void FillPythonPath(); |
| 165 | 133 |
| 166 // Run config file. | 134 // Run config file. |
| 167 bool RunConfigFile(); | 135 bool RunConfigFile(); |
| 168 | 136 |
| 169 bool FillOtherConfig(const base::CommandLine& cmdline); | 137 bool FillOtherConfig(const base::CommandLine& cmdline); |
| 170 | 138 |
| 139 BuildSettings build_settings_; |
| 140 scoped_refptr<LoaderImpl> loader_; |
| 141 scoped_refptr<Builder> builder_; |
| 142 |
| 143 SourceFile root_build_file_; |
| 144 |
| 145 bool check_for_bad_items_; |
| 146 bool check_for_unused_overrides_; |
| 147 bool check_public_headers_; |
| 148 |
| 149 // See getter for info. |
| 150 scoped_ptr<std::vector<LabelPattern>> check_patterns_; |
| 151 |
| 171 Scheduler scheduler_; | 152 Scheduler scheduler_; |
| 172 | 153 |
| 173 // These empty settings and toolchain are used to interpret the command line | 154 // These empty settings and toolchain are used to interpret the command line |
| 174 // and dot file. | 155 // and dot file. |
| 175 BuildSettings empty_build_settings_; | 156 BuildSettings empty_build_settings_; |
| 176 Settings empty_settings_; | 157 Settings empty_settings_; |
| 177 Scope dotfile_scope_; | 158 Scope dotfile_scope_; |
| 178 | 159 |
| 179 // State for invoking the dotfile. | 160 // State for invoking the dotfile. |
| 180 base::FilePath dotfile_name_; | 161 base::FilePath dotfile_name_; |
| 181 scoped_ptr<InputFile> dotfile_input_file_; | 162 scoped_ptr<InputFile> dotfile_input_file_; |
| 182 std::vector<Token> dotfile_tokens_; | 163 std::vector<Token> dotfile_tokens_; |
| 183 scoped_ptr<ParseNode> dotfile_root_; | 164 scoped_ptr<ParseNode> dotfile_root_; |
| 184 | 165 |
| 185 // Set to true when we should populate the build arguments from the command | 166 // Set to true when we should populate the build arguments from the command |
| 186 // line or build argument file. See setter above. | 167 // line or build argument file. See setter above. |
| 187 bool fill_arguments_; | 168 bool fill_arguments_; |
| 188 | 169 |
| 189 // State for invoking the command line args. We specifically want to keep | 170 // State for invoking the command line args. We specifically want to keep |
| 190 // this around for the entire run so that Values can blame to the command | 171 // this around for the entire run so that Values can blame to the command |
| 191 // line when we issue errors about them. | 172 // line when we issue errors about them. |
| 192 scoped_ptr<InputFile> args_input_file_; | 173 scoped_ptr<InputFile> args_input_file_; |
| 193 std::vector<Token> args_tokens_; | 174 std::vector<Token> args_tokens_; |
| 194 scoped_ptr<ParseNode> args_root_; | 175 scoped_ptr<ParseNode> args_root_; |
| 195 | 176 |
| 196 DISALLOW_COPY_AND_ASSIGN(Setup); | 177 DISALLOW_COPY_AND_ASSIGN(Setup); |
| 197 }; | 178 }; |
| 198 | 179 |
| 199 // A dependent setup allows one to do more than one build at a time. You would | |
| 200 // make a dependent setup which clones the state of the main one, make any | |
| 201 // necessary changes, and then run it. | |
| 202 // | |
| 203 // The way to run both at the same time is: | |
| 204 // dependent_setup.RunPreMessageLoop(); | |
| 205 // main_setup.Run(); | |
| 206 // dependent_setup.RunPostMessageLoop(); | |
| 207 // so that the main setup executes the message loop, but both are run. | |
| 208 class DependentSetup : public CommonSetup { | |
| 209 public: | |
| 210 // Note: this could be one function that takes a CommonSetup*, but then | |
| 211 // the compiler can get confused what to call, since it also matches the | |
| 212 // default copy constructor. | |
| 213 explicit DependentSetup(Setup* derive_from); | |
| 214 explicit DependentSetup(DependentSetup* derive_from); | |
| 215 ~DependentSetup() override; | |
| 216 | |
| 217 // These are the two parts of Run() in the regular setup, not including the | |
| 218 // call to actually run the message loop. | |
| 219 void RunPreMessageLoop(); | |
| 220 bool RunPostMessageLoop(); | |
| 221 | |
| 222 Scheduler* GetScheduler() override; | |
| 223 | |
| 224 private: | |
| 225 Scheduler* scheduler_; | |
| 226 }; | |
| 227 | |
| 228 #endif // TOOLS_GN_SETUP_H_ | 180 #endif // TOOLS_GN_SETUP_H_ |
| OLD | NEW |