Add option to not generate VS projects for targets deps

BUG=589099

Review-Url: https://codereview.chromium.org/2200123002
Cr-Original-Commit-Position: refs/heads/master@{#409489}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 64edbcf758a9c60fbd1679460e1fd69db29998f7
diff --git a/tools/gn/command_gen.cc b/tools/gn/command_gen.cc
index 60735f8..fa5b75a 100644
--- a/tools/gn/command_gen.cc
+++ b/tools/gn/command_gen.cc
@@ -39,6 +39,7 @@
 const char kSwitchIdeValueXcode[] = "xcode";
 const char kSwitchIdeValueJson[] = "json";
 const char kSwitchNinjaExtraArgs[] = "ninja-extra-args";
+const char kSwitchNoDeps[] = "no-deps";
 const char kSwitchRootTarget[] = "root-target";
 const char kSwitchSln[] = "sln";
 const char kSwitchWorkspace[] = "workspace";
@@ -205,8 +206,9 @@
     std::string filters;
     if (command_line->HasSwitch(kSwitchFilters))
       filters = command_line->GetSwitchValueASCII(kSwitchFilters);
+    bool no_deps = command_line->HasSwitch(kSwitchNoDeps);
     bool res = VisualStudioWriter::RunAndWriteFiles(
-        build_settings, builder, version, sln_name, filters, err);
+        build_settings, builder, version, sln_name, filters, no_deps, err);
     if (res && !quiet) {
       OutputString("Generating Visual Studio projects took " +
                    base::Int64ToString(timer.Elapsed().InMilliseconds()) +
@@ -310,6 +312,11 @@
     "      Override default sln file name (\"all\"). Solution file is written\n"
     "      to the root build directory.\n"
     "\n"
+    "  --no-deps\n"
+    "      Don't include targets dependencies to the solution. Changes the\n"
+    "      way how --filters option works. Only directly matching targets are\n"
+    "      included.\n"
+    "\n"
     "Xcode Flags\n"
     "\n"
     "  --workspace=<file_name>\n"
@@ -348,7 +355,7 @@
     "Generic JSON Output\n"
     "\n"
     "  Dumps target information to JSON file and optionally invokes python\n"
-    "  script on generated file. \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"
diff --git a/tools/gn/docs/reference.md b/tools/gn/docs/reference.md
index acf0ac1..d25782f 100644
--- a/tools/gn/docs/reference.md
+++ b/tools/gn/docs/reference.md
@@ -446,7 +446,7 @@
 
 
 ```
-## **gn desc <out_dir> <label or pattern> [<what to show>] [\--blame]**
+## **gn desc <out_dir> <label or pattern> [<what to show>] [\--blame] [\--format=json]**
 
 ```
   Displays information about a given target or config. The build
@@ -512,6 +512,9 @@
       this flag, only the default toolchain one will be matched by
       wildcards. With this flag, both will be matched.
 
+  --format=json
+      Format the output as JSON instead of text.
+
 ```
 
 ### **Target flags**
@@ -702,12 +705,13 @@
       "vs2015" - Visual Studio 2015 project/solution files.
       "xcode" - Xcode workspace/solution files.
       "qtcreator" - QtCreator project files.
+      "json" - JSON file containing target information
 
   --filters=<path_prefixes>
       Semicolon-separated list of label patterns used to limit the set
       of generated projects (see "gn help label_pattern"). Only
       matching targets and their dependencies will be included in the
-      solution. Only used for Visual Studio and Xcode.
+      solution. Only used for Visual Studio, Xcode and JSON.
 
 ```
 
@@ -718,6 +722,11 @@
       Override default sln file name ("all"). Solution file is written
       to the root build directory.
 
+  --no-deps
+      Don't include targets dependencies to the solution. Changes the
+      way how --filters option works. Only directly matching targets are
+      included.
+
 ```
 
 ### **Xcode Flags**
@@ -762,6 +771,29 @@
   project. This works fairly well but may still result in a few indexer
   issues here and there.
 
+```
+
+### **Generic JSON Output**
+
+```
+  Dumps target information to JSON file and optionally invokes python
+  script on generated file.
+  See comments at the beginning of json_project_writer.cc and
+  desc_builder.cc for overview of JSON file format.
+
+  --json-file-name=<json_file_name>
+      Overrides default file name (project.json) of generated JSON file.
+
+  --json-ide-script=<path_to_python_script>
+      Executes python script after the JSON file is generated.
+      Path can be project absolute (//), system absolute (/) or
+      relative, in which case the output directory will be base.
+      Path to generated JSON file will be first argument when invoking
+      script.
+
+  --json-ide-script-args=<argument>
+      Optional second argument that will passed to executed script.
+
 
 ```
 ## **gn help <anything>**
@@ -3031,9 +3063,7 @@
 
         If you specify more than one output for shared library links,
         you should consider setting link_output, depend_output, and
-        runtime_link_output. Otherwise, the first entry in the
-        outputs list should always be the main output which will be
-        linked to.
+        runtime_outputs.
 
         Example for a compiler tool that produces .obj files:
           outputs = [
@@ -3058,16 +3088,14 @@
 
     link_output  [string with substitutions]
     depend_output  [string with substitutions]
-    runtime_link_output  [string with substitutions]
         Valid for: "solink" only (optional)
 
-        These three files specify which of the outputs from the solink
+        These two files specify which of the outputs from the solink
         tool should be used for linking and dependency tracking. These
         should match entries in the "outputs". If unspecified, the
         first item in the "outputs" array will be used for all. See
         "Separate linking and dependencies for shared libraries"
-        below for more. If link_output is set but runtime_link_output
-        is not set, runtime_link_output defaults to link_output.
+        below for more.
 
         On Windows, where the tools produce a .dll shared library and
         a .lib import library, you will want the first two to be the
@@ -3144,6 +3172,14 @@
             rspfile_content = "{{inputs}} {{solibs}} {{libs}}"
           }
 
+    runtime_outputs  [string list with substitutions]
+        Valid for: linker tools
+
+        If specified, this list is the subset of the outputs that should
+        be added to runtime deps (see "gn help runtime_deps"). By
+        default (if runtime_outputs is empty or unspecified), it will be
+        the link_output.
+
 ```
 
 ### **Expansions for tool variables**
@@ -6157,11 +6193,9 @@
 ### **Multiple outputs**
 
 ```
-  When a tool produces more than one output, only the first output
-  is considered. For example, a shared library target may produce a
-  .dll and a .lib file on Windows. Only the .dll file will be considered
-  a runtime dependency. This applies only to linker tools. Scripts and
-  copy steps with multiple outputs will get all outputs listed.
+  Linker tools can specify which of their outputs should be considered
+  when computing the runtime deps by setting runtime_outputs. If this
+  is unset on the tool, the default will be the first output only.
 
 
 ```
diff --git a/tools/gn/visual_studio_writer.cc b/tools/gn/visual_studio_writer.cc
index 870d96c..0c9972d 100644
--- a/tools/gn/visual_studio_writer.cc
+++ b/tools/gn/visual_studio_writer.cc
@@ -167,22 +167,26 @@
 
 bool FilterTargets(const BuildSettings* build_settings,
                    const Builder& builder,
-                   const std::string& dir_filters,
+                   const std::string& filters,
+                   bool no_deps,
                    std::vector<const Target*>* targets,
                    Err* err) {
-  if (dir_filters.empty()) {
+  if (filters.empty()) {
     *targets = builder.GetAllResolvedTargets();
     return true;
   }
 
-  std::vector<LabelPattern> filters;
-  if (!commands::FilterPatternsFromString(build_settings, dir_filters, &filters,
+  std::vector<LabelPattern> patterns;
+  if (!commands::FilterPatternsFromString(build_settings, filters, &patterns,
                                           err))
     return false;
 
-  commands::FilterTargetsByPatterns(builder.GetAllResolvedTargets(), filters,
+  commands::FilterTargetsByPatterns(builder.GetAllResolvedTargets(), patterns,
                                     targets);
 
+  if (no_deps)
+    return true;
+
   std::set<Label> labels;
   std::queue<const Target*> to_process;
   for (const Target* target : *targets) {
@@ -272,10 +276,11 @@
                                           const Builder& builder,
                                           Version version,
                                           const std::string& sln_name,
-                                          const std::string& dir_filters,
+                                          const std::string& filters,
+                                          bool no_deps,
                                           Err* err) {
   std::vector<const Target*> targets;
-  if (!FilterTargets(build_settings, builder, dir_filters, &targets, err))
+  if (!FilterTargets(build_settings, builder, filters, no_deps, &targets, err))
     return false;
 
   const char* config_platform = "Win32";
diff --git a/tools/gn/visual_studio_writer.h b/tools/gn/visual_studio_writer.h
index 0a8fcb4..639be09 100644
--- a/tools/gn/visual_studio_writer.h
+++ b/tools/gn/visual_studio_writer.h
@@ -32,15 +32,17 @@
   };
 
   // Writes Visual Studio project and solution files. |sln_name| is the optional
-  // solution file name ("all" is used if not specified). |dir_filters| is
-  // optional semicolon-separated list of label patterns used to limit the set
-  // of generated projects. Only matching targets will be included to the
-  // solution. On failure will populate |err| and will return false.
+  // solution file name ("all" is used if not specified). |filters| is optional
+  // semicolon-separated list of label patterns used to limit the set of
+  // generated projects. Only matching targets and their dependencies (unless
+  // |no_deps| is true) will be included to the solution. On failure will
+  // populate |err| and will return false.
   static bool RunAndWriteFiles(const BuildSettings* build_settings,
                                const Builder& builder,
                                Version version,
                                const std::string& sln_name,
-                               const std::string& dir_filters,
+                               const std::string& filters,
+                               bool no_deps,
                                Err* err);
 
  private: