Skip to content

Add apple.test_bundle_tree_artifacts feature to output test bundles as tree artifacts - #3146

Open
tinder-cwybranowski wants to merge 1 commit into
bazelbuild:mainfrom
tinder-cwybranowski:test-bundle-tree-artifacts
Open

tinder-cwybranowski wants to merge 1 commit into
bazelbuild:mainfrom
tinder-cwybranowski:test-bundle-tree-artifacts

Conversation

@tinder-cwybranowski

Copy link
Copy Markdown

Summary

Adds an opt-in apple.test_bundle_tree_artifacts feature. With it enabled, *_unit_test and *_ui_test targets output their .xctest bundle as a tree artifact instead of a .zip, as if use_tree_artifacts_outputs were set for the test bundle only.

  • Test hosts, apps, extensions and frameworks are unaffected and keep the output type set by use_tree_artifacts_outputs (an .ipa or .zip by default).
  • It can be set on the command line (--features=apple.test_bundle_tree_artifacts) or per target (features = ["apple.test_bundle_tree_artifacts"]). With use_tree_artifacts_outputs already set, it changes nothing.
  • It's implemented in the shared test bundle implementation (apple_test_bundle_support.bzl), so it applies to every platform's test rules. A small helper overrides use_tree_artifacts_outputs in the build settings used for the test bundle's platform_prerequisites, so the existing tree artifact code path is reused as is.
  • No runner changes are needed: the iOS, macOS and xctestrun runners already copy a .xctest directory and unzip anything else, and they handle the test bundle and the test host independently.
  • Without the feature, nothing changes.

Motivation

Test bundles are never shipped or distributed, so their archive exists only to be unzipped again by the test runner. Zipping a large test bundle takes time on every change. With remote execution or a remote cache, the archive is also uploaded and downloaded as a single large blob, which can't be deduplicated against the files of the bundle that are already in the cache.

use_tree_artifacts_outputs avoids that, but it's global: it also turns applications into tree artifacts, so no .ipa is produced. Builds that still need archives for distribution can't use it, and there's currently no way to get tree artifacts for test bundles only.

Alternatives considered

  • A build setting instead of a feature: a feature can be enabled per target and doesn't add a configuration-changing flag, and it matches existing opt-ins like apple.skip_codesign_simulator_bundles. Happy to switch to a build setting if that's preferred.
  • Other names: apple.tree_artifact_test_bundles would follow the apple.tree_artifact_dsym_files define. apple.test_bundle_tree_artifacts seemed closer to the existing use_tree_artifacts_outputs setting.

Testing

  • New apple_test_info_test analysis test rule, with three cases in ios_unit_test_tests.bzl on a unit test with a test host:
    • By default, the test bundle passed to the runner is unit_test.zip and the test host is app.ipa, neither a tree artifact.
    • With --features=apple.test_bundle_tree_artifacts, the test bundle is a unit_test.xctest tree artifact and the test host is still app.ipa.
    • With use_tree_artifacts_outputs, both are tree artifacts, as before.
  • New ios_unit_test_test_bundle_tree_artifacts_contents_test builds the test bundle with the feature and checks its contents.
  • New test_ios_unit_test_with_host_and_test_bundle_tree_artifacts_pass in test/ios_xctestrun_runner_unit_test.sh runs a hosted unit test with the feature through the xctestrun runner, and checks that the test bundle is a directory and the test host an .ipa.
  • I ran the ios_unit_test, ios_ui_test, macos_unit_test and tvos_unit_test Starlark test suites locally, and they pass, including the new tests. With the change to apple_test_bundle_support.bzl reverted, the new feature test fails as expected.
  • One local caveat, the same as in Add background_action to ios_xctestrun_runner #3113: the iPhone Xs used by ios_xctestrun_runner_unit_test.sh can't be created with my local simulator runtimes, so I swapped the device type in a local copy. With that, hosted unit tests (including the existing test_ios_unit_test_with_host_pass) fail on my machine before the tests start (The test runner crashed before establishing connection), with or without this change, so I couldn't run the new hosted test locally. An unhosted unit test with the feature enabled does pass through the xctestrun runner with a tree artifact .xctest.
  • buildifier --lint=warn passes on the changed .bzl and BUILD files.

With the feature enabled, test bundles are output as a tree artifact
.xctest instead of a .zip, as if use_tree_artifacts_outputs were set for
the test bundle only. Test hosts, applications, extensions and frameworks
keep the output type set by the build setting.

Test bundles aren't distributed, so their archive is only unzipped again
by the test runner. Skipping it saves the zip and unzip, and lets a
remote cache store and transfer the bundle's files individually instead
of as one large blob. The global build setting can't be used for this
when applications still need an .ipa.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant