Skip to content

Commit

Permalink
Fork the Xcode rules from Bazel built-in Starlark into apple_support.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 631018102
  • Loading branch information
allevato authored and swiple-rules-gardener committed May 6, 2024
1 parent d5a60a6 commit f1bbadc
Show file tree
Hide file tree
Showing 9 changed files with 690 additions and 26 deletions.
6 changes: 5 additions & 1 deletion test/xcode_config_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ load(
"@build_bazel_apple_support//xcode:xcode_version.bzl",
"xcode_version",
)
load(
"@build_bazel_apple_support//xcode/private:providers.bzl",
"XcodeVersionPropertiesInfo",
) # buildifier: disable=bzl-visibility
load(":test_helpers.bzl", "FIXTURE_TAGS", "find_action", "make_all_tests")

visibility("private")

# ------------------------------------------------------------------------------

def _version_retriever_impl(ctx):
xcode_properties = ctx.attr.dep[apple_common.XcodeProperties]
xcode_properties = ctx.attr.dep[XcodeVersionPropertiesInfo]
version = xcode_properties.xcode_version
return [config_common.FeatureFlagInfo(value = version)]

Expand Down
6 changes: 5 additions & 1 deletion test/xcode_version_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ load(
"@build_bazel_apple_support//xcode:xcode_version.bzl",
"xcode_version",
)
load(
"@build_bazel_apple_support//xcode/private:providers.bzl",
"XcodeVersionPropertiesInfo",
) # buildifier: disable=bzl-visibility
load(":test_helpers.bzl", "FIXTURE_TAGS", "make_all_tests")

visibility("private")
Expand Down Expand Up @@ -47,7 +51,7 @@ def _read_version_from_provider_test_impl(ctx):
env = analysistest.begin(ctx)

target_under_test = analysistest.target_under_test(env)
xcode_properties = target_under_test[apple_common.XcodeProperties]
xcode_properties = target_under_test[XcodeVersionPropertiesInfo]

