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