Chromium Code Reviews| Index: tools/gn/command_gen.cc |
| diff --git a/tools/gn/command_gen.cc b/tools/gn/command_gen.cc |
| index 3d442745c393970e383074971a14c0f1e33db26d..1d439313a67f6d7c88f5604cddccbd66a7af91d6 100644 |
| --- a/tools/gn/command_gen.cc |
| +++ b/tools/gn/command_gen.cc |
| @@ -11,6 +11,7 @@ |
| #include "tools/gn/build_settings.h" |
| #include "tools/gn/commands.h" |
| #include "tools/gn/eclipse_writer.h" |
| +#include "tools/gn/json_project_writer.h" |
| #include "tools/gn/ninja_target_writer.h" |
| #include "tools/gn/ninja_writer.h" |
| #include "tools/gn/qt_creator_writer.h" |
| @@ -36,10 +37,14 @@ const char kSwitchIdeValueVs[] = "vs"; |
| const char kSwitchIdeValueVs2013[] = "vs2013"; |
| const char kSwitchIdeValueVs2015[] = "vs2015"; |
| const char kSwitchIdeValueXcode[] = "xcode"; |
| +const char kSwitchIdeValueJSON[] = "json"; |
| const char kSwitchNinjaExtraArgs[] = "ninja-extra-args"; |
| const char kSwitchRootTarget[] = "root-target"; |
| const char kSwitchSln[] = "sln"; |
| const char kSwitchWorkspace[] = "workspace"; |
| +const char kSwitchFileName[] = "file-name"; |
| +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.
|
| +const char kSwitchExecScriptExtraArgs[] = "exec-script-extra-args"; |
| // Called on worker thread to write the ninja file. |
| void BackgroundDoWrite(const Target* target) { |
| @@ -113,7 +118,7 @@ void PrintInvalidGeneratedInput(const Builder* builder, |
| if (generator) { |
| err += "but this file was not generated by any dependencies of the " + |
| - target_str + ". The target\nthat generates the file is:\n "; |
| + target_str + ". The target\nthat generates the file is:\n "; |
| err += generator->label().GetUserVisibleName(show_toolchains); |
| } else { |
| err += "but no targets in the build generate that file."; |
| @@ -220,6 +225,26 @@ bool RunIdeWriter(const std::string& ide, |
| "ms\n"); |
| } |
| return res; |
| + } else if (ide == kSwitchIdeValueJSON) { |
| + std::string file_name = command_line->GetSwitchValueASCII(kSwitchFileName); |
| + if (file_name.empty()) |
| + file_name = "project.json"; |
| + std::string exec_script = |
| + command_line->GetSwitchValueASCII(kSwitchExecScript); |
| + std::string exec_script_extra_args = |
| + command_line->GetSwitchValueASCII(kSwitchExecScriptExtraArgs); |
| + std::string filters = command_line->GetSwitchValueASCII(kSwitchFilters); |
| + |
| + 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.
|
| + bool res = JSONProjectWriter::RunAndWriteFiles( |
| + build_settings, builder, file_name, exec_script, exec_script_extra_args, |
| + filters, quiet, err); |
| + if (res && !quiet) { |
| + OutputString("Generating JSON projects took " + |
| + base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
| + "ms\n"); |
| + } |
| + return res; |
| } |
| *err = Err(Location(), "Unknown IDE: " + ide); |
| @@ -229,8 +254,7 @@ bool RunIdeWriter(const std::string& ide, |
| } // namespace |
| const char kGen[] = "gen"; |
| -const char kGen_HelpShort[] = |
| - "gen: Generate ninja files."; |
| +const char kGen_HelpShort[] = "gen: Generate ninja files."; |
| const char kGen_Help[] = |
| "gn gen: Generate ninja files.\n" |
| "\n" |
| @@ -259,12 +283,13 @@ const char kGen_Help[] = |
| " \"vs2015\" - Visual Studio 2015 project/solution files.\n" |
| " \"xcode\" - Xcode workspace/solution files.\n" |
| " \"qtcreator\" - QtCreator project files.\n" |
| + " \"json\" - JSON file containing target information\n" |
| "\n" |
| " --filters=<path_prefixes>\n" |
| " Semicolon-separated list of label patterns used to limit the set\n" |
| " of generated projects (see \"gn help label_pattern\"). Only\n" |
| " matching targets and their dependencies will be included in the\n" |
| - " solution. Only used for Visual Studio and Xcode.\n" |
| + " solution. Only used for Visual Studio, Xcode and JSON.\n" |
| "\n" |
| "Visual Studio Flags\n" |
| "\n" |
| @@ -305,7 +330,25 @@ const char kGen_Help[] = |
| " properly define includes/defines for each file individually.\n" |
| " Instead, one set of includes/defines is generated for the entire\n" |
| " project. This works fairly well but may still result in a few indexer\n" |
| - " issues here and there.\n"; |
| + " issues here and there.\n" |
| + "\n" |
| + "Generic JSON Output\n" |
| + "\n" |
| + " Dumps target information to JSON file and optionally invokes a python\n" |
| + " script.\n" |
| + "\n" |
| + " --file_name=<json_file_name>\n" |
| + " 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.
|
| + "\n" |
| + " --exec-script=<path_to_python_script>\n" |
| + " Executes python script after the JSON file is generated.\n" |
| + " Path can be project absolute (//), system absolute (/) or\n" |
| + " relative, in which case the output directory will be base.\n" |
| + " Path to generated JSON file will be first argument when invoking\n" |
| + " script.\n" |
| + "\n" |
| + " --exec-script-extra-args=<argument>\n" |
| + " Optional second argument that will passed to executed-script.\n"; |
| int RunGen(const std::vector<std::string>& args) { |
| base::ElapsedTimer timer; |