Skip to content

Commit

Permalink
Apply platform defaults to the internal platform prerequisites constr…
Browse files Browse the repository at this point in the history
…uctor.

Prerequisite for creating an alternative Apple resource aspect that compiles additional resource types with device families for the given platform, assuming the default values.

PiperOrigin-RevId: 693010003
  • Loading branch information
nglevin authored and swiple-rules-gardener committed Nov 4, 2024
1 parent ca91ef9 commit f7502d7
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 15 deletions.
1 change: 1 addition & 0 deletions apple/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ bzl_library(
],
deps = [
":providers",
"//apple/internal/utils:platform_defaults",
"@build_bazel_apple_support//lib:apple_support",
],
)
Expand Down
4 changes: 0 additions & 4 deletions apple/internal/aspects/resource_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,11 @@ def _platform_prerequisites_for_aspect(target, aspect_ctx):
deps_and_target = getattr(aspect_ctx.rule.attr, "deps", []) + [target]
uses_swift = swift_support.uses_swift(deps_and_target)

# TODO(b/176548199): Support device_families when rule_descriptor can be accessed from an
# aspect, or the list of allowed device families can be determined independently of the
# rule_descriptor.
return platform_support.platform_prerequisites(
apple_fragment = apple_fragment,
apple_platform_info = platform_support.apple_platform_info_from_rule_ctx(aspect_ctx),
build_settings = apple_xplat_toolchain_info.build_settings,
config_vars = aspect_ctx.var,
device_families = None,
explicit_minimum_os = cpp_fragment.minimum_os_version(),
objc_fragment = None,
uses_swift = uses_swift,
Expand Down
14 changes: 11 additions & 3 deletions apple/internal/platform_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ load(
"@build_bazel_rules_apple//apple/internal:providers.bzl",
"new_appleplatforminfo",
)
load(
"@build_bazel_rules_apple//apple/internal/utils:platform_defaults.bzl",
"platform_defaults",
)

visibility([
"//apple/...",
Expand Down Expand Up @@ -123,7 +127,7 @@ def _platform_prerequisites(
build_settings,
config_vars,
cpp_fragment = None,
device_families,
device_families = None,
explicit_minimum_os,
objc_fragment = None,
uses_swift,
Expand All @@ -136,7 +140,8 @@ def _platform_prerequisites(
build_settings: A struct with build settings info from AppleXplatToolsToolchainInfo.
config_vars: A reference to configuration variables, typically from `ctx.var`.
cpp_fragment: An cpp fragment (ctx.fragments.cpp), if it is present. Optional.
device_families: The list of device families that apply to the target being built.
device_families: The list of device families that apply to the target being built. If not
specified, the default for the platform will be used.
explicit_minimum_os: A dotted version string indicating minimum OS desired.
objc_fragment: An Objective-C fragment (ctx.fragments.objc), if it is present. Optional.
uses_swift: Boolean value to indicate if this target uses Swift.
Expand All @@ -149,12 +154,15 @@ def _platform_prerequisites(
platform_type_attr = getattr(apple_common.platform_type, apple_platform_info.target_os)
sdk_version = xcode_version_config.sdk_version_for_platform(platform)

if not device_families:
device_families = platform_defaults.device_families(str(platform_type_attr))

return struct(
apple_fragment = apple_fragment,
build_settings = build_settings,
config_vars = config_vars,
cpp_fragment = cpp_fragment,
device_families = sorted(device_families) if device_families else None,
device_families = sorted(device_families, reverse = True),
minimum_os = explicit_minimum_os,
platform = platform,
platform_type = platform_type_attr,
Expand Down
5 changes: 5 additions & 0 deletions apple/internal/utils/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ bzl_library(
deps = ["@bazel_skylib//lib:paths"],
)

bzl_library(
name = "platform_defaults",
srcs = ["platform_defaults.bzl"],
)

bzl_library(
name = "xctoolrunner",
srcs = ["xctoolrunner.bzl"],
Expand Down
33 changes: 33 additions & 0 deletions apple/internal/utils/platform_defaults.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Shared default values for Apple platforms."""

visibility("//apple/internal/...")

_PLATFORM_TYPE_TO_DEVICE_FAMILIES = {
"ios": ["iphone", "ipad"],
"macos": ["mac"],
"tvos": ["tv"],
"visionos": ["vision"],
"watchos": ["watch"],
}

def _device_families(platform_type):
"""Returns the default device families list for a given platform."""
return _PLATFORM_TYPE_TO_DEVICE_FAMILIES[platform_type]

platform_defaults = struct(
device_families = _device_families,
)
4 changes: 2 additions & 2 deletions test/starlark_tests/ios_extension_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def ios_extension_test_suite(name):
"DTXcode": "*",
"DTXcodeBuild": "*",
"MinimumOSVersion": common.min_os_ios.baseline,
"UIDeviceFamily:0": "2",
"UIDeviceFamily:1": "1",
"UIDeviceFamily:0": "1",
"UIDeviceFamily:1": "2",
},
tags = [name],
)
Expand Down
4 changes: 2 additions & 2 deletions test/starlark_tests/ios_framework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def ios_framework_test_suite(name):
"DTXcode": "*",
"DTXcodeBuild": "*",
"MinimumOSVersion": common.min_os_ios.baseline,
"UIDeviceFamily:0": "2",
"UIDeviceFamily:1": "1",
"UIDeviceFamily:0": "1",
"UIDeviceFamily:1": "2",
},
tags = [name],
)
Expand Down
4 changes: 2 additions & 2 deletions test/starlark_tests/ios_imessage_application_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def ios_imessage_application_test_suite(name):
"DTXcodeBuild": "*",
"LSApplicationLaunchProhibited": "true",
"MinimumOSVersion": common.min_os_ios.baseline,
"UIDeviceFamily:0": "2",
"UIDeviceFamily:1": "1",
"UIDeviceFamily:0": "1",
"UIDeviceFamily:1": "2",
},
tags = [name],
)
Expand Down
4 changes: 2 additions & 2 deletions test/starlark_tests/ios_imessage_extension_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def ios_imessage_extension_test_suite(name):
"DTXcodeBuild": "*",
"MinimumOSVersion": common.min_os_ios.baseline,
"NSExtension:NSExtensionPointIdentifier": "com.apple.widget-extension",
"UIDeviceFamily:0": "2",
"UIDeviceFamily:1": "1",
"UIDeviceFamily:0": "1",
"UIDeviceFamily:1": "2",
},
tags = [name],
)
Expand Down

0 comments on commit f7502d7

Please sign in to comment.