Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: tools/gn/command_gen.cc

Issue 2064533002: [GN] Add JSON project writer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [GN] fix include order Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/gn/command_gen.cc
diff --git a/tools/gn/command_gen.cc b/tools/gn/command_gen.cc
index 3d442745c393970e383074971a14c0f1e33db26d..185ba72fff6bfa6afa997fac26a86f0eae1fe864 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";
+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,25 @@ 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);
+
+ bool quiet = command_line->HasSwitch(switches::kQuiet);
+ bool res = JSONProjectWriter::RunAndWriteFiles(
+ build_settings, builder, file_name, exec_script, exec_script_extra_args,
+ 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 +253,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,6 +282,7 @@ 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"
@@ -305,7 +329,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"
+ "\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;
« tools/gn/command_desc.cc ('K') | « tools/gn/command_desc.cc ('k') | tools/gn/commands.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698