Android: Simplify gtest GN logic

Each test was creating:
* a non-incremental wrapper script,
* an incremental wrapper script,
* another non-incremental wrapper script.

This third target is actually just needed to depend on the other two, so
refactored to make this more clear. It also makes it easier to address
changing incremental install a GN arg (linked bug).

Bug: 1013688
Change-Id: I530e95a3277aa9a5164e7ad9a02f0f1ec830e556
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1856841
Commit-Queue: Andrew Grieve <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Cr-Commit-Position: refs/heads/master@{#707243}
diff --git a/testing/test.gni b/testing/test.gni
index 0eb9ecd0..8882424 100644
--- a/testing/test.gni
+++ b/testing/test.gni
@@ -183,13 +183,13 @@
 
       # Incremental test targets work only for .apks.
       test_runner_script(_incremental_test_runner_target) {
-        forward_variables_from(invoker,
-                               _wrapper_script_vars + [
-                                     "data",
-                                     "data_deps",
-                                     "deps",
-                                     "public_deps",
-                                   ])
+        forward_variables_from(invoker, _wrapper_script_vars)
+
+        # Dep needed for the test runner .runtime_deps file to pick up data
+        # deps from the forward_variables_from(invoker, "*") on the library.
+        data_deps = [
+          ":$_library_target",
+        ]
         apk_target = ":$_apk_target"
         test_name = _incremental_test_name
         test_type = "gtest"
@@ -209,18 +209,18 @@
 
     if (!_incremental_apk_only) {
       test_runner_script(_test_runner_target) {
-        forward_variables_from(invoker,
-                               _wrapper_script_vars + [
-                                     "data",
-                                     "data_deps",
-                                     "deps",
-                                     "public_deps",
-                                   ])
+        forward_variables_from(invoker, _wrapper_script_vars)
 
         if (_use_raw_android_executable) {
           executable_dist_dir = "$root_out_dir/$_dist_target"
         } else {
           apk_target = ":$_apk_target"
+
+          # Dep needed for the test runner .runtime_deps file to pick up data
+          # deps from the forward_variables_from(invoker, "*") on the library.
+          data_deps = [
+            ":$_library_target",
+          ]
         }
         test_name = _output_name
         test_type = "gtest"
@@ -228,35 +228,28 @@
       }
     }
 
-    test_runner_script(target_name) {
-      forward_variables_from(invoker,
-                             _wrapper_script_vars + [
-                                   "data",
-                                   "data_deps",
-                                   "deps",
-                                   "public_deps",
-                                 ])
-
+    # Create a wrapper script rather than using a group() in order to ensure
+    # "ninja $target_name" always works. If this was a group(), then GN would
+    # not create a top-level alias for it if a target exists in another
+    # directory with the same $target_name.
+    # Also - bots run this script directly for "components_perftests".
+    generate_wrapper(target_name) {
+      testonly = true
+      executable = "$root_build_dir/bin/run_$_output_name"
+      wrapper_script = "$root_build_dir/$_output_name"
+      deps = [
+        ":$_test_runner_target",
+      ]
       if (_use_raw_android_executable) {
-        executable_dist_dir = "$root_out_dir/$_dist_target"
-        deps += [
-          ":$_dist_target",
-          ":$_test_runner_target",
-        ]
+        deps += [ ":$_dist_target" ]
       } else {
-        apk_target = ":$_apk_target"
-        deps += [ ":$_apk_target" ]
-        if (_incremental_apk_only) {
-          deps += [ ":${target_name}_incremental" ]
-        } else {
-          deps += [ ":$_test_runner_target" ]
-        }
+        # Dep needed for the swarming .isolate file to pick up data
+        # deps from the forward_variables_from(invoker, "*") on the library.
+        deps += [
+          ":$_apk_target",
+          ":$_library_target",
+        ]
       }
-      generated_script = "$root_build_dir/$_output_name"
-      incremental_install = _incremental_apk_only
-      test_name = _output_name
-      test_suite = _output_name
-      test_type = "gtest"
     }
   } else if (is_fuchsia) {
     _output_name = invoker.target_name