-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: run unit tests with partial compilation and Angular linker (#2…
…2979) Instead of running e2e tests against a linker-processed application, we run all of our unit tests using partial compilation and the Angular linker. This ensures we test our components more throroughly against the Angular linker & partial compilation. This also solves our CI flakiness issue due to the large amount of webdriver e2e tests running concurrently on CI (especially since all e2e tests ran on snapshot builds).
- Loading branch information
1 parent
81cd26b
commit 77e5c21
Showing
10 changed files
with
297 additions
and
143 deletions.
There are no files selected for viewing
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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 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,30 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") | ||
load("//tools:defaults.bzl", "ts_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ts_library( | ||
name = "sources", | ||
srcs = glob(["**/*.ts"]), | ||
deps = [ | ||
"@npm//@angular/compiler-cli", | ||
"@npm//@babel/core", | ||
"@npm//@babel/traverse", | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
# Exposes the `linker-process` tool as executable so that it can be used as | ||
# build tool (for `ctx.actions.run`) within the `linker_process` custom Bazel rule. | ||
nodejs_binary( | ||
name = "linker-process", | ||
data = [ | ||
":sources", | ||
], | ||
entry_point = ":linker-process.ts", | ||
templated_args = [ | ||
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver | ||
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324 | ||
"--bazel_patch_module_resolver", | ||
], | ||
) |
This file contains 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,100 @@ | ||
""" | ||
Exposes a custom Bazel rule for processing sources, which are extracted from Bazel | ||
targets, with the Angular linker plugin. | ||
""" | ||
|
||
load("@build_bazel_rules_nodejs//:providers.bzl", "JSModuleInfo", "JSNamedModuleInfo") | ||
|
||
""" | ||
Gets the Bazel manifest path for a given file. Manifest paths are used within Bazel runfile | ||
manifests and are formatted as followed: `<workspace_name>/<workspace_relative_file_path>` | ||
""" | ||
|
||
def _to_manifest_path(ctx, file): | ||
# If a file resides outside of the current workspace, we omit the leading `../` | ||
# segment as the rest will contain the workspace name. e.g. `../npm/node_modules/<..>`. | ||
if file.short_path.startswith("../"): | ||
return file.short_path[3:] | ||
else: | ||
return ctx.workspace_name + "/" + file.short_path | ||
|
||
"""Extracts all source files from the specified list of dependencies.""" | ||
|
||
def _extract_source_files(deps): | ||
depsets = [] | ||
for dep in deps: | ||
if JSNamedModuleInfo in dep: | ||
depsets.append(dep[JSNamedModuleInfo].sources) | ||
elif JSModuleInfo in dep: | ||
depsets.append(dep[JSModuleInfo].sources) | ||
elif hasattr(dep, "files"): | ||
depsets.append(dep.files) | ||
return depset(transitive = depsets) | ||
|
||
def _linker_process(ctx): | ||
args = ctx.actions.args() | ||
sources = _extract_source_files(ctx.attr.srcs) | ||
tmp_dir_name = ctx.label.name | ||
|
||
# The output directory manifest path. e.g `angular_material/src/cdk/a11y/linker_processed`. | ||
output_dir_manifest_path = "%s/%s/%s" % (ctx.workspace_name, ctx.label.package, tmp_dir_name) | ||
|
||
# The output directory exec path. e.g `bazel_out/<..>/src/cdk/a11y/linker_processed`. | ||
output_dir_exec_path = "%s/%s/%s" % (ctx.bin_dir.path, ctx.label.package, tmp_dir_name) | ||
|
||
# Given the sources being transformed and written to a new location, the AMD module names | ||
# need to be rewritten. This file maps AMD modules as per the new location to the AMD modules | ||
# as they appear in the sources. i.e. we generate AMD module aliases. | ||
amd_module_mapping_file = ctx.actions.declare_file("%s/_module_mappings.js" % tmp_dir_name) | ||
|
||
args.add(output_dir_exec_path) | ||
args.add(output_dir_manifest_path) | ||
args.add(amd_module_mapping_file.path) | ||
|
||
outputs = [amd_module_mapping_file] | ||
|
||
# Iterate through the determined sources and pass them to the tool as argument. | ||
for input_file in sources.to_list(): | ||
output_pkg_path = _to_manifest_path(ctx, input_file) | ||
args.add("%s:%s" % (input_file.path, output_pkg_path)) | ||
outputs.append(ctx.actions.declare_file("%s/%s" % (tmp_dir_name, output_pkg_path))) | ||
|
||
# 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", use_always = True) | ||
|
||
ctx.actions.run( | ||
inputs = sources, | ||
outputs = outputs, | ||
executable = ctx.executable._linker_process_tool, | ||
arguments = [args], | ||
progress_message = "NgLinkerProcess", | ||
) | ||
|
||
outputs_depset = depset(outputs) | ||
|
||
return [ | ||
DefaultInfo(files = outputs_depset), | ||
] | ||
|
||
""" | ||
Rule definition for the "linker_process" rule that can process a list of targets | ||
with the Angular linker. The processed files can be retrieved through the default | ||
files provider, or through the `JSNamedModuleInfo` provider. | ||
""" | ||
linker_process = rule( | ||
implementation = _linker_process, | ||
attrs = { | ||
"srcs": attr.label_list( | ||
allow_files = True, | ||
doc = """List of sources that should be processed with the Angular linker.""", | ||
), | ||
"_linker_process_tool": attr.label( | ||
default = Label("//tools/linker-process"), | ||
executable = True, | ||
cfg = "host", | ||
), | ||
}, | ||
) |
Oops, something went wrong.