ios_eg2_test.gni 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # Copyright 2018 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("//build/config/ios/ios_test_runner_wrapper.gni")
  5. import("//build/config/ios/rules.gni")
  6. import("//ios/public/provider/chrome/browser/build_config.gni")
  7. template("ios_eg2_test_app_host") {
  8. ios_app_bundle(target_name) {
  9. testonly = true
  10. forward_variables_from(invoker, "*")
  11. configs += [ "//build/config/ios:xctest_config" ]
  12. if (!defined(bundle_deps)) {
  13. bundle_deps = []
  14. }
  15. bundle_deps += [ "//ios/third_party/earl_grey2:app_framework+bundle" ]
  16. if (!defined(include_provider_resources)) {
  17. include_provider_resources = true
  18. }
  19. if (include_provider_resources) {
  20. bundle_deps += ios_providers_resources_targets
  21. }
  22. if (!defined(deps)) {
  23. deps = []
  24. }
  25. deps += [ "//ios/third_party/earl_grey2:app_framework+link" ]
  26. # Xcode needs the following frameworks installed in the application (and
  27. # signed) for the XCTest to run, so install them using
  28. # extra_system_frameworks.
  29. extra_system_frameworks = [
  30. "$ios_sdk_platform_path/Developer/Library/Frameworks/XCTest.framework",
  31. "$ios_sdk_platform_path/Developer/Library/PrivateFrameworks/XCTAutomationSupport.framework",
  32. ]
  33. # Xcode 13 now depends on XCTestCore. To keep things future proof, copy over
  34. # everything that Xcode copies.
  35. if (xcode_version_int >= 1300) {
  36. extra_system_frameworks += [
  37. "$ios_sdk_platform_path/Developer/Library/PrivateFrameworks/XCTestCore.framework",
  38. "$ios_sdk_platform_path/Developer/Library/PrivateFrameworks/XCUIAutomation.framework",
  39. "$ios_sdk_platform_path/Developer/Library/PrivateFrameworks/XCUnit.framework",
  40. "$ios_sdk_platform_path/Developer/usr/lib/libXCTestSwiftSupport.dylib",
  41. ]
  42. }
  43. if (!defined(ldflags)) {
  44. ldflags = []
  45. }
  46. ldflags += [
  47. "-Wl,-rpath,@executable_path/Frameworks",
  48. "-Wl,-rpath,@loader_path/Frameworks",
  49. ]
  50. }
  51. }
  52. set_defaults("ios_eg2_test_app_host") {
  53. configs = default_executable_configs
  54. }
  55. # EarlGrey2 tests are just XCUITests that also depends on EarlGrey2.
  56. template("ios_eg2_test") {
  57. assert(defined(invoker.xcode_test_application_name),
  58. "xcode_test_application_name must be defined for $target_name")
  59. assert(
  60. defined(invoker.deps),
  61. "deps must be defined for $target_name to include at least one earl grey test file.")
  62. _target_name = target_name
  63. _test_target = "${target_name}_test"
  64. ios_xcuitest_test(_test_target) {
  65. forward_variables_from(invoker,
  66. [
  67. "xcode_test_application_name",
  68. "xctest_bundle_principal_class",
  69. "bundle_deps",
  70. "deps",
  71. "data_deps",
  72. ])
  73. if (!defined(deps)) {
  74. deps = []
  75. }
  76. deps += [ "//ios/third_party/earl_grey2:test_lib" ]
  77. # TODO(crbug.com/1056328) Because we change the target name, the subnodes
  78. # are going to append with the _test in the naming, which won't be backwards
  79. # compatible during migration from iOS recipe to Chromium.
  80. output_name = "${_target_name}"
  81. }
  82. ios_test_runner_wrapper(target_name) {
  83. forward_variables_from(invoker,
  84. [
  85. "data",
  86. "data_deps",
  87. "deps",
  88. "executable_args",
  89. "retries",
  90. "shards",
  91. "xcode_test_application_name",
  92. ])
  93. _root_build_dir = rebase_path("${root_build_dir}", root_build_dir)
  94. if (!defined(data_deps)) {
  95. data_deps = []
  96. }
  97. # Include the top ios_eg2_test target, and the host app
  98. data_deps += [ ":${_test_target}" ]
  99. if (!defined(executable_args)) {
  100. executable_args = []
  101. }
  102. # EG2 tests app are bundled as *-Runner.app, while the host app is bundled
  103. # as *.app.
  104. executable_args += [
  105. "--app",
  106. "@WrappedPath(${_root_build_dir}/${target_name}-Runner.app)",
  107. ]
  108. executable_args += [
  109. "--host-app",
  110. "@WrappedPath(${_root_build_dir}/${xcode_test_application_name}.app)",
  111. ]
  112. }
  113. }
  114. set_defaults("ios_eg2_test") {
  115. configs = default_shared_library_configs
  116. }