Skip to content

Commit

Permalink
Add support for other resource rules
Browse files Browse the repository at this point in the history
Summary:
Building off the previous diff, we can now support other resource rules by simply adding
1. an XcodeDataInfo provider for that rule
2. setting the extra_xcode_files
3. add the rule_type as one that is supported but doesn't have a native target

Reviewed By: milend

Differential Revision: D67841936

fbshipit-source-id: c59cc010c3f29038c25d0eca063d6f020c29f2ca
  • Loading branch information
chatura-atapattu authored and facebook-github-bot committed Jan 6, 2025
1 parent 7e73615 commit 4e2c07d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
19 changes: 18 additions & 1 deletion prelude/apple/apple_asset_catalog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
# of this source tree.

load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolchainInfo")
load(
"@prelude//ide_integrations/xcode:data.bzl",
"XCODE_DATA_SUB_TARGET",
"XcodeDataInfoKeys",
"generate_xcode_data",
)
load("@prelude//utils:utils.bzl", "flatten")
load(":apple_asset_catalog_compilation_options.bzl", "AppleAssetCatalogsCompilationOptions", "get_apple_asset_catalogs_compilation_options") # @unused Used as a type
load(":apple_asset_catalog_types.bzl", "AppleAssetCatalogResult", "AppleAssetCatalogSpec", "StringWithSourceTarget")
Expand All @@ -27,7 +33,14 @@ def apple_asset_catalog_impl(ctx: AnalysisContext) -> list[Provider]:
exported_deps = [],
asset_catalog_spec = spec,
)
return [DefaultInfo(default_output = None), graph]

xcode_data_default_info, xcode_data_info = generate_xcode_data(ctx, "apple_asset_catalog", None, _xcode_populate_attributes)

return [DefaultInfo(
sub_targets = {
XCODE_DATA_SUB_TARGET: xcode_data_default_info,
},
), graph, xcode_data_info]

def compile_apple_asset_catalog(ctx: AnalysisContext, specs: list[AppleAssetCatalogSpec]) -> [AppleAssetCatalogResult, None]:
single_spec = _merge_asset_catalog_specs(ctx, specs)
Expand Down Expand Up @@ -119,3 +132,7 @@ def _get_actool_command(ctx: AnalysisContext, info: AppleAssetCatalogSpec, catal
)
command = cmd_args(["/bin/sh", wrapper_script], hidden = [actool_command, catalog_output])
return command

def _xcode_populate_attributes(ctx) -> dict[str, typing.Any]:
data = {XcodeDataInfoKeys.EXTRA_XCODE_FILES: ctx.attrs.dirs}
return data
19 changes: 18 additions & 1 deletion prelude/apple/apple_core_data.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

load("@prelude//:paths.bzl", "paths")
load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolchainInfo")
load(
"@prelude//ide_integrations/xcode:data.bzl",
"XCODE_DATA_SUB_TARGET",
"XcodeDataInfoKeys",
"generate_xcode_data",
)
load(":apple_bundle_utility.bzl", "get_bundle_min_target_version", "get_bundle_resource_processing_options")
load(":apple_core_data_types.bzl", "AppleCoreDataSpec")
load(":apple_sdk.bzl", "get_apple_sdk_name")
Expand All @@ -25,7 +31,14 @@ def apple_core_data_impl(ctx: AnalysisContext) -> list[Provider]:
exported_deps = [],
core_data_spec = spec,
)
return [DefaultInfo(), graph]

xcode_data_default_info, xcode_data_info = generate_xcode_data(ctx, "apple_asset_catalog", None, _xcode_populate_attributes)

return [DefaultInfo(
sub_targets = {
XCODE_DATA_SUB_TARGET: xcode_data_default_info,
},
), graph, xcode_data_info]

def compile_apple_core_data(ctx: AnalysisContext, specs: list[AppleCoreDataSpec], product_name: str) -> Artifact | None:
if len(specs) == 0:
Expand Down Expand Up @@ -93,3 +106,7 @@ def _get_tool_command(ctx: AnalysisContext, core_data_spec: AppleCoreDataSpec, p
cmd_args(core_data_spec.path, format = "./{}"),
output,
], delimiter = " ", hidden = core_data_spec.path)

def _xcode_populate_attributes(ctx) -> dict[str, typing.Any]:
data = {XcodeDataInfoKeys.EXTRA_XCODE_FILES: [ctx.attrs.path]}
return data
19 changes: 18 additions & 1 deletion prelude/apple/scene_kit_assets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
# of this source tree.

load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolchainInfo")
load(
"@prelude//ide_integrations/xcode:data.bzl",
"XCODE_DATA_SUB_TARGET",
"XcodeDataInfoKeys",
"generate_xcode_data",
)
load(":apple_bundle_utility.bzl", "get_bundle_min_target_version", "get_bundle_resource_processing_options")
load(":apple_sdk.bzl", "get_apple_sdk_name")
load(":resource_groups.bzl", "create_resource_graph")
Expand All @@ -22,7 +28,14 @@ def scene_kit_assets_impl(ctx: AnalysisContext) -> list[Provider]:
exported_deps = [],
scene_kit_assets_spec = spec,
)
return [DefaultInfo(), graph]

xcode_data_default_info, xcode_data_info = generate_xcode_data(ctx, "apple_asset_catalog", None, _xcode_populate_attributes)

return [DefaultInfo(
sub_targets = {
XCODE_DATA_SUB_TARGET: xcode_data_default_info,
},
), graph, xcode_data_info]

def compile_scene_kit_assets(ctx: AnalysisContext, specs: list[SceneKitAssetsSpec]) -> Artifact | None:
if len(specs) == 0:
Expand Down Expand Up @@ -71,3 +84,7 @@ def _get_copy_scene_kit_assets_cmd(ctx: AnalysisContext, scene_kit_assets_spec:
"--target-platform=" + get_apple_sdk_name(ctx),
"--target-version=" + get_bundle_min_target_version(ctx, ctx.attrs.binary),
], delimiter = " ")

def _xcode_populate_attributes(ctx) -> dict[str, typing.Any]:
data = {XcodeDataInfoKeys.EXTRA_XCODE_FILES: [ctx.attrs.path]}
return data

0 comments on commit 4e2c07d

Please sign in to comment.