asserts.equals(env, "8", xcode_properties.xcode_version)
asserts.equals(env, "9.0", xcode_properties.default_ios_sdk_version)
Expand Down
8 changes: 7 additions & 1 deletion xcode/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package(
bzl_library(
name = "available_xcodes",
srcs = ["available_xcodes.bzl"],
deps = ["//xcode/private:providers"],
)

bzl_library(
Expand All @@ -19,22 +20,27 @@ bzl_library(
bzl_library(
name = "xcode_config",
srcs = ["xcode_config.bzl"],
deps = ["//xcode/private:providers"],
)

bzl_library(
name = "xcode_config_alias",
srcs = ["xcode_config_alias.bzl"],
deps = ["//xcode/private:providers"],
)

bzl_library(
name = "xcode_version",
srcs = ["xcode_version.bzl"],
deps = ["//xcode/private:providers"],
)

# Consumed by bazel tests.
filegroup(
name = "for_bazel_tests",
testonly = True,
srcs = glob(["**"]),
srcs = glob(["**"]) + [
"//xcode/private:for_bazel_tests",
],
visibility = ["//:__pkg__"],
)
46 changes: 40 additions & 6 deletions xcode/available_xcodes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,45 @@

"""Implementation of the `available_xcodes` build rule."""

load(
"@build_bazel_apple_support//xcode/private:providers.bzl",
"AvailableXcodesInfo",
"XcodeVersionRuleInfo",
)

visibility("public")

def available_xcodes(name, **kwargs):
# TODO: b/311385128 - Migrate the native implementation here.
native.available_xcodes(
name = name,
**kwargs
)
def _available_xcodes_impl(ctx):
available_versions = [
target[XcodeVersionRuleInfo]
for target in ctx.attr.versions
]
default_version = ctx.attr.default[XcodeVersionRuleInfo]

return [
AvailableXcodesInfo(
available_versions = available_versions,
default_version = default_version,
),
]

available_xcodes = rule(
attrs = {
"default": attr.label(
doc = "The default Xcode version for this platform.",
mandatory = True,
providers = [[XcodeVersionRuleInfo]],
),
"versions": attr.label_list(
doc = "The Xcode versions that are available on this platform.",
providers = [[XcodeVersionRuleInfo]],
),
},
doc = """\
Two targets of this rule can be depended on by an `xcode_config` rule instance
to indicate the remotely and locally available Xcode versions. This allows
selection of an official Xcode version from the collectively available Xcodes.
""",
implementation = _available_xcodes_impl,
provides = [AvailableXcodesInfo],
)
20 changes: 20 additions & 0 deletions xcode/private/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

licenses(["notice"])

package(
default_visibility = ["//xcode:__subpackages__"],
)

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

# Consumed by bazel tests.
filegroup(
name = "for_bazel_tests",
testonly = True,
srcs = glob(["**"]),
visibility = ["//xcode:__pkg__"],
)
110 changes: 110 additions & 0 deletions xcode/private/providers.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 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.

"""Providers used internally by the Xcode rules not meant for client use."""

visibility([
"@build_bazel_apple_support//test/...",
"@build_bazel_apple_support//xcode/...",
])

AvailableXcodesInfo = provider(
doc = """\
The available Xcode versions computed from the `available_xcodes` rule.
""",
fields = {
"available_versions": """\
The available Xcode versions from `available_xcodes`.
""",
"default_version": """\
The default Xcode version from `available_xcodes`.
""",
},
)

def _xcode_version_properties_info_init(
*,
xcode_version,
default_ios_sdk_version = "8.4",
default_macos_sdk_version = "10.11",
default_tvos_sdk_version = "9.0",
default_watchos_sdk_version = "2.0",
default_visionos_sdk_version = "1.0"):
# Ensure that all fields get default values if they weren't specified.
return {
"xcode_version": xcode_version,
"default_ios_sdk_version": default_ios_sdk_version,
"default_macos_sdk_version": default_macos_sdk_version,
"default_tvos_sdk_version": default_tvos_sdk_version,
"default_watchos_sdk_version": default_watchos_sdk_version,
"default_visionos_sdk_version": default_visionos_sdk_version,
}

XcodeVersionPropertiesInfo, _new_xcode_version_properties_info = provider(
doc = """\
Information about a specific Xcode version, such as its default SDK versions.
""",
fields = {
"xcode_version": """\
A string representing the Xcode version number, or `None` if it is unknown.
""",
"default_ios_sdk_version": """\
A string representing the default iOS SDK version number for this version of
Xcode, or `None` if it is unknown.
""",
"default_macos_sdk_version": """\
A string representing the default macOS SDK version number for this version of
Xcode, or `None` if it is unknown.
""",
"default_tvos_sdk_version": """\
A string representing the default tvOS SDK version number for this version of
Xcode, or `None` if it is unknown.
""",
"default_watchos_sdk_version": """\
A string representing the default watchOS SDK version number for this version of
Xcode, or `None` if it is unknown.
""",
"default_visionos_sdk_version": """\
A string representing the default visionOS SDK version number for this version
of Xcode, or `None` if it is unknown.
""",
},
init = _xcode_version_properties_info_init,
)

XcodeVersionRuleInfo = provider(
doc = """\
The information in a single target of the `xcode_version` rule. A single target
of this rule contains an official version label decided by Apple, a number of
supported aliases one might use to reference this version, and various
properties of the Xcode version (such as default SDK versions).
For example, one may want to reference official Xcode version 7.0.1 using the
"7" or "7.0" aliases. This official version of Xcode may have a default
supported iOS SDK of 9.0.
""",
fields = {
"aliases": """\
A list of strings denoting aliases that can be used to reference this Xcode
version.
""",
"label": """\
The build `Label` of the `xcode_version` target that propagated this provider.
""",
"xcode_version_properties": """\
An `XcodeVersionPropertiesInfo` provider that contains the details about this
Xcode version, such as its default SDK versions.
""",
},
)
Loading

1 comment on commit f1bbadc

@brentleyjones
Copy link
Collaborator

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.