Skip to content

Commit

Permalink
Only allow one module to define App Intents, as that is all that Appl…
Browse files Browse the repository at this point in the history
…e's app intents metadata processor tool allows for.

PiperOrigin-RevId: 590322476
  • Loading branch information
nglevin authored and swiple-rules-gardener committed Dec 12, 2023
1 parent 5668eb4 commit 21b435b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
2 changes: 2 additions & 0 deletions apple/internal/aspects/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ bzl_library(
deps = [
"//apple/internal:cc_info_support",
"//apple/internal/providers:app_intents_info",
"@bazel_skylib//lib:collections",
"@build_bazel_apple_support//lib:apple_support",
"@build_bazel_rules_swift//swift:module_name",
"@build_bazel_rules_swift//swift:providers",
],
)
Expand Down
15 changes: 11 additions & 4 deletions apple/internal/aspects/app_intents_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

"""Implementation of the aspect that propagates AppIntentsInfo providers."""

load(
"@bazel_skylib//lib:collections.bzl",
"collections",
)
load(
"@build_bazel_apple_support//lib:apple_support.bzl",
"apple_support",
Expand All @@ -23,6 +27,10 @@ load(
"@build_bazel_rules_apple//apple/internal/providers:app_intents_info.bzl",
"AppIntentsInfo",
)
load(
"@build_bazel_rules_swift//swift:module_name.bzl",
"derive_swift_module_name",
)
load(
"@build_bazel_rules_swift//swift:providers.bzl",
"SwiftInfo",
Expand All @@ -43,12 +51,11 @@ def _app_intents_aspect_impl(target, ctx):
)

swiftconstvalues_files = []
module_names = []
module_names = collections.uniq([x.name for x in target[SwiftInfo].direct_modules if x.swift])
if not module_names:
module_names = [derive_swift_module_name(ctx.label)]
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
if xcode_version_config.xcode_version() >= apple_common.dotted_version("15.0"):
# TODO(b/315847370): See if these names need to be deduplicated, if duplicate entries are at
# all possible.
module_names = [x.name for x in target[SwiftInfo].direct_modules if x.swift]
swiftconstvalues_files = target[OutputGroupInfo]["const_values"].to_list()

return [
Expand Down
25 changes: 16 additions & 9 deletions apple/internal/resource_actions/app_intents.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,22 @@ def generate_app_intents_metadata_bundle(
args.add("appintentsmetadataprocessor")

args.add("--binary-file", bundle_binary)
if len(intents_module_names) == 0:
# TODO(b/315847370): See why this works for Xcode 14.x, and if it should be an actual module
# name instead.
args.add("--module-name", label.name)
else:
args.add_all(
intents_module_names,
before_each = "--module-name",
)

if len(intents_module_names) > 1:
fail("""
Found the following module names in the top level target {label} for app_intents: {intents_module_names}
App Intents must have only one module name for metadata generation to work correctly.
""".format(
intents_module_names = ", ".join(intents_module_names),
label = str(label),
))
elif len(intents_module_names) == 0:
fail("""
Could not find a module name for app_intents. One is required for App Intents metadata generation.
""")

args.add("--module-name", intents_module_names[0])
args.add("--output", output.dirname)
args.add_all(
source_files,
Expand Down
16 changes: 8 additions & 8 deletions test/starlark_tests/ios_application_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -593,15 +593,15 @@ def ios_application_test_suite(name):
],
)

# Test app with a Widget Configuration Intent with a computed property generates and bundles Metadata.appintents bundle.
archive_contents_test(
name = "{}_with_app_intent_and_widget_configuration_intent_contains_app_intents_metadata_bundle_test".format(name),
build_type = "simulator",
# Test app that has two Intents defined as top level modules generates an error message.
analysis_failure_message_test(
name = "{}_with_two_app_intents_and_two_modules_fails".format(name),
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_app_intent_and_widget_configuration_intent",
contains = [
"$BUNDLE_ROOT/Metadata.appintents/extract.actionsdata",
"$BUNDLE_ROOT/Metadata.appintents/version.json",
],
expected_error = (
"App Intents must have only one module name for metadata generation to work correctly."
).format(
package = "//test/starlark_tests/targets_under_test/ios",
),
tags = [
name,
],
Expand Down

1 comment on commit 21b435b

@keith
Copy link
Member

@keith keith commented on 21b435b Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.