-
Notifications
You must be signed in to change notification settings - Fork 319
Add support for Apple .doccarchive #2007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brentleyjones
merged 1 commit into
bazelbuild:master
from
luispadron:lpadron/add-bazel-docc-support
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Copyright 2023 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. | ||
|
|
||
| """Defines rules for building Apple DocC targets.""" | ||
|
|
||
| load( | ||
| "@build_bazel_rules_apple//apple/internal:docc.bzl", | ||
| _docc_archive = "docc_archive", | ||
| ) | ||
|
|
||
| docc_archive = _docc_archive |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # Copyright 2023 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. | ||
|
|
||
| """Defines aspects for collecting information required to build .docc and .doccarchive files.""" | ||
|
|
||
| load( | ||
| "@build_bazel_rules_swift//swift:swift.bzl", | ||
| "SwiftInfo", | ||
| ) | ||
| load( | ||
| "@build_bazel_rules_apple//apple:providers.bzl", | ||
| "DocCBundleInfo", | ||
| "DocCSymbolGraphsInfo", | ||
| ) | ||
|
|
||
| def _swift_symbol_graph(swift_info): | ||
| """Returns the symbol graph from a SwiftInfo provider or fails if it doesn't exist.""" | ||
| direct_modules = swift_info.direct_modules | ||
| if len(direct_modules) != 1: | ||
| return None | ||
| module = direct_modules[0] | ||
| if not module.swift: | ||
| return None | ||
| swift_module = module.swift | ||
| if not swift_module.symbol_graph: | ||
| return None | ||
| return swift_module.symbol_graph | ||
|
|
||
| def _first_docc_bundle(target, ctx): | ||
| """Returns the first .docc bundle for the target or its deps by looking in it's data.""" | ||
| docc_bundles = [] | ||
|
|
||
| # Find the path to the .docc directory if it exists. | ||
| for data_target in ctx.rule.attr.data: | ||
| for file in data_target.files.to_list(): | ||
| if file.extension == "docc": | ||
| docc_bundles.append(file) | ||
|
|
||
| if len(docc_bundles) > 1: | ||
| fail("Expected target %s to have at most one .docc bundle in its data" % target.label) | ||
|
|
||
| return docc_bundles[0] if docc_bundles else None | ||
|
|
||
| def _docc_symbol_graphs_aspect_impl(target, ctx): | ||
| """Creates a DocCSymbolGraphsInfo provider for targets which have a SwiftInfo provider (or which bundle a target that does).""" | ||
|
|
||
| symbol_graphs = [] | ||
|
|
||
| if SwiftInfo in target: | ||
| symbol_graphs.append(_swift_symbol_graph(target[SwiftInfo])) | ||
| elif hasattr(ctx.rule.attr, "deps"): | ||
| for dep in ctx.rule.attr.deps: | ||
| if SwiftInfo in dep: | ||
| symbol_graphs.append(_swift_symbol_graph(dep[SwiftInfo])) | ||
|
|
||
| # Filter out None | ||
| symbol_graphs = [symbol_graph for symbol_graph in symbol_graphs if symbol_graph] | ||
|
|
||
| if not symbol_graphs: | ||
| return [] | ||
|
|
||
| return [DocCSymbolGraphsInfo(symbol_graphs = symbol_graphs)] | ||
|
|
||
| def _docc_bundle_info_aspect_impl(target, ctx): | ||
| """Creates a DocCBundleInfo provider for targets which have a .docc bundle (or which bundle a target that does)""" | ||
|
|
||
| if hasattr(ctx.rule.attr, "data"): | ||
| first_docc_bundle = _first_docc_bundle(target, ctx) | ||
| if first_docc_bundle: | ||
| return [DocCBundleInfo(bundle = first_docc_bundle)] | ||
| elif hasattr(ctx.rule.attr, "deps"): | ||
| # If this target has "deps", try to find a DocCBundleInfo provider in its deps. | ||
| for dep in ctx.rule.attr.deps: | ||
| if DocCBundleInfo in dep: | ||
| return dep[DocCBundleInfo] | ||
|
|
||
| return [] | ||
|
|
||
| docc_bundle_info_aspect = aspect( | ||
| implementation = _docc_bundle_info_aspect_impl, | ||
| doc = """ | ||
| Creates or collects the DocCBundleInfo provider for a target or its deps. | ||
|
|
||
| This aspect works with targets that have a .docc bundle in their data, or which bundle a target that does. | ||
| """, | ||
| attr_aspects = ["data", "deps"], | ||
| ) | ||
|
|
||
| docc_symbol_graphs_aspect = aspect( | ||
| implementation = _docc_symbol_graphs_aspect_impl, | ||
| doc = """ | ||
| Creates or collects the DocCSymbolGraphsInfo provider for a target or its deps. | ||
|
|
||
| This aspect works with targets that have a SwiftInfo provider, or which bundle a target that does. | ||
| """, | ||
| attr_aspects = ["deps"], | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if need
private_depshere too