Vendor dependencies

Let's see how I like this workflow.
This commit is contained in:
John Doty 2022-12-19 08:27:18 -08:00
parent 34d1830413
commit 9c435dc440
7500 changed files with 1665121 additions and 99 deletions

View file

@ -0,0 +1,52 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//:attributes.bzl", "AppleBundleExtension")
load("@prelude//apple:apple_bundle_resources.bzl", "get_apple_bundle_resource_part_list")
load("@prelude//apple:apple_bundle_types.bzl", "AppleBundleResourceInfo")
load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolchainInfo", "AppleToolsInfo")
load("@prelude//user:rule_spec.bzl", "RuleRegistrationSpec")
load(":resource_group_map.bzl", "resource_group_map_attr")
def _get_apple_resources_toolchain_attr():
# FIXME: prelude// should be standalone (not refer to fbcode//)
return attrs.toolchain_dep(default = "fbcode//buck2/platform/toolchain:apple-resources", providers = [AppleToolchainInfo])
def _impl(ctx: "context") -> ["provider"]:
resource_output = get_apple_bundle_resource_part_list(ctx)
return [
DefaultInfo(),
AppleBundleResourceInfo(
resource_output = resource_output,
),
]
registration_spec = RuleRegistrationSpec(
name = "apple_resource_bundle",
impl = _impl,
attrs = {
"asset_catalogs_compilation_options": attrs.dict(key = attrs.string(), value = attrs.any(), default = {}),
"binary": attrs.option(attrs.dep(), default = None),
"deps": attrs.list(attrs.dep(), default = []),
"extension": attrs.one_of(attrs.enum(AppleBundleExtension), attrs.string()),
"ibtool_flags": attrs.option(attrs.list(attrs.string()), default = None),
"ibtool_module_flag": attrs.option(attrs.bool(), default = None),
"info_plist": attrs.source(),
"info_plist_substitutions": attrs.dict(key = attrs.string(), value = attrs.string(), sorted = False, default = {}),
"product_name": attrs.option(attrs.string(), default = None),
"resource_group": attrs.option(attrs.string(), default = None),
"resource_group_map": resource_group_map_attr(),
# Only include macOS hosted toolchains, so we compile resources directly on Mac RE
"_apple_toolchain": _get_apple_resources_toolchain_attr(),
# FIXME: prelude// should be standalone (not refer to fbsource//)
"_apple_tools": attrs.exec_dep(default = "fbsource//xplat/buck2/platform/apple:apple-tools", providers = [AppleToolsInfo]),
# Because `apple_resource_bundle` is a proxy for `apple_bundle`, we need to get `name`
# field of the `apple_bundle`, as it's used as a fallback value in Info.plist.
"_bundle_target_name": attrs.string(),
"_compile_resources_locally_override": attrs.option(attrs.bool(), default = None),
},
)

View file

@ -0,0 +1,51 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolchainInfo")
load("@prelude//cxx:cxx_toolchain_types.bzl", "CxxToolchainInfo")
load("@prelude//user:rule_spec.bzl", "RuleRegistrationSpec")
def _impl(ctx: "context") -> ["provider"]:
base = ctx.attrs.base[AppleToolchainInfo]
cxx_toolchain_override = ctx.attrs.cxx_toolchain[CxxToolchainInfo]
return [
DefaultInfo(),
AppleToolchainInfo(
actool = base.actool,
ibtool = base.ibtool,
dsymutil = base.dsymutil,
dwarfdump = base.dwarfdump,
lipo = base.lipo,
cxx_platform_info = base.cxx_platform_info,
cxx_toolchain_info = cxx_toolchain_override if cxx_toolchain_override != None else base.cxx_toolchain_info,
codesign = base.codesign,
codesign_allocate = base.codesign_allocate,
compile_resources_locally = base.compile_resources_locally,
libtool = base.libtool,
momc = base.momc,
min_version = base.min_version,
xctest = base.xctest,
platform_path = base.platform_path,
sdk_name = base.sdk_name,
sdk_path = base.sdk_path,
sdk_version = base.sdk_version,
sdk_build_version = base.sdk_build_version,
swift_toolchain_info = base.swift_toolchain_info,
watch_kit_stub_binary = base.watch_kit_stub_binary,
xcode_version = base.xcode_version,
xcode_build_version = base.xcode_build_version,
),
]
registration_spec = RuleRegistrationSpec(
name = "apple_toolchain_override",
impl = _impl,
attrs = {
"base": attrs.dep(providers = [AppleToolchainInfo]),
"cxx_toolchain": attrs.dep(providers = [CxxToolchainInfo]),
},
)

View file

