Let source_target_relative be a valid substitution for bundle_data.

This helps address the situation where one needs to package a bundle not
produced by the build's create_bundle rule, like a third-party
framework, inside another bundle that is produced by the build. If a
bundle_data rule only pointed to the outer directory of that third-party
framework, any changes to the inner components of the bundle would not
trigger a re-copy.

The {{source_target_relative}} is useful because it lets one define a
bundle_data target at the same level as the third-party bundle, list
its entire contents in |sources|, and have the bundle's folder
structure preserved.

With the existing set of valid substitution patterns, a bundle_data
rule would need to be created for each level of folder structure in
the third-party bundle.

Bug: chromium:955936, chromium:608382
Change-Id: I6e32a98ea607fb95d73ec707c7c8e9a39ee1e9d0
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/4860
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Petr Hosek <phosek@google.com>
diff --git a/docs/reference.md b/docs/reference.md
index fe23b19..1d2ea49 100644
--- a/docs/reference.md
+++ b/docs/reference.md
@@ -778,12 +778,15 @@
 #### **Compilation Database**
 
 ```
-  --export-compile-commands
+  --export-compile-commands[=<target_name1,target_name2...>]
       Produces a compile_commands.json file in the root of the build directory
       containing an array of “command objects”, where each command object
-      specifies one way a translation unit is compiled in the project. This is
-      used for various Clang-based tooling, allowing for the replay of individual
-      compilations independent of the build system.
+      specifies one way a translation unit is compiled in the project. If a list
+      of target_name is supplied, only targets that are reachable from the list
+      of target_name will be used for “command objects” generation, otherwise
+      all available targets will be used. This is used for various Clang-based
+      tooling, allowing for the replay of individual compilations independent
+      of the build system.
 ```
 ### <a name="cmd_help"></a>**gn help &lt;anything&gt;**
 
@@ -6807,8 +6810,9 @@
   {{source_target_relative}}
       The path to the source file relative to the target's directory. This will
       generally be used for replicating the source directory layout in the
-      output directory. This can only be used in actions and it is an error to
-      use in process_file_template where there is no "target".
+      output directory. This can only be used in actions and bundle_data
+      targets. It is an error to use in process_file_template where there is no
+      "target".
         "//foo/bar/baz.txt" => "baz.txt"
 ```
 
diff --git a/tools/gn/substitution_type.cc b/tools/gn/substitution_type.cc
index f38013e..ae680c9 100644
--- a/tools/gn/substitution_type.cc
+++ b/tools/gn/substitution_type.cc
@@ -128,7 +128,9 @@
 }
 
 bool IsValidBundleDataSubstitution(const Substitution* type) {
-  return type == &SubstitutionLiteral || type == &SubstitutionSourceNamePart ||
+  return type == &SubstitutionLiteral ||
+         type == &SubstitutionSourceTargetRelative ||
+         type == &SubstitutionSourceNamePart ||
          type == &SubstitutionSourceFilePart ||
          type == &SubstitutionSourceRootRelativeDir ||
          type == &SubstitutionBundleRootDir ||
diff --git a/tools/gn/substitution_writer.cc b/tools/gn/substitution_writer.cc
index c8bc70f..b26579b 100644
--- a/tools/gn/substitution_writer.cc
+++ b/tools/gn/substitution_writer.cc
@@ -102,8 +102,9 @@
   {{source_target_relative}}
       The path to the source file relative to the target's directory. This will
       generally be used for replicating the source directory layout in the
-      output directory. This can only be used in actions and it is an error to
-      use in process_file_template where there is no "target".
+      output directory. This can only be used in actions and bundle_data
+      targets. It is an error to use in process_file_template where there is no
+      "target".
         "//foo/bar/baz.txt" => "baz.txt"
 
 (*) Note on directories