Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / tools / gn / command_help.cc
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 #include <algorithm>
6 #include <iostream>
7
8 #include "tools/gn/args.h"
9 #include "tools/gn/commands.h"
10 #include "tools/gn/err.h"
11 #include "tools/gn/functions.h"
12 #include "tools/gn/input_conversion.h"
13 #include "tools/gn/label_pattern.h"
14 #include "tools/gn/setup.h"
15 #include "tools/gn/standard_out.h"
16 #include "tools/gn/substitution_writer.h"
17 #include "tools/gn/variables.h"
18
19 namespace commands {
20
21 namespace {
22
23 void PrintToplevelHelp() {
24   OutputString("Commands (type \"gn help <command>\" for more details):\n");
25   for (const auto& cmd : commands::GetCommands())
26     PrintShortHelp(cmd.second.help_short);
27
28   OutputString(
29       "\n"
30       "Common switches:\n");
31   PrintShortHelp(
32       "--args: Specifies build arguments overrides. "
33       "See \"gn help buildargs\".");
34   PrintShortHelp(
35       "--[no]color: Forces colored output on or off (rather than autodetect).");
36   PrintShortHelp(
37       "--dotfile: Specifies an alternate .gn file. See \"gn help dotfile\".");
38   PrintShortHelp(
39       "--no-exec: Skips exec_script calls (for performance testing).");
40   PrintShortHelp(
41       "-q: Quiet mode, don't print anything on success.");
42   PrintShortHelp(
43       "--root: Specifies source root (overrides .gn file).");
44   PrintShortHelp(
45       "--time: Outputs a summary of how long everything took.");
46   PrintShortHelp(
47       "--tracelog: Writes a Chrome-compatible trace log to the given file.");
48   PrintShortHelp(
49       "-v: Verbose mode, print lots of logging.");
50   PrintShortHelp(
51       "--version: Print the GN binary's version and exit.");
52
53   // Target declarations.
54   OutputString("\nTarget declarations (type \"gn help <function>\" for more "
55                "details):\n");
56   for (const auto& func : functions::GetFunctions()) {
57     if (func.second.is_target)
58       PrintShortHelp(func.second.help_short);
59   }
60
61   // Functions.
62   OutputString("\nBuildfile functions (type \"gn help <function>\" for more "
63                "details):\n");
64   for (const auto& func : functions::GetFunctions()) {
65     if (!func.second.is_target)
66       PrintShortHelp(func.second.help_short);
67   }
68
69   // Built-in variables.
70   OutputString("\nBuilt-in predefined variables (type \"gn help <variable>\" "
71                "for more details):\n");
72   for (const auto& builtin : variables::GetBuiltinVariables())
73     PrintShortHelp(builtin.second.help_short);
74
75   // Target variables.
76   OutputString("\nVariables you set in targets (type \"gn help <variable>\" "
77                "for more details):\n");
78   for (const auto& target : variables::GetTargetVariables())
79     PrintShortHelp(target.second.help_short);
80
81   OutputString("\nOther help topics:\n");
82   PrintShortHelp("buildargs: How build arguments work.");
83   PrintShortHelp("dotfile: Info about the toplevel .gn file.");
84   PrintShortHelp("label_pattern: Matching more than one label.");
85   PrintShortHelp(
86       "input_conversion: Processing input from exec_script and read_file.");
87   PrintShortHelp("source_expansion: Map sources to outputs for scripts.");
88 }
89
90 }  // namespace
91
92 const char kHelp[] = "help";
93 const char kHelp_HelpShort[] =
94     "help: Does what you think.";
95 const char kHelp_Help[] =
96     "gn help <anything>\n"
97     "  Yo dawg, I heard you like help on your help so I put help on the help\n"
98     "  in the help.\n";
99
100 int RunHelp(const std::vector<std::string>& args) {
101   if (args.size() == 0) {
102     PrintToplevelHelp();
103     return 0;
104   }
105
106   // Check commands.
107   const commands::CommandInfoMap& command_map = commands::GetCommands();
108   commands::CommandInfoMap::const_iterator found_command =
109       command_map.find(args[0]);
110   if (found_command != command_map.end()) {
111     PrintLongHelp(found_command->second.help);
112     return 0;
113   }
114
115   // Check functions.
116   const functions::FunctionInfoMap& function_map = functions::GetFunctions();
117   functions::FunctionInfoMap::const_iterator found_function =
118       function_map.find(args[0]);
119   if (found_function != function_map.end()) {
120     PrintLongHelp(found_function->second.help);
121     return 0;
122   }
123
124   // Builtin variables.
125   const variables::VariableInfoMap& builtin_vars =
126       variables::GetBuiltinVariables();
127   variables::VariableInfoMap::const_iterator found_builtin_var =
128       builtin_vars.find(args[0]);
129   if (found_builtin_var != builtin_vars.end()) {
130     PrintLongHelp(found_builtin_var->second.help);
131     return 0;
132   }
133
134   // Target variables.
135   const variables::VariableInfoMap& target_vars =
136       variables::GetTargetVariables();
137   variables::VariableInfoMap::const_iterator found_target_var =
138       target_vars.find(args[0]);
139   if (found_target_var != target_vars.end()) {
140     PrintLongHelp(found_target_var->second.help);
141     return 0;
142   }
143
144   // Random other topics.
145   if (args[0] == "buildargs") {
146     PrintLongHelp(kBuildArgs_Help);
147     return 0;
148   }
149   if (args[0] == "dotfile") {
150     PrintLongHelp(kDotfile_Help);
151     return 0;
152   }
153   if (args[0] == "input_conversion") {
154     PrintLongHelp(kInputConversion_Help);
155     return 0;
156   }
157   if (args[0] == "label_pattern") {
158     PrintLongHelp(kLabelPattern_Help);
159     return 0;
160   }
161   if (args[0] == "source_expansion") {
162     PrintLongHelp(kSourceExpansion_Help);
163     return 0;
164   }
165
166   // No help on this.
167   Err(Location(), "No help on \"" + args[0] + "\".").PrintToStdout();
168   RunHelp(std::vector<std::string>());
169   return 1;
170 }
171
172 }  // namespace commands