Paul Gschwendtner fd3cfbb678 build: create bazel marco to test for circular dependencies (#34774)
Creates a Bazel macro that can be used to test packages for
circular dependencies. We face one limitation with Bazel:

 * Built packages use module imports, and not relative source file
 paths. This means we need custom resolution.

Fortunately, tools like `madge` support custom resolution.

Also removes the outdated `check-cycles` gulp task that
didn't catch circular dependencies. It seems like the test
became broken when we switched the packages-dist output to Bazel. It
breaks because the Bazel output doesn't use relative paths, but uses
the module imports. This will be handled in the new Bazel macro/rule.

PR Close #34774
2020-01-23 11:36:40 -08:00

38 lines
1.6 KiB
Python

# Copyright Google Inc. All Rights Reserved.
#
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE file at https://angular.io/license
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
MADGE_CONFIG_LABEL = "//tools/circular_dependency_test:madge-resolve.config.js"
"""
Creates a test target that ensures that no circular dependencies can
be found in the given entry point file.
"""
def circular_dependency_test(name, deps, entry_point, **kwargs):
nodejs_test(
name = name,
data = ["@npm//madge", MADGE_CONFIG_LABEL] + deps,
entry_point = "@npm//:node_modules/madge/bin/cli.js",
templated_args = [
"--circular",
"--no-spinner",
# NOTE: We cannot use `$(location)` to resolve labels. This is because `ts_library`
# does not pre-declare outputs in the rule. Hence, the outputs cannot be referenced
# through labels (i.e. `//packages/core:index.js`). Read more here:
# https://docs.bazel.build/versions/2.0.0/skylark/rules.html#outputs
# TODO: revisit once https://github.com/bazelbuild/rules_nodejs/issues/1563 is solved.
"$(rlocation %s)" % entry_point,
# Madge supports custom module resolution, but expects a configuration file
# similar to a Webpack configuration file setting the `resolve` option.
"--webpack-config",
"$(rlocation $(location %s))" % MADGE_CONFIG_LABEL,
],
testonly = 1,
expected_exit_code = 0,
**kwargs
)