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" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "tools/gn/build_settings.h" | 13 #include "tools/gn/build_settings.h" |
14 #include "tools/gn/scheduler.h" | 14 #include "tools/gn/scheduler.h" |
15 #include "tools/gn/scope.h" | 15 #include "tools/gn/scope.h" |
16 #include "tools/gn/settings.h" | 16 #include "tools/gn/settings.h" |
17 #include "tools/gn/token.h" | 17 #include "tools/gn/token.h" |
18 #include "tools/gn/toolchain.h" | 18 #include "tools/gn/toolchain.h" |
19 | 19 |
20 class CommandLine; | 20 class CommandLine; |
21 class InputFile; | 21 class InputFile; |
22 class ParseNode; | 22 class ParseNode; |
23 | 23 |
24 extern const char kDotfile_Help[]; | 24 extern const char kDotfile_Help[]; |
25 | 25 |
| 26 // Base class for code shared between Setup and DependentSetup. |
| 27 class CommonSetup { |
| 28 public: |
| 29 virtual ~CommonSetup(); |
| 30 |
| 31 // When true (the default), Run() will check for unresolved dependencies and |
| 32 // cycles upon completion. When false, such errors will be ignored. |
| 33 void set_check_for_bad_items(bool s) { check_for_bad_items_ = s; } |
| 34 |
| 35 BuildSettings& build_settings() { return build_settings_; } |
| 36 |
| 37 protected: |
| 38 CommonSetup(); |
| 39 CommonSetup(const CommonSetup& other); |
| 40 |
| 41 // Performs the two sets of operations to run the generation before and after |
| 42 // the message loop is run. |
| 43 void RunPreMessageLoop(); |
| 44 bool RunPostMessageLoop(); |
| 45 |
| 46 protected: |
| 47 BuildSettings build_settings_; |
| 48 |
| 49 bool check_for_bad_items_; |
| 50 |
| 51 private: |
| 52 CommonSetup& operator=(const CommonSetup& other); // Disallow. |
| 53 }; |
| 54 |
26 // Helper class to setup the build settings and environment for the various | 55 // Helper class to setup the build settings and environment for the various |
27 // commands to run. | 56 // commands to run. |
28 class Setup { | 57 class Setup : public CommonSetup { |
29 public: | 58 public: |
30 Setup(); | 59 Setup(); |
31 ~Setup(); | 60 virtual ~Setup(); |
32 | 61 |
33 // Configures the build for the current command line. On success returns | 62 // Configures the build for the current command line. On success returns |
34 // true. On failure, prints the error and returns false. | 63 // true. On failure, prints the error and returns false. |
35 bool DoSetup(); | 64 bool DoSetup(); |
36 | 65 |
37 // When true (the default), Run() will check for unresolved dependencies and | |
38 // cycles upon completion. When false, such errors will be ignored. | |
39 void set_check_for_bad_items(bool s) { check_for_bad_items_ = s; } | |
40 | |
41 // Runs the load, returning true on success. On failure, prints the error | 66 // Runs the load, returning true on success. On failure, prints the error |
42 // and returns false. | 67 // and returns false. This includes both RunPreMessageLoop() and |
| 68 // RunPostMessageLoop(). |
43 bool Run(); | 69 bool Run(); |
44 | 70 |
45 BuildSettings& build_settings() { return build_settings_; } | |
46 Scheduler& scheduler() { return scheduler_; } | 71 Scheduler& scheduler() { return scheduler_; } |
47 | 72 |
48 private: | 73 private: |
49 // Fills build arguments. Returns true on success. | 74 // Fills build arguments. Returns true on success. |
50 bool FillArguments(const CommandLine& cmdline); | 75 bool FillArguments(const CommandLine& cmdline); |
51 | 76 |
52 // Fills the root directory into the settings. Returns true on success. | 77 // Fills the root directory into the settings. Returns true on success. |
53 bool FillSourceDir(const CommandLine& cmdline); | 78 bool FillSourceDir(const CommandLine& cmdline); |
54 | 79 |
55 // Fills the python path portion of the command line. On failure, sets | 80 // Fills the python path portion of the command line. On failure, sets |
56 // it to just "python". | 81 // it to just "python". |
57 void FillPythonPath(); | 82 void FillPythonPath(); |
58 | 83 |
59 // Run config file. | 84 // Run config file. |
60 bool RunConfigFile(); | 85 bool RunConfigFile(); |
61 | 86 |
62 bool FillOtherConfig(const CommandLine& cmdline); | 87 bool FillOtherConfig(const CommandLine& cmdline); |
63 | 88 |
64 BuildSettings build_settings_; | |
65 Scheduler scheduler_; | 89 Scheduler scheduler_; |
66 | 90 |
67 bool check_for_bad_items_; | |
68 | |
69 // These empty settings and toolchain are used to interpret the command line | 91 // These empty settings and toolchain are used to interpret the command line |
70 // and dot file. | 92 // and dot file. |
71 BuildSettings empty_build_settings_; | 93 BuildSettings empty_build_settings_; |
72 Toolchain empty_toolchain_; | 94 Toolchain empty_toolchain_; |
73 Settings empty_settings_; | 95 Settings empty_settings_; |
74 Scope dotfile_scope_; | 96 Scope dotfile_scope_; |
75 | 97 |
76 // State for invoking the dotfile. | 98 // State for invoking the dotfile. |
77 base::FilePath dotfile_name_; | 99 base::FilePath dotfile_name_; |
78 scoped_ptr<InputFile> dotfile_input_file_; | 100 scoped_ptr<InputFile> dotfile_input_file_; |
79 std::vector<Token> dotfile_tokens_; | 101 std::vector<Token> dotfile_tokens_; |
80 scoped_ptr<ParseNode> dotfile_root_; | 102 scoped_ptr<ParseNode> dotfile_root_; |
81 | 103 |
82 // State for invoking the command line args. We specifically want to keep | 104 // State for invoking the command line args. We specifically want to keep |
83 // this around for the entire run so that Values can blame to the command | 105 // this around for the entire run so that Values can blame to the command |
84 // line when we issue errors about them. | 106 // line when we issue errors about them. |
85 scoped_ptr<InputFile> args_input_file_; | 107 scoped_ptr<InputFile> args_input_file_; |
86 std::vector<Token> args_tokens_; | 108 std::vector<Token> args_tokens_; |
87 scoped_ptr<ParseNode> args_root_; | 109 scoped_ptr<ParseNode> args_root_; |
88 | 110 |
89 DISALLOW_COPY_AND_ASSIGN(Setup); | 111 DISALLOW_COPY_AND_ASSIGN(Setup); |
90 }; | 112 }; |
91 | 113 |
| 114 // A dependent setup allows one to do more than one build at a time. You would |
| 115 // make a dependent setup which clones the state of the main one, make any |
| 116 // necessary changes, and then run it. |
| 117 // |
| 118 // The way to run both at the same time is: |
| 119 // dependent_setup.RunPreMessageLoop(); |
| 120 // main_setup.Run(); |
| 121 // dependent_setup.RunPostMessageLoop(); |
| 122 // so that the main setup executes the message loop, but both are run. |
| 123 class DependentSetup : public CommonSetup { |
| 124 public: |
| 125 DependentSetup(const Setup& main_setup); |
| 126 virtual ~DependentSetup(); |
| 127 |
| 128 // These are the two parts of Run() in the regular setup, not including the |
| 129 // call to actually run the message loop. |
| 130 void RunPreMessageLoop(); |
| 131 bool RunPostMessageLoop(); |
| 132 |
| 133 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(DependentSetup); |
| 135 }; |
| 136 |
92 #endif // TOOLS_GN_SETUP_H_ | 137 #endif // TOOLS_GN_SETUP_H_ |
OLD | NEW |