bazelbuild / rules_apple

Bazel rules to build apps for Apple platforms.
Apache License 2.0
512 stars 269 forks source link

Only insert libXCTestBundleInject.dylib for unit tests #2530

Closed andre-alves closed 2 months ago

andre-alves commented 2 months ago

Fixes #2528.

Stop adding libXCTestBundleInject.dylib for UI tests. Xcode only injects this dylib when running unit tests with host app.

This diff was tested with Xcode 15.2 and Xcode 16 RC1.

bazel test //test:ios_xctestrun_runner_ui_test
bazel test //test:ios_xctestrun_runner_unit_test
andre-alves commented 2 months ago

@luispadron could you help me check macos_test_runner with Xcode 16? My setup is iOS-only.

libXCTestBundleInject.dylib might still need to be inserted for macOS, as it's still required for iOS, but only for unit tests.

Should this only happen for Xcode 16+?

This change is only necessary for Xcode 16, but it should also work fine in Xcode 15 because the .xctestrun generated by Xcode 15 does not include libXCTestBundleInject.dylib as well, but it doesn't crash if we insert it.

andre-alves commented 2 months ago

The //test:ios_coverage_test failure in CI seems unrelated to these changes, and I'm not able to reproduce it locally.

bazel test //test:ios_coverage_test is passing here (Xcode 15.4, Xcode 16 RC1).

Also, checking the logs:

test_standalone_unit_test_coverage_json FAILED: Unable to find coverage.json in test-testlogs/app/standalone_test/test.outputs/outputs.zip .
/private/var/tmp/_bazel_buildkite/1b8f5aa2a34c7759c42ecb8e12f480e3/sandbox/darwin-sandbox/6389/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/test/ios_coverage_test.runfiles/_main/test/apple_shell_testutils.sh:550: in call to unzip_single_file
/private/var/tmp/_bazel_buildkite/1b8f5aa2a34c7759c42ecb8e12f480e3/sandbox/darwin-sandbox/6389/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/test/ios_coverage_test.runfiles/_main/test/ios_coverage_test.sh:262: in call to test_standalone_unit_test_coverage_json

This test test_standalone_unit_test_coverage_json is not using ios_xctestrun_runner:

ios_unit_test(
    name = "standalone_test",
    deps = [":standalone_test_lib"],
    minimum_os_version = "${MIN_OS_IOS}",
)

function test_standalone_unit_test_coverage_json() {
  create_common_files
  do_coverage ios --test_output=errors --ios_minimum_os=9.0 --experimental_use_llvm_covmap --test_env=COVERAGE_PRODUCE_JSON=1 //app:standalone_test || fail "Should build"
  unzip_single_file "test-testlogs/app/standalone_test/test.outputs/outputs.zip" coverage.json \
      grep -q '"name":"SharedLogic.m:-\[SharedLogic doSomething\]"'
}

Any tips on how to handle this failure?

jpsim commented 2 months ago

This should get the tests passing again on last-green https://github.com/bazelbuild/rules_apple/pull/2531