From da4a29eb4b88da6359cf5944ba1f89794ba7a0b1 Mon Sep 17 00:00:00 2001 From: Gabriel Giosia Date: Fri, 26 Jul 2019 13:02:17 -0700 Subject: [PATCH] Add additional_contents to macos_unit_tests and macos_ui_test RELNOTES: macos_unit_tests and macos_ui_test now accept a `additional_contents` attribute which can copy files into specific subdirectories of the Contents folder. PiperOrigin-RevId: 260198078 --- .../testing/apple_test_bundle_support.bzl | 15 +++++++- doc/rules-macos.md | 34 ++++++++++++++++- test/macos_ui_test_test.sh | 37 +++++++++++++++++++ test/macos_unit_test_test.sh | 28 ++++++++++++++ 4 files changed, 111 insertions(+), 3 deletions(-) diff --git a/apple/internal/testing/apple_test_bundle_support.bzl b/apple/internal/testing/apple_test_bundle_support.bzl index 6f833bd3a1..b1749ce774 100644 --- a/apple/internal/testing/apple_test_bundle_support.bzl +++ b/apple/internal/testing/apple_test_bundle_support.bzl @@ -30,6 +30,10 @@ load( "@build_bazel_rules_apple//apple/internal:partials.bzl", "partials", ) +load( + "@build_bazel_rules_apple//apple/internal:platform_support.bzl", + "platform_support", +) load( "@build_bazel_rules_apple//apple/internal:processor.bzl", "processor", @@ -76,7 +80,11 @@ def _apple_test_bundle_impl(ctx, extra_providers = []): binary_artifact = binary_descriptor.artifact debug_outputs_provider = binary_descriptor.debug_outputs_provider - debug_dependencies = [] + if hasattr(ctx.attr, "additional_contents"): + debug_dependencies = ctx.attr.additional_contents.keys() + else: + debug_dependencies = [] + if hasattr(ctx.attr, "frameworks"): targets_to_avoid = list(ctx.attr.frameworks) else: @@ -115,6 +123,11 @@ def _apple_test_bundle_impl(ctx, extra_providers = []): ), ] + if platform_support.platform_type(ctx) == apple_common.platform_type.macos: + processor_partials.append( + partials.macos_additional_contents_partial(), + ) + processor_result = processor.process(ctx, processor_partials) # TODO(kaipi): Remove this filtering when apple_*_test is merged with the bundle and binary diff --git a/doc/rules-macos.md b/doc/rules-macos.md index dc30d16216..cb28021ed8 100644 --- a/doc/rules-macos.md +++ b/doc/rules-macos.md @@ -1074,7 +1074,7 @@ Builds and bundles a macOS Spotlight Importer. ## macos_unit_test ```python -macos_unit_test(name, bundle_id, infoplists, minimum_os_version, runner, +macos_unit_test(name, additional_contents, bundle_id, infoplists, minimum_os_version, runner, test_host, data, deps) ``` @@ -1111,6 +1111,21 @@ of the attributes inherited by all test rules, please check the

A unique name for the target.

+ + additional_contents + +

Dictionary of labels to strings; optional

+

Files that should be copied into specific subdirectories of the + Contents folder in the xctest. The keys of this + dictionary are labels pointing to single files, + filegroups, or targets; the corresponding value is the + name of the subdirectory of Contents where they should + be placed.

+

The relative directory structure of filegroup + contents is preserved when they are copied into the desired + Contents subdirectory.

+ + bundle_id @@ -1197,7 +1212,7 @@ of the attributes inherited by all test rules, please check the ## macos_ui_test ```python -macos_ui_test(name, bundle_id, infoplists, minimum_os_version, runner, +macos_ui_test(name, additional_contents, bundle_id, infoplists, minimum_os_version, runner, test_host, data, deps, [test specific attributes]) ``` @@ -1226,6 +1241,21 @@ of the attributes inherited by all test rules, please check the

A unique name for the target.

+ + additional_contents + +

Dictionary of labels to strings; optional

+

Files that should be copied into specific subdirectories of the + Contents folder in the xctest. The keys of this + dictionary are labels pointing to single files, + filegroups, or targets; the corresponding value is the + name of the subdirectory of Contents where they should + be placed.

+

The relative directory structure of filegroup + contents is preserved when they are copied into the desired + Contents subdirectory.

+ + bundle_id diff --git a/test/macos_ui_test_test.sh b/test/macos_ui_test_test.sh index 7e83e5dee9..c5f70cfc04 100644 --- a/test/macos_ui_test_test.sh +++ b/test/macos_ui_test_test.sh @@ -216,4 +216,41 @@ function test_dsyms_generated() { done } +# Tests that files passed in via the additional_contents attribute get placed at +# the correct locations in the xctest bundle. +function test_additional_contents() { + create_common_files + + cat > app/simple.txt <> app/BUILD < app/simple.txt <> app/BUILD <