• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    # For now preserve passing shards during transition ifff clones not passed
94    # TODO(crbug.com/1500395) deprecate shards
95    if (defined(clones)) {
96      executable_args += [
97        "--clones",
98        "${clones}",
99      ]
100    } else {
101      if (defined(shards)) {
102        executable_args += [
103          "--shards",
104          "${shards}",
105        ]
106      }
107    }
108
109    if (xcode_version_int >= 1400) {
110      executable_args += [
111        "--readline-timeout",
112        "600",
113      ]
114    }
115
116    data_deps = [ "//testing:test_scripts_shared" ]
117    if (defined(invoker.data_deps)) {
118      data_deps += invoker.data_deps
119    }
120
121    # test runner relies on iossim for simulator builds.
122    if (target_environment == "simulator") {
123      _rebased_root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
124      data_deps += [ "//testing/iossim" ]
125
126      executable_args += [
127        "--iossim",
128        "@WrappedPath(${_rebased_root_build_dir}/iossim)",
129      ]
130    }
131
132    if (use_clang_coverage) {
133      executable_args += [ "--use-clang-coverage" ]
134    }
135
136    if (!is_debug) {
137      executable_args += [ "--release" ]
138    }
139
140    # wrapper script output name and path
141    if (!defined(wrapper_output_name)) {
142      _wrapper_output_name = "run_${target_name}"
143    } else {
144      _wrapper_output_name = wrapper_output_name
145    }
146
147    wrapper_script = "${root_build_dir}/bin/${_wrapper_output_name}"
148
149    data = []
150    if (defined(invoker.data)) {
151      data += invoker.data
152    }
153    data += [
154      "//ios/build/bots/scripts/",
155      "//ios/build/bots/scripts/plugin",
156
157      # gRPC interface for iOS test plugin
158      "//ios/testing/plugin",
159
160      # Variations test utilities used by variations_runner script.
161      "//testing/scripts/variations_seed_access_helper.py",
162      "//testing/test_env.py",
163    ]
164  }
165}
166