Skip to content

Commit

Permalink
Add support for .provisionprofile in local_provisioning_profile (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
luispadron authored Jan 17, 2025
1 parent 38ae5c2 commit d7c7f86
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
59 changes: 42 additions & 17 deletions apple/internal/local_provisioning_profiles.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ load(
"AppleProvisioningProfileInfo",
)

_IOS_PROFILE_EXTENSION = ".mobileprovision"
_MACOS_PROFILE_EXTENSION = ".provisionprofile"
_PROFILE_EXTENSIONS = [_IOS_PROFILE_EXTENSION, _MACOS_PROFILE_EXTENSION]

def _provisioning_profile_repository(repository_ctx):
system_profiles_path = "{}/Library/MobileDevice/Provisioning Profiles".format(repository_ctx.os.environ["HOME"])
repository_ctx.execute(["mkdir", "-p", system_profiles_path])
Expand All @@ -16,12 +20,16 @@ def _provisioning_profile_repository(repository_ctx):
repository_ctx.execute(["mkdir", "-p", user_profiles_path])
repository_ctx.symlink(user_profiles_path, "user profiles")

repository_ctx.file("BUILD.bazel", """\
repository_ctx.file(
"BUILD.bazel",
"""\
filegroup(
name = "profiles",
srcs = glob([
"profiles/*.mobileprovision",
"user profiles/*.mobileprovision",
"profiles/*{ios_extension}",
"profiles/*{macos_extension}",
"user profiles/*{ios_extension}",
"user profiles/*{macos_extension}",
], allow_empty = True),
visibility = ["//visibility:public"],
)
Expand All @@ -34,17 +42,22 @@ filegroup(
alias(
name = "fallback_profiles",
actual = "{}",
actual = "{fallback_profiles}",
visibility = ["//visibility:public"],
)
""".format(repository_ctx.attr.fallback_profiles or ":empty"))
""".format(
ios_extension = _IOS_PROFILE_EXTENSION,
macos_extension = _MACOS_PROFILE_EXTENSION,
fallback_profiles = repository_ctx.attr.fallback_profiles or ":empty",
),
)

provisioning_profile_repository = repository_rule(
environ = ["HOME"],
implementation = _provisioning_profile_repository,
attrs = {
"fallback_profiles": attr.label(
allow_files = [".mobileprovision"],
allow_files = _PROFILE_EXTENSIONS,
),
},
doc = """
Expand Down Expand Up @@ -124,7 +137,7 @@ provisioning_profile_repository_extension = module_extension(
tag_classes = {
"setup": tag_class(attrs = {
"fallback_profiles": attr.label(
allow_files = [".mobileprovision"],
allow_files = _PROFILE_EXTENSIONS,
),
}),
},
Expand All @@ -138,7 +151,7 @@ def _local_provisioning_profile(ctx):
ctx.fail("Either local or fallback provisioning profiles must exist")

profile_name = ctx.attr.profile_name or ctx.attr.name
selected_profile_path = "{name}.mobileprovision".format(name = profile_name)
selected_profile_path = profile_name + ctx.attr.profile_extension
selected_profile = ctx.actions.declare_file(selected_profile_path)

args = ctx.actions.args()
Expand Down Expand Up @@ -172,6 +185,11 @@ def _local_provisioning_profile(ctx):

local_provisioning_profile = rule(
attrs = {
"profile_extension": attr.string(
doc = "The extension for the provisioning profile which may differ by platform.",
values = _PROFILE_EXTENSIONS,
default = _IOS_PROFILE_EXTENSION,
),
"profile_name": attr.string(
doc = "Name of the profile to use, if it's not provided the name of the rule is used",
),
Expand All @@ -193,15 +211,19 @@ local_provisioning_profile = rule(
implementation = _local_provisioning_profile,
doc = """
This rule declares a bazel target that you can pass to the
'provisioning_profile' attribute of rules that require it. It discovers a
`provisioning_profile` attribute of rules that support it. It discovers a
provisioning profile for the given attributes either on the user's local
machine, or with the optional 'fallback_profiles' passed to
'provisioning_profile_repository'. This will automatically pick the newest
profile if there are multiple profiles matching the given criteria. By default
this rule will search for a profile with the same name as the rule itself, you
can pass profile_name to use a different name, and you can pass team_id if
you'd like to disambiguate between 2 Apple developer accounts that have the
same profile name.
machine, or with the optional `fallback_profiles` passed to
`provisioning_profile_repository`.
This rule will automatically pick the newest
profile if there are multiple profiles matching the given criteria.
By default this rule will search for a `{ios_extension}` file with the same name
as the rule itself, you can pass `profile_name` to use a different name, you
can pass `team_id` if you'd like to disambiguate between 2 Apple developer accounts
that have the same profile name. You may also pass `{macos_extension}` to
`profile_extension` to search for a macOS provisioning profile instead.
## Example
Expand Down Expand Up @@ -230,5 +252,8 @@ ios_application(
provisioning_profile = ":app_release_profile",
)
```
""",
""".format(
ios_extension = _IOS_PROFILE_EXTENSION,
macos_extension = _MACOS_PROFILE_EXTENSION,
),
)
23 changes: 14 additions & 9 deletions doc/rules-apple.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,23 @@ Builds and bundles an XCFramework for third-party distribution.
## local_provisioning_profile

<pre>
local_provisioning_profile(<a href="#local_provisioning_profile-name">name</a>, <a href="#local_provisioning_profile-profile_name">profile_name</a>, <a href="#local_provisioning_profile-team_id">team_id</a>)
local_provisioning_profile(<a href="#local_provisioning_profile-name">name</a>, <a href="#local_provisioning_profile-profile_extension">profile_extension</a>, <a href="#local_provisioning_profile-profile_name">profile_name</a>, <a href="#local_provisioning_profile-team_id">team_id</a>)
</pre>

This rule declares a bazel target that you can pass to the
'provisioning_profile' attribute of rules that require it. It discovers a
`provisioning_profile` attribute of rules that support it. It discovers a
provisioning profile for the given attributes either on the user's local
machine, or with the optional 'fallback_profiles' passed to
'provisioning_profile_repository'. This will automatically pick the newest
profile if there are multiple profiles matching the given criteria. By default
this rule will search for a profile with the same name as the rule itself, you
can pass profile_name to use a different name, and you can pass team_id if
you'd like to disambiguate between 2 Apple developer accounts that have the
same profile name.
machine, or with the optional `fallback_profiles` passed to
`provisioning_profile_repository`.

This rule will automatically pick the newest
profile if there are multiple profiles matching the given criteria.

By default this rule will search for a `.mobileprovision` file with the same name
as the rule itself, you can pass `profile_name` to use a different name, you
can pass `team_id` if you'd like to disambiguate between 2 Apple developer accounts
that have the same profile name. You may also pass `.provisionprofile` to
`profile_extension` to search for a macOS provisioning profile instead.

## Example

Expand Down Expand Up @@ -368,6 +372,7 @@ ios_application(
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="local_provisioning_profile-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="local_provisioning_profile-profile_extension"></a>profile_extension | The extension for the provisioning profile which may differ by platform. | String | optional | `".mobileprovision"` |
| <a id="local_provisioning_profile-profile_name"></a>profile_name | Name of the profile to use, if it's not provided the name of the rule is used | String | optional | `""` |
| <a id="local_provisioning_profile-team_id"></a>team_id | Team ID of the profile to find. This is useful for disambiguating between multiple profiles with the same name on different developer accounts. | String | optional | `""` |

Expand Down

0 comments on commit d7c7f86

Please sign in to comment.