Skip to content

Commit 43ac4f3

Browse files
Create xcodeproj_extra_files aspect hint (#3150)
Create an aspect hint to allow dependencies to propagate up extra files that should be include in the Xcode navigator --------- Signed-off-by: John Flanagan <john.flanagan@doordash.com> Signed-off-by: John Flanagan <91548783+jflan-dd@users.noreply.github.com> Co-authored-by: Brentley Jones <github@brentleyjones.com>
1 parent 754ac5d commit 43ac4f3

File tree

11 files changed

+190
-1
lines changed

11 files changed

+190
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ END_UNRELEASED_TEMPLATE
4848

4949
### New
5050

51-
* TBD
51+
* Added `xcodeproj_extra_files` aspect hint: [#3150](https://github.com/MobileNativeFoundation/rules_xcodeproj/pull/3150)
5252

5353
### Adjusted
5454

docs/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
66
# Generating
77

88
_DOC_COMPONENTS = [
9+
"aspect_hints",
910
"project_options",
1011
"providers",
1112
"top_level_target",
@@ -35,6 +36,7 @@ genrule(
3536
":xcschemes",
3637
":xcode_build_settings",
3738
":providers",
39+
":aspect_hints",
3840
],
3941
outs = ["bazel.generated.md"],
4042
cmd = """\

docs/bazel.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ load("@rules_xcodeproj//xcodeproj:xcodeproj.bzl", "xcodeproj")
5050
- [Providers](#providers)
5151
- [`XcodeProjAutomaticTargetProcessingInfo`](#XcodeProjAutomaticTargetProcessingInfo)
5252
- [`XcodeProjInfo`](#XcodeProjInfo)
53+
- [Aspect Hints](#aspect-hints)
54+
- [`xcodeproj_extra_files`](#xcodeproj_extra_files)
5355

5456
# Core
5557

@@ -814,3 +816,47 @@ Provides information needed to generate an Xcode project.
814816
| <a id="XcodeProjInfo-xcode_targets"></a>xcode_targets | A `depset` of values from `xcode_targets.make`, which potentially will become targets in the Xcode project. |
815817

816818

819+
# Aspect Hints
820+
821+
Aspect hints that can be used to provide additional information during project generation.
822+
823+
<a id="xcodeproj_extra_files"></a>
824+
825+
## xcodeproj_extra_files
826+
827+
<pre>
828+
xcodeproj_extra_files(<a href="#xcodeproj_extra_files-name">name</a>, <a href="#xcodeproj_extra_files-files">files</a>)
829+
</pre>
830+
831+
This rule is used to surface extra files that should be included in the Xcode
832+
project navigator, but otherwise aren't inputs to a target. The provider
833+
created by this rule should be attached to the related target via an aspect
834+
hint.
835+
836+
**EXAMPLE**
837+
838+
```starlark
839+
load("@rules_xcodeproj//xcodeproj:xcodeproj_extra_files.bzl", "xcodeproj_extra_files")
840+
841+
swift_library(
842+
...
843+
aspect_hints = [":library_extra_files"],
844+
...
845+
)
846+
847+
# Display the README.md file located alongside the Swift library in Xcode
848+
xcodeproj_extra_files(
849+
name = "library_extra_files",
850+
files = ["README.md"],
851+
)
852+
```
853+
854+
**ATTRIBUTES**
855+
856+
857+
| Name | Description | Type | Mandatory | Default |
858+
| :------------- | :------------- | :------------- | :------------- | :------------- |
859+
| <a id="xcodeproj_extra_files-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
860+
| <a id="xcodeproj_extra_files-files"></a>files | The list of extra files to surface in the Xcode navigator. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
861+
862+

test/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test_suite(
1313
"//test/internal/target",
1414
"//test/internal/target_id",
1515
"//test/internal/targets",
16+
"//test/internal/xcodeproj_extra_files",
1617
"//test/internal/xcschemes",
1718
],
1819
)
@@ -29,6 +30,7 @@ bzl_library(
2930
"//test/internal/target:bzls",
3031
"//test/internal/target_id:bzls",
3132
"//test/internal/targets:bzls",
33+
"//test/internal/xcodeproj_extra_files:bzls",
3234
"//test/internal/xcschemes:bzls",
3335
],
3436
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load(":xcodeproj_extra_files_tests.bzl", "xcodeproj_extra_files_test_suite")
3+
4+
xcodeproj_extra_files_test_suite(name = "xcodeproj_extra_files_test")
5+
6+
test_suite(name = "xcodeproj_extra_files")
7+
8+
bzl_library(
9+
name = "bzls",
10+
srcs = glob(
11+
["*.bzl"],
12+
exclude = ["utils.bzl"],
13+
),
14+
visibility = ["//test:__pkg__"],
15+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Tests for the `xcodeproj_extra_files` module."""
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
4+
load("//xcodeproj:xcodeproj_extra_files.bzl", "xcodeproj_extra_files")
5+
6+
# buildifier: disable=bzl-visibility
7+
load("//xcodeproj/internal:providers.bzl", "XcodeProjExtraFilesHintInfo")
8+
9+
def _provider_contents_test_impl(ctx):
10+
env = analysistest.begin(ctx)
11+
12+
target_under_test = analysistest.target_under_test(env)
13+
14+
files_list = target_under_test[XcodeProjExtraFilesHintInfo].files.to_list()
15+
16+
asserts.equals(env, len(files_list), 1)
17+
asserts.equals(
18+
env,
19+
files_list[0].path,
20+
"test/internal/xcodeproj_extra_files/BUILD",
21+
)
22+
23+
return analysistest.end(env)
24+
25+
provider_contents_test = analysistest.make(_provider_contents_test_impl)
26+
27+
def _test_provider_contents():
28+
xcodeproj_extra_files(
29+
name = "xcodeproj_extra_files_subject",
30+
files = ["BUILD"],
31+
tags = ["manual"],
32+
)
33+
34+
provider_contents_test(
35+
name = "provider_contents_test",
36+
target_under_test = ":xcodeproj_extra_files_subject",
37+
)
38+
39+
def xcodeproj_extra_files_test_suite(name):
40+
_test_provider_contents()
41+
42+
native.test_suite(
43+
name = name,
44+
tests = [
45+
":provider_contents_test",
46+
],
47+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""# Aspect Hints
2+
3+
Aspect hints that can be used to provide additional information during \
4+
project generation.
5+
"""
6+
7+
load(
8+
"//xcodeproj:xcodeproj_extra_files.bzl",
9+
_xcodeproj_extra_files = "xcodeproj_extra_files",
10+
)
11+
12+
xcodeproj_extra_files = _xcodeproj_extra_files

xcodeproj/internal/docs/bazel.header.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ load("@rules_xcodeproj//xcodeproj:xcodeproj.bzl", "xcodeproj")
5050
- [Providers](#providers)
5151
- [`XcodeProjAutomaticTargetProcessingInfo`](#XcodeProjAutomaticTargetProcessingInfo)
5252
- [`XcodeProjInfo`](#XcodeProjInfo)
53+
- [Aspect Hints](#aspect-hints)
54+
- [`xcodeproj_extra_files`](#xcodeproj_extra_files)
5355

5456
# Core

xcodeproj/internal/files/input_files.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ load(
1111
"EMPTY_LIST",
1212
"memory_efficient_depset",
1313
)
14+
load("//xcodeproj/internal:providers.bzl", "XcodeProjExtraFilesHintInfo")
1415
load(":linker_input_files.bzl", "linker_input_files")
1516
load(":resources.bzl", resources_module = "resources")
1617

@@ -408,6 +409,13 @@ def _collect_input_files(
408409
rule_files = ctx.rule.files,
409410
)
410411

412+
# Collect extra fila provided via the `xcodeproj_extra_files` aspect hint
413+
for hint in rule_attr.aspect_hints:
414+
if XcodeProjExtraFilesHintInfo in hint:
415+
hint_extra_files = hint[XcodeProjExtraFilesHintInfo].files
416+
if hint_extra_files:
417+
extra_files.extend(hint_extra_files.to_list())
418+
411419
product_framework_files = memory_efficient_depset(
412420
transitive = [
413421
info.inputs._product_framework_files

xcodeproj/internal/providers.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ XcodeProjRunnerOutputInfo = provider(
1515
"runner": "The xcodeproj runner.",
1616
},
1717
)
18+
19+
XcodeProjExtraFilesHintInfo = provider(
20+
doc = "Provides a list of extra files to include during project generation",
21+
fields = {
22+
"files": "List of files to include in the extra files.",
23+
},
24+
)

0 commit comments

Comments
 (0)