Skip to content

build: flatten golden files directory #22967

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
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tools/public_api_guard/generate-guard-tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ load("@npm//ts-api-guardian:index.bzl", "ts_api_guardian_test")
against the associated source entry point.
"""

def generate_test_targets(golden_files):
for golden_file in golden_files:
def generate_test_targets(targets):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was split between doing this here or when generating the target names in tools/public_api_guard/BUILD.bazel. I decided to do it here, because even though it would be cleaner when generating the target names, I think that the slashes in the target name make sense, they just produce a weird directory structure when the golden is generated.

for target_name in targets:
# Splits the path that is relative to the current directory into the package name and
# entry point tail path. The package name is always the first path segment (e.g. "cdk/")
[package_name, entry_point_tail] = golden_file.split("/", 1)
[package_name, entry_point_tail] = target_name.split("/", 1)

# Name of the entry-point (e.g. "a11y", "drag-drop", "platform")
entry_point = entry_point_tail[:-len(".d.ts")]

# Name of the .d.ts file that will be produced. We replace the slashes in the entry
# point name with underscores so that we can get a flat directory of golden files.
golden_file = "%s/%s" % (package_name, entry_point_tail.replace("/", "-"))

# Construct the path to the given entry-point. Note that we also need to find a way to
# allow guards for the primary entry-point of a package. e.g. "//src/cdk:cdk" should be also
# validated. We achieve this by checking if the package_name is equal to the entry_point name.
Expand All @@ -24,7 +28,7 @@ def generate_test_targets(golden_files):

# Create the test rule that compares the build output with the golden file.
ts_api_guardian_test(
name = "%s_api" % golden_file,
name = "%s_api" % target_name,
actual = "angular_material/src/%s/index.d.ts" % entry_point_path,
data = [golden_file] + [
"//src/%s" % (entry_point_path),
Expand Down