@ -0,0 +1,36 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolsInfo")
load("@prelude//user:rule_spec.bzl", "RuleRegistrationSpec")
def _impl(ctx: "context") -> ["provider"]:
return [
DefaultInfo(),
AppleToolsInfo(
assemble_bundle = ctx.attrs.assemble_bundle[RunInfo],
info_plist_processor = ctx.attrs.info_plist_processor[RunInfo],
make_modulemap = ctx.attrs.make_modulemap[RunInfo],
make_vfsoverlay = ctx.attrs.make_vfsoverlay[RunInfo],
swift_objc_header_postprocess = ctx.attrs.swift_objc_header_postprocess[RunInfo],
),
]
# The `apple_tools` rule exposes a set of supplementary tools
# required by the Apple rules _internally_. Such tools are not
# toolchain/SDK specific, they're just internal helper tools.
registration_spec = RuleRegistrationSpec(
name = "apple_tools",
impl = _impl,
attrs = {
"assemble_bundle": attrs.dep(providers = [RunInfo]),
"info_plist_processor": attrs.dep(providers = [RunInfo]),
"make_modulemap": attrs.dep(providers = [RunInfo]),
"make_vfsoverlay": attrs.dep(providers = [RunInfo]),
"swift_objc_header_postprocess": attrs.dep(providers = [RunInfo]),
},
)

View file

@ -0,0 +1,59 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//:attributes.bzl", "AppleBundleExtension", "Traversal")
load("@prelude//apple:apple_bundle.bzl", "apple_bundle_impl")
load("@prelude//apple:apple_rules_impl_utility.bzl", "apple_bundle_extra_attrs")
load("@prelude//user:rule_spec.bzl", "RuleRegistrationSpec")
load(":watch_transition.bzl", "watch_transition")
def _apple_bundle_base_attrs():
return {
# Attributes comes from `attributes.bzl` but since it's autogenerated, we cannot easily abstract
"asset_catalogs_compilation_options": attrs.dict(key = attrs.string(), value = attrs.any(), default = {}),
"binary": attrs.option(attrs.dep(), default = None),
"codesign_flags": attrs.list(attrs.string(), default = []),
"codesign_identity": attrs.option(attrs.string(), default = None),
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"default_platform": attrs.option(attrs.string(), default = None),
"deps": attrs.list(attrs.dep(), default = []),
"extension": attrs.one_of(attrs.enum(AppleBundleExtension), attrs.string()),
"ibtool_flags": attrs.option(attrs.list(attrs.string()), default = None),
"ibtool_module_flag": attrs.option(attrs.bool(), default = None),
"incremental_bundling_enabled": attrs.option(attrs.bool(), default = None),
"info_plist": attrs.source(),
"info_plist_substitutions": attrs.dict(key = attrs.string(), value = attrs.string(), sorted = False, default = {}),
"labels": attrs.list(attrs.string(), default = []),
"licenses": attrs.list(attrs.source(), default = []),
"platform_binary": attrs.option(attrs.list(attrs.tuple(attrs.regex(), attrs.dep())), default = None),
"product_name": attrs.option(attrs.string(), default = None),
"resource_group": attrs.option(attrs.string(), default = None),
"resource_group_map": attrs.option(attrs.list(attrs.tuple(attrs.string(), attrs.list(attrs.tuple(attrs.dep(), attrs.enum(Traversal), attrs.option(attrs.string()))))), default = None),
"skip_copying_swift_stdlib": attrs.option(attrs.bool(), default = None),
"try_skip_code_signing": attrs.option(attrs.bool(), default = None),
"within_view": attrs.option(attrs.list(attrs.string())),
"xcode_product_type": attrs.option(attrs.string(), default = None),
}
def _apple_watchos_bundle_attrs():
attributes = {}
attributes.update(_apple_bundle_base_attrs())
attributes.update(apple_bundle_extra_attrs())
return attributes
def apple_watchos_bundle_impl(ctx: "context") -> ["provider"]:
# This rule is _equivalent_ to `apple_bundle` except it applies
# an incoming watchOS transition.
return apple_bundle_impl(ctx)
registration_spec = RuleRegistrationSpec(
name = "apple_watchos_bundle",
impl = apple_watchos_bundle_impl,
attrs = _apple_watchos_bundle_attrs(),
cfg = watch_transition,
)

View file

@ -0,0 +1,51 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//:attributes.bzl", "Traversal")
load(
"@prelude//apple:resource_groups.bzl",
"ResourceGroupInfo",
"create_resource_graph",
"get_resource_graph_node_map_func",
)
load(
"@prelude//cxx:groups.bzl",
"compute_mappings",
"parse_groups_definitions",
)
load("@prelude//user:rule_spec.bzl", "RuleRegistrationSpec")
def v1_attrs():
return attrs.list(attrs.tuple(attrs.string(), attrs.list(attrs.tuple(attrs.dep(), attrs.enum(Traversal), attrs.option(attrs.string())))))
def resource_group_map_attr():
v2_attrs = attrs.dep(providers = [ResourceGroupInfo])
return attrs.option(attrs.one_of(v2_attrs, v1_attrs()), default = None)
def _impl(ctx: "context") -> ["provider"]:
resource_groups = parse_groups_definitions(ctx.attrs.map)
resource_groups_deps = [mapping.root.node for group in resource_groups for mapping in group.mappings]
resource_graph = create_resource_graph(
ctx = ctx,
labels = [],
deps = resource_groups_deps,
exported_deps = [],
)
resource_graph_node_map = get_resource_graph_node_map_func(resource_graph)()
mappings = compute_mappings(groups = resource_groups, graph_map = resource_graph_node_map)
return [
DefaultInfo(),
ResourceGroupInfo(groups = resource_groups, groups_hash = hash(str(resource_groups)), mappings = mappings),
]
registration_spec = RuleRegistrationSpec(
name = "resource_group_map",
impl = _impl,
attrs = {
"map": v1_attrs(),
},
)

