-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(components-example): extract regions from component example source files #19376
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
Changes from all commits
043174a
0406774
bd7a1a3
d183339
c9c1217
451d7be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,25 @@ | |
""" | ||
|
||
def _package_docs_content(ctx): | ||
# Directory that will contain all grouped input files. This directory will be created | ||
# relatively to the current target package. (e.g. "bin/src/components-examples/docs-content") | ||
output_dir = ctx.attr.name | ||
|
||
# Arguments that will be passed to the packager executable. | ||
args = ctx.actions.args() | ||
|
||
# List of outputs that should be generated by the packager action. Bazel will automatically | ||
# throw an error if any output has not been generated properly. | ||
expected_outputs = [] | ||
# Directory that will contain all grouped input files. This directory will be | ||
# created relatively to the current target package. For example: | ||
# "bin/src/components-examples/docs-content/docs-content". The reason we need to | ||
# repeat `docs-content` is that the ng_package rule does not properly handle tree | ||
# artifacts in data. Instead, we create a tree artifact that can be put into nested_packages. | ||
# Nested packages do not preserve the tree artifact name (i.e. the directory name), | ||
# so all contents of the docs-content would be put directly into the @angular/components-examples package. | ||
# To avoid that, we create another folder like docs-content in the tree artifact that | ||
# is preserved as content of the tree artifact. | ||
output_dir = ctx.actions.declare_directory("%s/%s" % (ctx.attr.name, ctx.attr.name)) | ||
|
||
# Support passing arguments through a parameter file. This is necessary because on Windows | ||
# there is an argument limit and we need to handle a large amount of input files. Bazel | ||
# switches between parameter file and normal argument passing based on the operating system. | ||
# Read more here: https://docs.bazel.build/versions/master/skylark/lib/Args.html#use_param_file | ||
args.use_param_file(param_file_arg = "--param-file=%s") | ||
args.use_param_file(param_file_arg = "--param-file=%s", use_always = True) | ||
|
||
# Walk through each defined input target and the associated section and compute the | ||
# output file which will be added to the executable arguments. | ||
|
@@ -29,25 +32,25 @@ def _package_docs_content(ctx): | |
|
||
for input_file in section_files: | ||
# Creates a relative path from the input file. We don't want to include the full | ||
# path in docs content. e.g. `docs-content/overviews/cdk/src/cdk/a11y/a11y.html`. | ||
# Instead, we want the path to be: `docs-content/overviews/cdk/a11y/a11y.html`. | ||
section_relative_file_name = input_file.short_path[len(base_dir):] | ||
|
||
# For each input file, we want to create a copy that is stored in the output directory | ||
# within its specified section. e.g. "pkg_bin/docs-content/guides/getting-started.html" | ||
output_file = ctx.actions.declare_file( | ||
"%s/%s/%s" % (output_dir, section_name, section_relative_file_name), | ||
) | ||
# path in docs content. e.g. `/docs-content/overviews/cdk/src/cdk/a11y/a11y.html`. Instead, | ||
# we want the path to be: `/docs-content/overviews/cdk/a11y/a11y.html`. | ||
section_relative_file_name = input_file.short_path[len(base_dir) + 1:] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, can you explain what this change was for? The comment isn't changed so I'm curious what this was about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, we declared outputs on a per-file basis in Bazel as we knew what outputs to expect from a set of input files. This does no longer work, now that input file could also be a Bazel tree artifact. For those we cannot determine outputs at Bazel analysis time. We fix this (in a Bazel idiomatic way), by not declaring outputs per-file, but rather by creating a single tree artifact output (see |
||
|
||
# Add the output file to the expected outputs so that Bazel throws an error if the file | ||
# hasn't been generated properly. | ||
expected_outputs += [output_file] | ||
# The section name can be empty. This is reasonable when tree artifacts are copied | ||
# over to the resulting package so that only their contents are transferred. | ||
# TODO(devversion): Revisit if this can be improved so that the section name | ||
# is respected. `args.add_all` can unfold tree artifact contents. | ||
# https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/skylark/Args.java;l=381-382;drc=9a6997d595fbf3447e911346034edfbde7d8b57e?q=addAll&ss=bazel | ||
if section_name: | ||
expected_out_path = "%s/%s/%s" % (output_dir.path, section_name, section_relative_file_name) | ||
else: | ||
expected_out_path = "%s/%s" % (output_dir.path, section_relative_file_name) | ||
|
||
# Pass the input file path and the output file path to the packager executable. We need | ||
# to do this for each file because we cannot determine the general path to the output | ||
# directory in a reliable way because Bazel targets cannot just "declare" a directory. | ||
# See: https://docs.bazel.build/versions/master/skylark/lib/actions.html | ||
args.add("%s,%s" % (input_file.path, output_file.path)) | ||
args.add("%s,%s" % (input_file.path, expected_out_path)) | ||
|
||
# Do nothing if there are no input files. Bazel will throw if we schedule an action | ||
# that returns no outputs. | ||
|
@@ -59,12 +62,12 @@ def _package_docs_content(ctx): | |
ctx.actions.run( | ||
inputs = ctx.files.srcs, | ||
executable = ctx.executable._packager, | ||
outputs = expected_outputs, | ||
outputs = [output_dir], | ||
arguments = [args], | ||
progress_message = "PackageDocsContent", | ||
) | ||
|
||
return DefaultInfo(files = depset(expected_outputs)) | ||
return DefaultInfo(files = depset([output_dir])) | ||
|
||
""" | ||
Rule definition for the "package_docs_content" rule that can accept arbritary source files | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("//tools:defaults.bzl", "ts_library") | ||
annieyw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ts_library( | ||
name = "region-parser", | ||
srcs = glob(["**/*.ts"]), | ||
tsconfig = ":tsconfig.json", | ||
deps = [ | ||
"@npm//@types/node", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The implementation of `region-parser` is copied from the `angular/angular` repo. | ||
It has been adapted from JavaScript to Typescript along with a few minor changes. | ||
This is part of an ongoing effort to share more components between [angular.io] and [material.angular.io]. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// These kind of comments are used CSS and other languages that do not support inline comments | ||
export const blockC = { | ||
regionStartMatcher: /^\s*\/\*\s*#docregion\s*(.*)\s*\*\/\s*$/, | ||
regionEndMatcher: /^\s*\/\*\s*#enddocregion\s*(.*)\s*\*\/\s*$/, | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.