Index: tools/gn/command_gen.cc |
diff --git a/tools/gn/command_gen.cc b/tools/gn/command_gen.cc |
index 3d442745c393970e383074971a14c0f1e33db26d..06b99ca1124d6a63fb92907b190fbe3874dca054 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 kSwitchJsonFileName[] = "json-file-name"; |
+const char kSwitchJsonIdeScript[] = "json-ide-script"; |
+const char kSwitchJsonIdeScriptArgs[] = "json-ide-script-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."; |
@@ -166,11 +171,12 @@ bool RunIdeWriter(const std::string& ide, |
Err* err) { |
const base::CommandLine* command_line = |
base::CommandLine::ForCurrentProcess(); |
+ bool quiet = command_line->HasSwitch(switches::kQuiet); |
base::ElapsedTimer timer; |
if (ide == kSwitchIdeValueEclipse) { |
bool res = EclipseWriter::RunAndWriteFile(build_settings, builder, err); |
- if (res && !command_line->HasSwitch(switches::kQuiet)) { |
+ if (res && !quiet) { |
OutputString("Generating Eclipse settings took " + |
base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
"ms\n"); |
@@ -189,7 +195,7 @@ bool RunIdeWriter(const std::string& ide, |
filters = command_line->GetSwitchValueASCII(kSwitchFilters); |
bool res = VisualStudioWriter::RunAndWriteFiles( |
build_settings, builder, version, sln_name, filters, err); |
- if (res && !command_line->HasSwitch(switches::kQuiet)) { |
+ if (res && !quiet) { |
OutputString("Generating Visual Studio projects took " + |
base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
"ms\n"); |
@@ -202,7 +208,7 @@ bool RunIdeWriter(const std::string& ide, |
command_line->GetSwitchValueASCII(kSwitchNinjaExtraArgs), |
command_line->GetSwitchValueASCII(kSwitchFilters), build_settings, |
builder, err); |
- if (res && !command_line->HasSwitch(switches::kQuiet)) { |
+ if (res && !quiet) { |
OutputString("Generating Xcode projects took " + |
base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
"ms\n"); |
@@ -214,12 +220,32 @@ bool RunIdeWriter(const std::string& ide, |
root_target = command_line->GetSwitchValueASCII(kSwitchRootTarget); |
bool res = QtCreatorWriter::RunAndWriteFile(build_settings, builder, err, |
root_target); |
- if (res && !command_line->HasSwitch(switches::kQuiet)) { |
+ if (res && !quiet) { |
OutputString("Generating QtCreator projects took " + |
base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
"ms\n"); |
} |
return res; |
+ } else if (ide == kSwitchIdeValueJson) { |
+ std::string file_name = |
+ command_line->GetSwitchValueASCII(kSwitchJsonFileName); |
+ if (file_name.empty()) |
+ file_name = "project.json"; |
+ std::string exec_script = |
+ command_line->GetSwitchValueASCII(kSwitchJsonIdeScript); |
+ std::string exec_script_extra_args = |
+ command_line->GetSwitchValueASCII(kSwitchJsonIdeScriptArgs); |
+ std::string filters = command_line->GetSwitchValueASCII(kSwitchFilters); |
+ |
+ 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 +255,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 +284,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 +331,27 @@ 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 python\n" |
+ " script on generated file. \n" |
+ " See comments at the beginning of json_project_writer.cc and\n" |
+ " desc_builder.cc for overview of JSON file format.\n" |
+ "\n" |
+ " --json-file-name=<json_file_name>\n" |
+ " Overrides default file name (project.json) of generated JSON file.\n" |
+ "\n" |
+ " --json-ide-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" |
+ " --json-ide-script-args=<argument>\n" |
+ " Optional second argument that will passed to executed script.\n"; |
int RunGen(const std::vector<std::string>& args) { |
base::ElapsedTimer timer; |