Skip to content

Commit a38b66e

Browse files
committed
build: avoid file collisions in docs-content (#18691)
Currently we always move guides, overviews, example files into the `docs-content` by their basename. This means that no guides, overviews, example files with the same name can exist. The last one being processed by Bazel overwrites the previous ones. This can be currently observed in the docs where the custom form-field control example incorrectly displays the MDC-based form-field custom control example. Ultimately breaking StackBlitz. For example: https://material.angular.io/guide/creating-a-custom-form-field-control. Click on the first example, and open it on StackBlitz. We can fix this by preserving the directories where the guides, overviews and example files have been copied from. This also allows us to have multiple overviews in a package without the risk of collisions. Note: Needs an corresponding change in the material.angular.io repo.
1 parent f87195b commit a38b66e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

tools/dgeni/index.bzl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
"""
22
Implementation of the "_dgeni_api_docs" rule. The implementation runs Dgeni with the
3-
specified entry points and outputs the API docs into a package relative directory.
3+
specified entry points and outputs the API docs as `DefaultInfo` declared output files.
44
"""
55

66
def _dgeni_api_docs(ctx):
77
input_files = ctx.files.srcs
88
args = ctx.actions.args()
99
expected_outputs = []
10-
11-
output_dir_name = ctx.attr.name
12-
output_dir_path = "%s/%s/%s" % (ctx.bin_dir.path, ctx.label.package, output_dir_name)
10+
output_dir_path = "%s/%s" % (ctx.bin_dir.path, ctx.label.package)
1311

1412
# Do nothing if there are no input files. Bazel will throw if we schedule an action
1513
# that returns no outputs.
@@ -41,17 +39,15 @@ def _dgeni_api_docs(ctx):
4139
# Declare the output for the current entry-point. The output file will always follow the
4240
# same format: "{output_folder}/{package_name}-{entry_point_name}.html"
4341
# (e.g. "api-docs/material-slider-testing.html")
44-
ctx.actions.declare_file("%s/%s-%s.html" %
45-
(output_dir_name, package_name, entry_point.replace("/", "-"))),
42+
ctx.actions.declare_file("%s-%s.html" %
43+
(package_name, entry_point.replace("/", "-"))),
4644
]
4745

4846
# Small workaround that ensures that the "ripple" API doc is properly exposed as an output
4947
# of the packaging rule. Technically Dgeni should not output the "ripple" directory as
5048
# its own entry-point. TODO(devversion): Support sub API docs for entry-points
5149
if package_name == "material":
52-
expected_outputs += [
53-
ctx.actions.declare_file("%s/%s-%s.html" % (output_dir_name, package_name, "ripple")),
54-
]
50+
expected_outputs += [ctx.actions.declare_file("%s-%s.html" % (package_name, "ripple"))]
5551

5652
# Run the Dgeni bazel executable which builds the documentation output based on the
5753
# configured rule attributes.

tools/package-docs-content/index.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ def _package_docs_content(ctx):
2525
# output file which will be added to the executable arguments.
2626
for input_target, section_name in ctx.attr.srcs.items():
2727
section_files = input_target.files.to_list()
28+
base_dir = "%s" % (input_target.label.package)
2829

2930
for input_file in section_files:
31+
# Creates a relative path from the input file. We don't want to include the full
32+
# path in docs content. e.g. `docs-content/overviews/cdk/src/cdk/a11y/a11y.html`.
33+
# Instead, we want the path to be: `docs-content/overviews/cdk/a11y/a11y.html`.
34+
section_relative_file_name = input_file.short_path[len(base_dir):]
35+
3036
# For each input file, we want to create a copy that is stored in the output directory
3137
# within its specified section. e.g. "pkg_bin/docs-content/guides/getting-started.html"
3238
output_file = ctx.actions.declare_file(
33-
"%s/%s/%s" % (output_dir, section_name, input_file.basename),
39+
"%s/%s/%s" % (output_dir, section_name, section_relative_file_name),
3440
)
3541

3642
# Add the output file to the expected outputs so that Bazel throws an error if the file

0 commit comments

Comments
 (0)