- add sources.
[platform/framework/web/crosswalk.git] / src / tools / gn / setup.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_SETUP_H_
6 #define TOOLS_GN_SETUP_H_
7
8 #include <vector>
9
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/scheduler.h"
15 #include "tools/gn/scope.h"
16 #include "tools/gn/settings.h"
17 #include "tools/gn/token.h"
18 #include "tools/gn/toolchain.h"
19
20 class CommandLine;
21 class InputFile;
22 class ParseNode;
23
24 extern const char kDotfile_Help[];
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
55 // Helper class to setup the build settings and environment for the various
56 // commands to run.
57 class Setup : public CommonSetup {
58  public:
59   Setup();
60   virtual ~Setup();
61
62   // Configures the build for the current command line. On success returns
63   // true. On failure, prints the error and returns false.
64   bool DoSetup();
65
66   // Runs the load, returning true on success. On failure, prints the error
67   // and returns false. This includes both RunPreMessageLoop() and
68   // RunPostMessageLoop().
69   bool Run();
70
71   Scheduler& scheduler() { return scheduler_; }
72
73  private:
74   // Fills build arguments. Returns true on success.
75   bool FillArguments(const CommandLine& cmdline);
76
77   // Fills the root directory into the settings. Returns true on success.
78   bool FillSourceDir(const CommandLine& cmdline);
79
80   // Fills the python path portion of the command line. On failure, sets
81   // it to just "python".
82   void FillPythonPath();
83
84   // Run config file.
85   bool RunConfigFile();
86
87   bool FillOtherConfig(const CommandLine& cmdline);
88
89   Scheduler scheduler_;
90
91   // These empty settings and toolchain are used to interpret the command line
92   // and dot file.
93   BuildSettings empty_build_settings_;
94   Settings empty_settings_;
95   Scope dotfile_scope_;
96
97   // State for invoking the dotfile.
98   base::FilePath dotfile_name_;
99   scoped_ptr<InputFile> dotfile_input_file_;
100   std::vector<Token> dotfile_tokens_;
101   scoped_ptr<ParseNode> dotfile_root_;
102
103   // State for invoking the command line args. We specifically want to keep
104   // this around for the entire run so that Values can blame to the command
105   // line when we issue errors about them.
106   scoped_ptr<InputFile> args_input_file_;
107   std::vector<Token> args_tokens_;
108   scoped_ptr<ParseNode> args_root_;
109
110   DISALLOW_COPY_AND_ASSIGN(Setup);
111 };
112
113 // A dependent setup allows one to do more than one build at a time. You would
114 // make a dependent setup which clones the state of the main one, make any
115 // necessary changes, and then run it.
116 //
117 // The way to run both at the same time is:
118 //   dependent_setup.RunPreMessageLoop();
119 //   main_setup.Run();
120 //   dependent_setup.RunPostMessageLoop();
121 // so that the main setup executes the message loop, but both are run.
122 class DependentSetup : public CommonSetup {
123  public:
124   DependentSetup(const Setup& main_setup);
125   virtual ~DependentSetup();
126
127   // These are the two parts of Run() in the regular setup, not including the
128   // call to actually run the message loop.
129   void RunPreMessageLoop();
130   bool RunPostMessageLoop();
131
132  private:
133   DISALLOW_COPY_AND_ASSIGN(DependentSetup);
134 };
135
136 #endif  // TOOLS_GN_SETUP_H_