xref: /aosp_15_r20/external/cronet/build/config/ios/ios_test_runner_wrapper.gni (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2020 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/coverage/coverage.gni")
6import("//build/config/ios/ios_sdk.gni")
7import("//build/util/generate_wrapper.gni")
8
9# Invokes generate_wrapper to create an executable script wrapping iOS'
10# run.py with baked in arguments. Only takes effect when test entry in
11# gn_isolate_map.pyl is updated to type="generated_script" with script
12# set to the wrapper output path.
13#
14# Arguments:
15#
16# clones
17#   (optional) number of ios simulator clones to execute tests on
18#   in parallel
19#
20# data
21#   (optional, default [ "//ios/build/bots/scripts/" ]) list of files or
22#   directories required to run target
23#
24# data_deps
25#   (optional) list of target non-linked labels
26#
27# deps
28#   (optional) list of files or directories required to run target
29#
30# executable_args
31#   (optional) a list of string arguments to pass to run.py
32#
33# retries
34#   (optional, default 3) number of retry attempts
35#
36# shards
37#   (optional) number of ios simulator clones to execute tests in parallel. not
38#   the same as swarming shards. Only used if clones is not provided. Will be
39#   deprecated.
40#
41# wrapper_output_name
42#   (optional, default "run_${target_name}") name of the wrapper script
43#
44template("ios_test_runner_wrapper") {
45  generate_wrapper(target_name) {
46    forward_variables_from(invoker,
47                           [
48                             "deps",
49                             "retries",
50                             "shards",
51                             "wrapper_output_name",
52                           ])
53    testonly = true
54    executable = "//testing/test_env.py"
55
56    # iOS main test runner
57    _runner_path =
58        rebase_path("//ios/build/bots/scripts/run.py", root_build_dir)
59
60    executable_args = [ "@WrappedPath(${_runner_path})" ]
61
62    # arguments passed to run.py
63    if (defined(invoker.executable_args)) {
64      executable_args += invoker.executable_args
65    }
66
67    _rebased_mac_toolchain = rebase_path("//mac_toolchain", root_build_dir)
68    _rebased_xcode_path = rebase_path("//Xcode.app", root_build_dir)
69    _rebased_ios_runtime_cache_prefix =
70        rebase_path("//Runtime-ios-", root_build_dir)
71
72    # --out-dir argument is specified in gn_isolate_map.pyl because
73    # ${ISOLATED_OUTDIR} doesn't get resolved through this wrapper.
74    executable_args += [
75      "--xcode-path",
76      "@WrappedPath(${_rebased_xcode_path})",
77      "--mac-toolchain-cmd",
78      "@WrappedPath(${_rebased_mac_toolchain})",
79      "--runtime-cache-prefix",
80      "@WrappedPath(${_rebased_ios_runtime_cache_prefix})",
81    ]
82
83    # Default retries to 3
84    if (!defined(retries)) {
85      retries = 3
86    }
87    executable_args += [
88      "--retries",
89      "${retries}",
90    ]
91
92    # Clones is not required by test runner so only pass if defined.
93    if (defined(clones)) {
94      executable_args += [
95        "--clones",
96        "${clones}",
97      ]
98    }
99
100    if (xcode_version_int >= 1400) {
101      executable_args += [
102        "--readline-timeout",
103        "600",
104      ]
105    }
106
107    data_deps = [ "//testing:test_scripts_shared" ]
108    if (defined(invoker.data_deps)) {
109      data_deps += invoker.data_deps
110    }
111
112    # test runner relies on iossim for simulator builds.
113    if (target_environment == "simulator") {
114      _rebased_root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
115      data_deps += [ "//testing/iossim" ]
116
117      executable_args += [
118        "--iossim",
119        "@WrappedPath(${_rebased_root_build_dir}/iossim)",
120      ]
121    }
122
123    if (use_clang_coverage) {
124      executable_args += [ "--use-clang-coverage" ]
125    }
126
127    if (!is_debug) {
128      executable_args += [ "--release" ]
129    }
130
131    # wrapper script output name and path
132    if (!defined(wrapper_output_name)) {
133      _wrapper_output_name = "run_${target_name}"
134    } else {
135      _wrapper_output_name = wrapper_output_name
136    }
137
138    wrapper_script = "${root_build_dir}/bin/${_wrapper_output_name}"
139
140    data = []
141    if (defined(invoker.data)) {
142      data += invoker.data
143    }
144    data += [
145      "//ios/build/bots/scripts/",
146      "//ios/build/bots/scripts/plugin",
147
148      # gRPC interface for iOS test plugin
149      "//ios/testing/plugin",
150
151      # Variations test utilities used by variations_runner script.
152      "//testing/scripts/variations_seed_access_helper.py",
153      "//testing/test_env.py",
154    ]
155  }
156}
157