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 #include <map> | 5 #include <map> |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "tools/gn/commands.h" | 9 #include "tools/gn/commands.h" |
10 #include "tools/gn/input_file.h" | 10 #include "tools/gn/input_file.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 } // namespace | 100 } // namespace |
101 | 101 |
102 extern const char kArgs[] = "args"; | 102 extern const char kArgs[] = "args"; |
103 extern const char kArgs_HelpShort[] = | 103 extern const char kArgs_HelpShort[] = |
104 "args: Display configurable arguments declared by the build."; | 104 "args: Display configurable arguments declared by the build."; |
105 extern const char kArgs_Help[] = | 105 extern const char kArgs_Help[] = |
106 "gn args [arg name]\n" | 106 "gn args [arg name]\n" |
107 " Displays all arguments declared by buildfiles along with their\n" | 107 " Displays all arguments declared by buildfiles along with their\n" |
108 " description. Build arguments are anything in a declare_args() block\n" | 108 " description. Build arguments are anything in a declare_args() block\n" |
109 " in any buildfile. The comment preceeding the declaration will be\n" | 109 " in any buildfile. The comment preceding the declaration will be\n" |
110 " displayed here (so comment well!).\n" | 110 " displayed here (so comment well!).\n" |
111 "\n" | 111 "\n" |
112 " These arguments can be overriden on the command-line:\n" | 112 " These arguments can be overridden on the command-line:\n" |
113 " --args=\"doom_melon_setting=5 component_build=1\"\n" | 113 " --args=\"doom_melon_setting=5 component_build=1\"\n" |
114 " or in a toolchain definition (see \"gn help buildargs\" for more on\n" | 114 " or in a toolchain definition (see \"gn help buildargs\" for more on\n" |
115 " how this all works).\n" | 115 " how this all works).\n" |
116 "\n" | 116 "\n" |
117 " If \"arg name\" is specified, only the information for that argument\n" | 117 " If \"arg name\" is specified, only the information for that argument\n" |
118 " will be displayed. Otherwise all arguments will be displayed.\n"; | 118 " will be displayed. Otherwise all arguments will be displayed.\n"; |
119 | 119 |
120 int RunArgs(const std::vector<std::string>& args) { | 120 int RunArgs(const std::vector<std::string>& args) { |
121 Setup* setup = new Setup; | 121 Setup* setup = new Setup; |
122 setup->set_check_for_bad_items(false); | 122 setup->set_check_for_bad_items(false); |
123 if (!setup->DoSetup() || !setup->Run()) | 123 if (!setup->DoSetup() || !setup->Run()) |
124 return 1; | 124 return 1; |
125 | 125 |
126 const Scope::KeyValueMap& build_args = | 126 const Scope::KeyValueMap& build_args = |
127 setup->build_settings().build_args().declared_arguments(); | 127 setup->build_settings().build_args().declared_arguments(); |
128 | 128 |
129 if (args.size() == 1) { | 129 if (args.size() == 1) { |
130 // Get help on a specific command. | 130 // Get help on a specific command. |
131 Scope::KeyValueMap::const_iterator found_arg = build_args.find(args[0]); | 131 Scope::KeyValueMap::const_iterator found_arg = build_args.find(args[0]); |
132 if (found_arg == build_args.end()) { | 132 if (found_arg == build_args.end()) { |
133 Err(Location(), "Unknown build arg.", | 133 Err(Location(), "Unknown build argument.", |
134 "You asked for \"" + args[0] + "\" which I didn't find in any " | 134 "You asked for \"" + args[0] + "\" which I didn't find in any " |
135 "buildfile\nassociated with this build."); | 135 "buildfile\nassociated with this build."); |
136 return 1; | 136 return 1; |
137 } | 137 } |
138 PrintArgHelp(args[0], found_arg->second); | 138 PrintArgHelp(args[0], found_arg->second); |
139 return 0; | 139 return 0; |
140 } else if (args.size() > 1) { | 140 } else if (args.size() > 1) { |
141 // Too many arguments. | 141 // Too many arguments. |
142 Err(Location(), "You're holding it wrong.", | 142 Err(Location(), "You're holding it wrong.", |
143 "Usage: \"gn args [arg name]\"").PrintToStdout(); | 143 "Usage: \"gn args [arg name]\"").PrintToStdout(); |
144 return 1; | 144 return 1; |
145 } | 145 } |
146 | 146 |
147 // List all arguments. First put them in a regular map so they're sorted. | 147 // List all arguments. First put them in a regular map so they're sorted. |
148 std::map<base::StringPiece, Value> sorted_args; | 148 std::map<base::StringPiece, Value> sorted_args; |
149 for (Scope::KeyValueMap::const_iterator i = build_args.begin(); | 149 for (Scope::KeyValueMap::const_iterator i = build_args.begin(); |
150 i != build_args.end(); ++i) | 150 i != build_args.end(); ++i) |
151 sorted_args.insert(*i); | 151 sorted_args.insert(*i); |
152 | 152 |
153 for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin(); | 153 for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin(); |
154 i != sorted_args.end(); ++i) { | 154 i != sorted_args.end(); ++i) { |
155 PrintArgHelp(i->first, i->second); | 155 PrintArgHelp(i->first, i->second); |
156 OutputString("\n"); | 156 OutputString("\n"); |
157 } | 157 } |
158 | 158 |
159 return 0; | 159 return 0; |
160 } | 160 } |
161 | 161 |
162 } // namespace commands | 162 } // namespace commands |
OLD | NEW |