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 kSwitchFileName[] = "file-name"; | |
46 const char kSwitchExecScript[] = "exec-script"; | |
brettw
2016/07/06 22:19:26
Can we call this something like "json_ide_script"
matt.k
2016/07/08 00:39:07
Done.
| |
47 const char kSwitchExecScriptExtraArgs[] = "exec-script-extra-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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 if (command_line->HasSwitch(kSwitchRootTarget)) | 218 if (command_line->HasSwitch(kSwitchRootTarget)) |
214 root_target = command_line->GetSwitchValueASCII(kSwitchRootTarget); | 219 root_target = command_line->GetSwitchValueASCII(kSwitchRootTarget); |
215 bool res = QtCreatorWriter::RunAndWriteFile(build_settings, builder, err, | 220 bool res = QtCreatorWriter::RunAndWriteFile(build_settings, builder, err, |
216 root_target); | 221 root_target); |
217 if (res && !command_line->HasSwitch(switches::kQuiet)) { | 222 if (res && !command_line->HasSwitch(switches::kQuiet)) { |
218 OutputString("Generating QtCreator projects took " + | 223 OutputString("Generating QtCreator projects took " + |
219 base::Int64ToString(timer.Elapsed().InMilliseconds()) + | 224 base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
220 "ms\n"); | 225 "ms\n"); |
221 } | 226 } |
222 return res; | 227 return res; |
228 } else if (ide == kSwitchIdeValueJSON) { | |
229 std::string file_name = command_line->GetSwitchValueASCII(kSwitchFileName); | |
230 if (file_name.empty()) | |
231 file_name = "project.json"; | |
232 std::string exec_script = | |
233 command_line->GetSwitchValueASCII(kSwitchExecScript); | |
234 std::string exec_script_extra_args = | |
235 command_line->GetSwitchValueASCII(kSwitchExecScriptExtraArgs); | |
236 std::string filters = command_line->GetSwitchValueASCII(kSwitchFilters); | |
237 | |
238 bool quiet = command_line->HasSwitch(switches::kQuiet); | |
brettw
2016/07/06 22:19:26
This is duplicated from above (which already dupli
matt.k
2016/07/08 00:39:07
Done.
| |
239 bool res = JSONProjectWriter::RunAndWriteFiles( | |
240 build_settings, builder, file_name, exec_script, exec_script_extra_args, | |
241 filters, quiet, err); | |
242 if (res && !quiet) { | |
243 OutputString("Generating JSON projects took " + | |
244 base::Int64ToString(timer.Elapsed().InMilliseconds()) + | |
245 "ms\n"); | |
246 } | |
247 return res; | |
223 } | 248 } |
224 | 249 |
225 *err = Err(Location(), "Unknown IDE: " + ide); | 250 *err = Err(Location(), "Unknown IDE: " + ide); |
226 return false; | 251 return false; |
227 } | 252 } |
228 | 253 |
229 } // namespace | 254 } // namespace |
230 | 255 |
231 const char kGen[] = "gen"; | 256 const char kGen[] = "gen"; |
232 const char kGen_HelpShort[] = | 257 const char kGen_HelpShort[] = "gen: Generate ninja files."; |
233 "gen: Generate ninja files."; | |
234 const char kGen_Help[] = | 258 const char kGen_Help[] = |
235 "gn gen: Generate ninja files.\n" | 259 "gn gen: Generate ninja files.\n" |
236 "\n" | 260 "\n" |
237 " gn gen [<ide options>] <out_dir>\n" | 261 " gn gen [<ide options>] <out_dir>\n" |
238 "\n" | 262 "\n" |
239 " Generates ninja files from the current tree and puts them in the given\n" | 263 " Generates ninja files from the current tree and puts them in the given\n" |
240 " output directory.\n" | 264 " output directory.\n" |
241 "\n" | 265 "\n" |
242 " The output directory can be a source-repo-absolute path name such as:\n" | 266 " The output directory can be a source-repo-absolute path name such as:\n" |
243 " //out/foo\n" | 267 " //out/foo\n" |
244 " Or it can be a directory relative to the current directory such as:\n" | 268 " Or it can be a directory relative to the current directory such as:\n" |
245 " out/foo\n" | 269 " out/foo\n" |
246 "\n" | 270 "\n" |
247 " See \"gn help switches\" for the common command-line switches.\n" | 271 " See \"gn help switches\" for the common command-line switches.\n" |
248 "\n" | 272 "\n" |
249 "IDE options\n" | 273 "IDE options\n" |
250 "\n" | 274 "\n" |
251 " GN optionally generates files for IDE. Possibilities for <ide options>\n" | 275 " GN optionally generates files for IDE. Possibilities for <ide options>\n" |
252 "\n" | 276 "\n" |
253 " --ide=<ide_name>\n" | 277 " --ide=<ide_name>\n" |
254 " Generate files for an IDE. Currently supported values:\n" | 278 " Generate files for an IDE. Currently supported values:\n" |
255 " \"eclipse\" - Eclipse CDT settings file.\n" | 279 " \"eclipse\" - Eclipse CDT settings file.\n" |
256 " \"vs\" - Visual Studio project/solution files.\n" | 280 " \"vs\" - Visual Studio project/solution files.\n" |
257 " (default Visual Studio version: 2015)\n" | 281 " (default Visual Studio version: 2015)\n" |
258 " \"vs2013\" - Visual Studio 2013 project/solution files.\n" | 282 " \"vs2013\" - Visual Studio 2013 project/solution files.\n" |
259 " \"vs2015\" - Visual Studio 2015 project/solution files.\n" | 283 " \"vs2015\" - Visual Studio 2015 project/solution files.\n" |
260 " \"xcode\" - Xcode workspace/solution files.\n" | 284 " \"xcode\" - Xcode workspace/solution files.\n" |
261 " \"qtcreator\" - QtCreator project files.\n" | 285 " \"qtcreator\" - QtCreator project files.\n" |
286 " \"json\" - JSON file containing target information\n" | |
262 "\n" | 287 "\n" |
263 " --filters=<path_prefixes>\n" | 288 " --filters=<path_prefixes>\n" |
264 " Semicolon-separated list of label patterns used to limit the set\n" | 289 " Semicolon-separated list of label patterns used to limit the set\n" |
265 " of generated projects (see \"gn help label_pattern\"). Only\n" | 290 " of generated projects (see \"gn help label_pattern\"). Only\n" |
266 " matching targets and their dependencies will be included in the\n" | 291 " matching targets and their dependencies will be included in the\n" |
267 " solution. Only used for Visual Studio and Xcode.\n" | 292 " solution. Only used for Visual Studio, Xcode and JSON.\n" |
268 "\n" | 293 "\n" |
269 "Visual Studio Flags\n" | 294 "Visual Studio Flags\n" |
270 "\n" | 295 "\n" |
271 " --sln=<file_name>\n" | 296 " --sln=<file_name>\n" |
272 " Override default sln file name (\"all\"). Solution file is written\n" | 297 " Override default sln file name (\"all\"). Solution file is written\n" |
273 " to the root build directory.\n" | 298 " to the root build directory.\n" |
274 "\n" | 299 "\n" |
275 "Xcode Flags\n" | 300 "Xcode Flags\n" |
276 "\n" | 301 "\n" |
277 " --workspace=<file_name>\n" | 302 " --workspace=<file_name>\n" |
(...skipping 20 matching lines...) Expand all Loading... | |
298 "\n" | 323 "\n" |
299 "Eclipse IDE Support\n" | 324 "Eclipse IDE Support\n" |
300 "\n" | 325 "\n" |
301 " GN DOES NOT generate Eclipse CDT projects. Instead, it generates a\n" | 326 " 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" | 327 " 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" | 328 " 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" | 329 " not generate a full .cproject definition, it is not possible to\n" |
305 " properly define includes/defines for each file individually.\n" | 330 " properly define includes/defines for each file individually.\n" |
306 " Instead, one set of includes/defines is generated for the entire\n" | 331 " 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" | 332 " project. This works fairly well but may still result in a few indexer\n" |
308 " issues here and there.\n"; | 333 " issues here and there.\n" |
334 "\n" | |
335 "Generic JSON Output\n" | |
336 "\n" | |
337 " Dumps target information to JSON file and optionally invokes a python\n" | |
338 " script.\n" | |
339 "\n" | |
340 " --file_name=<json_file_name>\n" | |
341 " Overrides default file name of generated JSON file.\n" | |
brettw
2016/07/06 22:19:26
Can you list what the default file name is here?
matt.k
2016/07/08 00:39:07
Done.
| |
342 "\n" | |
343 " --exec-script=<path_to_python_script>\n" | |
344 " Executes python script after the JSON file is generated.\n" | |
345 " Path can be project absolute (//), system absolute (/) or\n" | |
346 " relative, in which case the output directory will be base.\n" | |
347 " Path to generated JSON file will be first argument when invoking\n" | |
348 " script.\n" | |
349 "\n" | |
350 " --exec-script-extra-args=<argument>\n" | |
351 " Optional second argument that will passed to executed-script.\n"; | |
309 | 352 |
310 int RunGen(const std::vector<std::string>& args) { | 353 int RunGen(const std::vector<std::string>& args) { |
311 base::ElapsedTimer timer; | 354 base::ElapsedTimer timer; |
312 | 355 |
313 if (args.size() != 1) { | 356 if (args.size() != 1) { |
314 Err(Location(), "Need exactly one build directory to generate.", | 357 Err(Location(), "Need exactly one build directory to generate.", |
315 "I expected something more like \"gn gen out/foo\"\n" | 358 "I expected something more like \"gn gen out/foo\"\n" |
316 "You can also see \"gn help gen\".").PrintToStdout(); | 359 "You can also see \"gn help gen\".").PrintToStdout(); |
317 return 1; | 360 return 1; |
318 } | 361 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 setup->scheduler().input_file_manager()->GetInputFileCount()) + | 417 setup->scheduler().input_file_manager()->GetInputFileCount()) + |
375 " files in " + | 418 " files in " + |
376 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; | 419 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; |
377 OutputString(stats); | 420 OutputString(stats); |
378 } | 421 } |
379 | 422 |
380 return 0; | 423 return 0; |
381 } | 424 } |
382 | 425 |
383 } // namespace commands | 426 } // namespace commands |
OLD | NEW |