View file

@ -0,0 +1,84 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
"""
Transition from iOS to watchOS. Used for watchOS bundle rule.
Transforms both OS and SDK constraints.
Only sanity check for source configuration is done.
"""
load("@prelude//utils:utils.bzl", "expect")
def _os_and_sdk_unrelated_constraints(platform: PlatformInfo.type, refs: struct.type) -> {"target_label": ConstraintValueInfo.type}:
return {
constraint_setting_label: constraint_setting_value
for (constraint_setting_label, constraint_setting_value) in platform.configuration.constraints.items()
if constraint_setting_label not in [refs.os[ConstraintSettingInfo].label, refs.sdk[ConstraintSettingInfo].label]
}
def _old_os_constraint_value(platform: PlatformInfo.type, refs: struct.type) -> [None, ConstraintValueInfo.type]:
return platform.configuration.constraints.get(refs.os[ConstraintSettingInfo].label)
def _old_sdk_constraint_value(platform: PlatformInfo.type, refs: struct.type) -> [None, ConstraintValueInfo.type]:
return platform.configuration.constraints.get(refs.sdk[ConstraintSettingInfo].label)
def _impl(platform: PlatformInfo.type, refs: struct.type) -> "PlatformInfo":
# This functions operates in the following way:
# - Start with all the constraints from the platform and filter out the constraints for OS and SDK.
# - If the old OS constraint was iOS or watchOS, set the new constraint to be always watchOS.
# - If the old SDK constraint was iOS, replace with the equivalent watchOS constraint.
# - Return a new platform with the updated constraints.
updated_constraints = _os_and_sdk_unrelated_constraints(platform, refs)
# Update OS constraint
old_os = _old_os_constraint_value(platform, refs)
watchos = refs.watchos[ConstraintValueInfo]
ios = refs.ios[ConstraintValueInfo]
if old_os != None:
expect(old_os.label in [watchos.label, ios.label], "If present, OS transitioned non-identically to watchOS should be `iphoneos`, got {}".format(old_os.label))
updated_constraints[refs.os[ConstraintSettingInfo].label] = watchos
# Update SDK constraint
old_sdk = _old_sdk_constraint_value(platform, refs)
watchos_device_sdk = refs.watchos_device_sdk[ConstraintValueInfo]
watchos_simulator_sdk = refs.watchos_simulator_sdk[ConstraintValueInfo]
ios_device_sdk = refs.ios_device_sdk[ConstraintValueInfo]
ios_simulator_sdk = refs.ios_simulator_sdk[ConstraintValueInfo]
is_simulator = True
if old_sdk != None:
if old_sdk.label == watchos_simulator_sdk.label:
pass
elif old_sdk.label == watchos_device_sdk.label:
is_simulator = False
elif old_sdk.label == ios_simulator_sdk.label:
pass
elif old_sdk.label == ios_device_sdk.label:
is_simulator = False
else:
fail("If present, SDK transitioned non-identically to watchOS should be either `iphoneos` or `iphonesimulator`, got {}".format(old_sdk.label))
updated_constraints[refs.sdk[ConstraintSettingInfo].label] = watchos_simulator_sdk if is_simulator else watchos_device_sdk
new_cfg = ConfigurationInfo(
constraints = updated_constraints,
values = platform.configuration.values,
)
return PlatformInfo(
label = "watch_transition",
configuration = new_cfg,
)
# FIXME: prelude// should be standalone (not refer to ovr_config//)
watch_transition = transition(impl = _impl, refs = {
"ios": "ovr_config//os/constraints:iphoneos",
"ios_device_sdk": "ovr_config//os/sdk/apple/constraints:iphoneos",
"ios_simulator_sdk": "ovr_config//os/sdk/apple/constraints:iphonesimulator",
"os": "ovr_config//os/constraints:os",
"sdk": "ovr_config//os/sdk/apple/constraints:_",
"watchos": "ovr_config//os/constraints:watchos",
"watchos_device_sdk": "ovr_config//os/sdk/apple/constraints:watchos",
"watchos_simulator_sdk": "ovr_config//os/sdk/apple/constraints:watchsimulator",
})