feat(bazel): allow explicit specification of factories (#22003)

The `ng_module` rule now has a factories attribute that
allows explicit specification of which files are expected
to generate factories. This allows avoiding generating
empty factory files (such as `.ngfactory.js`) begin
generated which might cause down-stream tools issues if
they have a limit on the number of files that can be
processed in a single bazel action.

PR Close #22003
This commit is contained in:
Chuck Jazdzewski 2018-02-02 15:13:31 -08:00 committed by Miško Hevery
parent b37cee36f9
commit e442881ead
1 changed files with 24 additions and 7 deletions

View File

@ -14,6 +14,14 @@ load(":rules_typescript.bzl",
"ts_providers_dict_to_struct", "ts_providers_dict_to_struct",
) )
def _basename_of(ctx, file):
ext_len = len(".ts")
if file.short_path.endswith(".ng.html"):
ext_len = len(".ng.html")
elif file.short_path.endswith(".html"):
ext_len = len(".html")
return file.short_path[len(ctx.label.package) + 1:-ext_len]
# Calculate the expected output of the template compiler for every source in # Calculate the expected output of the template compiler for every source in
# in the library. Most of these will be produced as empty files but it is # in the library. Most of these will be produced as empty files but it is
# unknown, without parsing, which will be empty. # unknown, without parsing, which will be empty.
@ -23,16 +31,21 @@ def _expected_outs(ctx):
declaration_files = [] declaration_files = []
summary_files = [] summary_files = []
factory_basename_set = depset([_basename_of(ctx, src) for src in ctx.files.factories])
for src in ctx.files.srcs + ctx.files.assets: for src in ctx.files.srcs + ctx.files.assets:
if src.short_path.endswith(".ts") and not src.short_path.endswith(".d.ts"): if src.short_path.endswith(".ts") and not src.short_path.endswith(".d.ts"):
basename = src.short_path[len(ctx.label.package) + 1:-len(".ts")] basename = src.short_path[len(ctx.label.package) + 1:-len(".ts")]
devmode_js = [ if len(factory_basename_set) == 0 or basename in factory_basename_set:
".ngfactory.js", devmode_js = [
".ngsummary.js", ".ngfactory.js",
".js", ".ngsummary.js",
] ".js",
summaries = [".ngsummary.json"] ]
summaries = [".ngsummary.json"]
else:
devmode_js = [".js"]
summaries = []
elif src.short_path.endswith(".css"): elif src.short_path.endswith(".css"):
basename = src.short_path[len(ctx.label.package) + 1:-len(".css")] basename = src.short_path[len(ctx.label.package) + 1:-len(".css")]
devmode_js = [ devmode_js = [
@ -265,6 +278,10 @@ NG_MODULE_ATTRIBUTES = {
".html", ".html",
]), ]),
"factories": attr.label_list(
allow_files = [".ts", ".html"],
mandatory = False),
"type_check": attr.bool(default = True), "type_check": attr.bool(default = True),
"no_i18n": attr.bool(default = False), "no_i18n": attr.bool(default = False),