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 "base/atomicops.h" | 5 #include "base/atomicops.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/timer/elapsed_timer.h" | 10 #include "base/timer/elapsed_timer.h" |
11 #include "tools/gn/build_settings.h" | 11 #include "tools/gn/build_settings.h" |
12 #include "tools/gn/commands.h" | 12 #include "tools/gn/commands.h" |
13 #include "tools/gn/eclipse_writer.h" | 13 #include "tools/gn/eclipse_writer.h" |
| 14 #include "tools/gn/json_project_writer.h" |
14 #include "tools/gn/ninja_target_writer.h" | 15 #include "tools/gn/ninja_target_writer.h" |
15 #include "tools/gn/ninja_writer.h" | 16 #include "tools/gn/ninja_writer.h" |
16 #include "tools/gn/qt_creator_writer.h" | 17 #include "tools/gn/qt_creator_writer.h" |
17 #include "tools/gn/runtime_deps.h" | 18 #include "tools/gn/runtime_deps.h" |
18 #include "tools/gn/scheduler.h" | 19 #include "tools/gn/scheduler.h" |
19 #include "tools/gn/setup.h" | 20 #include "tools/gn/setup.h" |
20 #include "tools/gn/standard_out.h" | 21 #include "tools/gn/standard_out.h" |
21 #include "tools/gn/switches.h" | 22 #include "tools/gn/switches.h" |
22 #include "tools/gn/target.h" | 23 #include "tools/gn/target.h" |
23 #include "tools/gn/visual_studio_writer.h" | 24 #include "tools/gn/visual_studio_writer.h" |
24 #include "tools/gn/xcode_writer.h" | 25 #include "tools/gn/xcode_writer.h" |
25 | 26 |
26 namespace commands { | 27 namespace commands { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const char kSwitchCheck[] = "check"; | 31 const char kSwitchCheck[] = "check"; |
31 const char kSwitchFilters[] = "filters"; | 32 const char kSwitchFilters[] = "filters"; |
32 const char kSwitchIde[] = "ide"; | 33 const char kSwitchIde[] = "ide"; |
33 const char kSwitchIdeValueEclipse[] = "eclipse"; | 34 const char kSwitchIdeValueEclipse[] = "eclipse"; |
34 const char kSwitchIdeValueQtCreator[] = "qtcreator"; | 35 const char kSwitchIdeValueQtCreator[] = "qtcreator"; |
35 const char kSwitchIdeValueVs[] = "vs"; | 36 const char kSwitchIdeValueVs[] = "vs"; |
36 const char kSwitchIdeValueVs2013[] = "vs2013"; | 37 const char kSwitchIdeValueVs2013[] = "vs2013"; |
37 const char kSwitchIdeValueVs2015[] = "vs2015"; | 38 const char kSwitchIdeValueVs2015[] = "vs2015"; |
38 const char kSwitchIdeValueXcode[] = "xcode"; | 39 const char kSwitchIdeValueXcode[] = "xcode"; |
| 40 const char kSwitchIdeValueJson[] = "json"; |
39 const char kSwitchNinjaExtraArgs[] = "ninja-extra-args"; | 41 const char kSwitchNinjaExtraArgs[] = "ninja-extra-args"; |
40 const char kSwitchRootTarget[] = "root-target"; | 42 const char kSwitchRootTarget[] = "root-target"; |
41 const char kSwitchSln[] = "sln"; | 43 const char kSwitchSln[] = "sln"; |
42 const char kSwitchWorkspace[] = "workspace"; | 44 const char kSwitchWorkspace[] = "workspace"; |
| 45 const char kSwitchJsonFileName[] = "json-file-name"; |
| 46 const char kSwitchJsonIdeScript[] = "json-ide-script"; |
| 47 const char kSwitchJsonIdeScriptArgs[] = "json-ide-script-args"; |
43 | 48 |
44 // Called on worker thread to write the ninja file. | 49 // Called on worker thread to write the ninja file. |
45 void BackgroundDoWrite(const Target* target) { | 50 void BackgroundDoWrite(const Target* target) { |
46 NinjaTargetWriter::RunAndWriteFile(target); | 51 NinjaTargetWriter::RunAndWriteFile(target); |
47 g_scheduler->DecrementWorkCount(); | 52 g_scheduler->DecrementWorkCount(); |
48 } | 53 } |
49 | 54 |
50 // Called on the main thread. | 55 // Called on the main thread. |
51 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, | 56 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, |
52 scoped_refptr<Builder> builder, | 57 scoped_refptr<Builder> builder, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 111 |
107 const std::string target_str = targets.size() > 1 ? "targets" : "target"; | 112 const std::string target_str = targets.size() > 1 ? "targets" : "target"; |
108 err += "The file:\n"; | 113 err += "The file:\n"; |
109 err += " " + file.value() + "\n"; | 114 err += " " + file.value() + "\n"; |
110 err += "is listed as an input or source for the " + target_str + ":\n"; | 115 err += "is listed as an input or source for the " + target_str + ":\n"; |
111 for (const Target* target : targets) | 116 for (const Target* target : targets) |
112 err += " " + target->label().GetUserVisibleName(show_toolchains) + "\n"; | 117 err += " " + target->label().GetUserVisibleName(show_toolchains) + "\n"; |
113 | 118 |
114 if (generator) { | 119 if (generator) { |
115 err += "but this file was not generated by any dependencies of the " + | 120 err += "but this file was not generated by any dependencies of the " + |
116 target_str + ". The target\nthat generates the file is:\n "; | 121 target_str + ". The target\nthat generates the file is:\n "; |
117 err += generator->label().GetUserVisibleName(show_toolchains); | 122 err += generator->label().GetUserVisibleName(show_toolchains); |
118 } else { | 123 } else { |
119 err += "but no targets in the build generate that file."; | 124 err += "but no targets in the build generate that file."; |
120 } | 125 } |
121 | 126 |
122 Err(Location(), "Input to " + target_str + " not generated by a dependency.", | 127 Err(Location(), "Input to " + target_str + " not generated by a dependency.", |
123 err).PrintToStdout(); | 128 err).PrintToStdout(); |
124 } | 129 } |
125 | 130 |
126 bool CheckForInvalidGeneratedInputs(Setup* setup) { | 131 bool CheckForInvalidGeneratedInputs(Setup* setup) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 164 } |
160 return false; | 165 return false; |
161 } | 166 } |
162 | 167 |
163 bool RunIdeWriter(const std::string& ide, | 168 bool RunIdeWriter(const std::string& ide, |
164 const BuildSettings* build_settings, | 169 const BuildSettings* build_settings, |
165 Builder* builder, | 170 Builder* builder, |
166 Err* err) { | 171 Err* err) { |
167 const base::CommandLine* command_line = | 172 const base::CommandLine* command_line = |
168 base::CommandLine::ForCurrentProcess(); | 173 base::CommandLine::ForCurrentProcess(); |
| 174 bool quiet = command_line->HasSwitch(switches::kQuiet); |
169 base::ElapsedTimer timer; | 175 base::ElapsedTimer timer; |
170 | 176 |
171 if (ide == kSwitchIdeValueEclipse) { | 177 if (ide == kSwitchIdeValueEclipse) { |
172 bool res = EclipseWriter::RunAndWriteFile(build_settings, builder, err); | 178 bool res = EclipseWriter::RunAndWriteFile(build_settings, builder, err); |
173 if (res && !command_line->HasSwitch(switches::kQuiet)) { | 179 if (res && !quiet) { |
174 OutputString("Generating Eclipse settings took " + | 180 OutputString("Generating Eclipse settings took " + |
175 base::Int64ToString(timer.Elapsed().InMilliseconds()) + | 181 base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
176 "ms\n"); | 182 "ms\n"); |
177 } | 183 } |
178 return res; | 184 return res; |
179 } else if (ide == kSwitchIdeValueVs || ide == kSwitchIdeValueVs2013 || | 185 } else if (ide == kSwitchIdeValueVs || ide == kSwitchIdeValueVs2013 || |
180 ide == kSwitchIdeValueVs2015) { | 186 ide == kSwitchIdeValueVs2015) { |
181 VisualStudioWriter::Version version = | 187 VisualStudioWriter::Version version = |
182 ide == kSwitchIdeValueVs2013 ? VisualStudioWriter::Version::Vs2013 | 188 ide == kSwitchIdeValueVs2013 ? VisualStudioWriter::Version::Vs2013 |
183 : VisualStudioWriter::Version::Vs2015; | 189 : VisualStudioWriter::Version::Vs2015; |
184 std::string sln_name; | 190 std::string sln_name; |
185 if (command_line->HasSwitch(kSwitchSln)) | 191 if (command_line->HasSwitch(kSwitchSln)) |
186 sln_name = command_line->GetSwitchValueASCII(kSwitchSln); | 192 sln_name = command_line->GetSwitchValueASCII(kSwitchSln); |
187 std::string filters; | 193 std::string filters; |
188 if (command_line->HasSwitch(kSwitchFilters)) | 194 if (command_line->HasSwitch(kSwitchFilters)) |
189 filters = command_line->GetSwitchValueASCII(kSwitchFilters); | 195 filters = command_line->GetSwitchValueASCII(kSwitchFilters); |
190 bool res = VisualStudioWriter::RunAndWriteFiles( | 196 bool res = VisualStudioWriter::RunAndWriteFiles( |
191 build_settings, builder, version, sln_name, filters, err); | 197 build_settings, builder, version, sln_name, filters, err); |
192 if (res && !command_line->HasSwitch(switches::kQuiet)) { | 198 if (res && !quiet) { |
193 OutputString("Generating Visual Studio projects took " + | 199 OutputString("Generating Visual Studio projects took " + |
194 base::Int64ToString(timer.Elapsed().InMilliseconds()) + | 200 base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
195 "ms\n"); | 201 "ms\n"); |
196 } | 202 } |
197 return res; | 203 return res; |
198 } else if (ide == kSwitchIdeValueXcode) { | 204 } else if (ide == kSwitchIdeValueXcode) { |
199 bool res = XcodeWriter::RunAndWriteFiles( | 205 bool res = XcodeWriter::RunAndWriteFiles( |
200 command_line->GetSwitchValueASCII(kSwitchWorkspace), | 206 command_line->GetSwitchValueASCII(kSwitchWorkspace), |
201 command_line->GetSwitchValueASCII(kSwitchRootTarget), | 207 command_line->GetSwitchValueASCII(kSwitchRootTarget), |
202 command_line->GetSwitchValueASCII(kSwitchNinjaExtraArgs), | 208 command_line->GetSwitchValueASCII(kSwitchNinjaExtraArgs), |
203 command_line->GetSwitchValueASCII(kSwitchFilters), build_settings, | 209 command_line->GetSwitchValueASCII(kSwitchFilters), build_settings, |
204 builder, err); | 210 builder, err); |
205 if (res && !command_line->HasSwitch(switches::kQuiet)) { | 211 if (res && !quiet) { |
206 OutputString("Generating Xcode projects took " + | 212 OutputString("Generating Xcode projects took " + |
207 base::Int64ToString(timer.Elapsed().InMilliseconds()) + | 213 base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
208 "ms\n"); | 214 "ms\n"); |
209 } | 215 } |
210 return res; | 216 return res; |
211 } else if (ide == kSwitchIdeValueQtCreator) { | 217 } else if (ide == kSwitchIdeValueQtCreator) { |
212 std::string root_target; | 218 std::string root_target; |
213 if (command_line->HasSwitch(kSwitchRootTarget)) | 219 if (command_line->HasSwitch(kSwitchRootTarget)) |
214 root_target = command_line->GetSwitchValueASCII(kSwitchRootTarget); | 220 root_target = command_line->GetSwitchValueASCII(kSwitchRootTarget); |
215 bool res = QtCreatorWriter::RunAndWriteFile(build_settings, builder, err, | 221 bool res = QtCreatorWriter::RunAndWriteFile(build_settings, builder, err, |
216 root_target); | 222 root_target); |
217 if (res && !command_line->HasSwitch(switches::kQuiet)) { | 223 if (res && !quiet) { |
218 OutputString("Generating QtCreator projects took " + | 224 OutputString("Generating QtCreator projects took " + |
219 base::Int64ToString(timer.Elapsed().InMilliseconds()) + | 225 base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
220 "ms\n"); | 226 "ms\n"); |
221 } | 227 } |
222 return res; | 228 return res; |
| 229 } else if (ide == kSwitchIdeValueJson) { |
| 230 std::string file_name = |
| 231 command_line->GetSwitchValueASCII(kSwitchJsonFileName); |
| 232 if (file_name.empty()) |
| 233 file_name = "project.json"; |
| 234 std::string exec_script = |
| 235 command_line->GetSwitchValueASCII(kSwitchJsonIdeScript); |
| 236 std::string exec_script_extra_args = |
| 237 command_line->GetSwitchValueASCII(kSwitchJsonIdeScriptArgs); |
| 238 std::string filters = command_line->GetSwitchValueASCII(kSwitchFilters); |
| 239 |
| 240 bool res = JSONProjectWriter::RunAndWriteFiles( |
| 241 build_settings, builder, file_name, exec_script, exec_script_extra_args, |
| 242 filters, quiet, err); |
| 243 if (res && !quiet) { |
| 244 OutputString("Generating JSON projects took " + |
| 245 base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
| 246 "ms\n"); |
| 247 } |
| 248 return res; |
223 } | 249 } |
224 | 250 |
225 *err = Err(Location(), "Unknown IDE: " + ide); | 251 *err = Err(Location(), "Unknown IDE: " + ide); |
226 return false; | 252 return false; |
227 } | 253 } |
228 | 254 |
229 } // namespace | 255 } // namespace |
230 | 256 |
231 const char kGen[] = "gen"; | 257 const char kGen[] = "gen"; |
232 const char kGen_HelpShort[] = | 258 const char kGen_HelpShort[] = "gen: Generate ninja files."; |
233 "gen: Generate ninja files."; | |
234 const char kGen_Help[] = | 259 const char kGen_Help[] = |
235 "gn gen: Generate ninja files.\n" | 260 "gn gen: Generate ninja files.\n" |
236 "\n" | 261 "\n" |
237 " gn gen [<ide options>] <out_dir>\n" | 262 " gn gen [<ide options>] <out_dir>\n" |
238 "\n" | 263 "\n" |
239 " Generates ninja files from the current tree and puts them in the given\n" | 264 " Generates ninja files from the current tree and puts them in the given\n" |
240 " output directory.\n" | 265 " output directory.\n" |
241 "\n" | 266 "\n" |
242 " The output directory can be a source-repo-absolute path name such as:\n" | 267 " The output directory can be a source-repo-absolute path name such as:\n" |
243 " //out/foo\n" | 268 " //out/foo\n" |
244 " Or it can be a directory relative to the current directory such as:\n" | 269 " Or it can be a directory relative to the current directory such as:\n" |
245 " out/foo\n" | 270 " out/foo\n" |
246 "\n" | 271 "\n" |
247 " See \"gn help switches\" for the common command-line switches.\n" | 272 " See \"gn help switches\" for the common command-line switches.\n" |
248 "\n" | 273 "\n" |
249 "IDE options\n" | 274 "IDE options\n" |
250 "\n" | 275 "\n" |
251 " GN optionally generates files for IDE. Possibilities for <ide options>\n" | 276 " GN optionally generates files for IDE. Possibilities for <ide options>\n" |
252 "\n" | 277 "\n" |
253 " --ide=<ide_name>\n" | 278 " --ide=<ide_name>\n" |
254 " Generate files for an IDE. Currently supported values:\n" | 279 " Generate files for an IDE. Currently supported values:\n" |
255 " \"eclipse\" - Eclipse CDT settings file.\n" | 280 " \"eclipse\" - Eclipse CDT settings file.\n" |
256 " \"vs\" - Visual Studio project/solution files.\n" | 281 " \"vs\" - Visual Studio project/solution files.\n" |
257 " (default Visual Studio version: 2015)\n" | 282 " (default Visual Studio version: 2015)\n" |
258 " \"vs2013\" - Visual Studio 2013 project/solution files.\n" | 283 " \"vs2013\" - Visual Studio 2013 project/solution files.\n" |
259 " \"vs2015\" - Visual Studio 2015 project/solution files.\n" | 284 " \"vs2015\" - Visual Studio 2015 project/solution files.\n" |
260 " \"xcode\" - Xcode workspace/solution files.\n" | 285 " \"xcode\" - Xcode workspace/solution files.\n" |
261 " \"qtcreator\" - QtCreator project files.\n" | 286 " \"qtcreator\" - QtCreator project files.\n" |
| 287 " \"json\" - JSON file containing target information\n" |
262 "\n" | 288 "\n" |
263 " --filters=<path_prefixes>\n" | 289 " --filters=<path_prefixes>\n" |
264 " Semicolon-separated list of label patterns used to limit the set\n" | 290 " Semicolon-separated list of label patterns used to limit the set\n" |
265 " of generated projects (see \"gn help label_pattern\"). Only\n" | 291 " of generated projects (see \"gn help label_pattern\"). Only\n" |
266 " matching targets and their dependencies will be included in the\n" | 292 " matching targets and their dependencies will be included in the\n" |
267 " solution. Only used for Visual Studio and Xcode.\n" | 293 " solution. Only used for Visual Studio, Xcode and JSON.\n" |
268 "\n" | 294 "\n" |
269 "Visual Studio Flags\n" | 295 "Visual Studio Flags\n" |
270 "\n" | 296 "\n" |
271 " --sln=<file_name>\n" | 297 " --sln=<file_name>\n" |
272 " Override default sln file name (\"all\"). Solution file is written\n" | 298 " Override default sln file name (\"all\"). Solution file is written\n" |
273 " to the root build directory.\n" | 299 " to the root build directory.\n" |
274 "\n" | 300 "\n" |
275 "Xcode Flags\n" | 301 "Xcode Flags\n" |
276 "\n" | 302 "\n" |
277 " --workspace=<file_name>\n" | 303 " --workspace=<file_name>\n" |
(...skipping 20 matching lines...) Expand all Loading... |
298 "\n" | 324 "\n" |
299 "Eclipse IDE Support\n" | 325 "Eclipse IDE Support\n" |
300 "\n" | 326 "\n" |
301 " GN DOES NOT generate Eclipse CDT projects. Instead, it generates a\n" | 327 " GN DOES NOT generate Eclipse CDT projects. Instead, it generates a\n" |
302 " settings file which can be imported into an Eclipse CDT project. The\n" | 328 " settings file which can be imported into an Eclipse CDT project. The\n" |
303 " XML file contains a list of include paths and defines. Because GN does\n" | 329 " XML file contains a list of include paths and defines. Because GN does\n" |
304 " not generate a full .cproject definition, it is not possible to\n" | 330 " not generate a full .cproject definition, it is not possible to\n" |
305 " properly define includes/defines for each file individually.\n" | 331 " properly define includes/defines for each file individually.\n" |
306 " Instead, one set of includes/defines is generated for the entire\n" | 332 " Instead, one set of includes/defines is generated for the entire\n" |
307 " project. This works fairly well but may still result in a few indexer\n" | 333 " project. This works fairly well but may still result in a few indexer\n" |
308 " issues here and there.\n"; | 334 " issues here and there.\n" |
| 335 "\n" |
| 336 "Generic JSON Output\n" |
| 337 "\n" |
| 338 " Dumps target information to JSON file and optionally invokes python\n" |
| 339 " script on generated file. \n" |
| 340 " See comments at the beginning of json_project_writer.cc and\n" |
| 341 " desc_builder.cc for overview of JSON file format.\n" |
| 342 "\n" |
| 343 " --json-file-name=<json_file_name>\n" |
| 344 " Overrides default file name (project.json) of generated JSON file.\n" |
| 345 "\n" |
| 346 " --json-ide-script=<path_to_python_script>\n" |
| 347 " Executes python script after the JSON file is generated.\n" |
| 348 " Path can be project absolute (//), system absolute (/) or\n" |
| 349 " relative, in which case the output directory will be base.\n" |
| 350 " Path to generated JSON file will be first argument when invoking\n" |
| 351 " script.\n" |
| 352 "\n" |
| 353 " --json-ide-script-args=<argument>\n" |
| 354 " Optional second argument that will passed to executed script.\n"; |
309 | 355 |
310 int RunGen(const std::vector<std::string>& args) { | 356 int RunGen(const std::vector<std::string>& args) { |
311 base::ElapsedTimer timer; | 357 base::ElapsedTimer timer; |
312 | 358 |
313 if (args.size() != 1) { | 359 if (args.size() != 1) { |
314 Err(Location(), "Need exactly one build directory to generate.", | 360 Err(Location(), "Need exactly one build directory to generate.", |
315 "I expected something more like \"gn gen out/foo\"\n" | 361 "I expected something more like \"gn gen out/foo\"\n" |
316 "You can also see \"gn help gen\".").PrintToStdout(); | 362 "You can also see \"gn help gen\".").PrintToStdout(); |
317 return 1; | 363 return 1; |
318 } | 364 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 setup->scheduler().input_file_manager()->GetInputFileCount()) + | 420 setup->scheduler().input_file_manager()->GetInputFileCount()) + |
375 " files in " + | 421 " files in " + |
376 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; | 422 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; |
377 OutputString(stats); | 423 OutputString(stats); |
378 } | 424 } |
379 | 425 |
380 return 0; | 426 return 0; |
381 } | 427 } |
382 | 428 |
383 } // namespace commands | 429 } // namespace commands |
OLD | NEW |