fix(bazel): ng_module should not emit shim files under bazel and Ivy (#33765)
Under bazel and Ivy we don't need the shim files to be emmited by default. We still need to the shims for blaze however because google3 code imports them. This improves build latency by 1-2 seconds per ng_module target. PR Close #33765
This commit is contained in:
parent
804933284b
commit
955423c79b
|
@ -13,6 +13,7 @@ exports_files(["tsconfig.json"])
|
|||
ng_module(
|
||||
name = "src",
|
||||
srcs = glob(["*.ts"]),
|
||||
generate_ve_shims = True,
|
||||
deps = [
|
||||
"//src/hello-world",
|
||||
"@npm//@angular/common",
|
||||
|
|
|
@ -17,6 +17,7 @@ ng_module(
|
|||
exclude = ["*.spec.ts"],
|
||||
),
|
||||
assets = [":hello-world-styles"],
|
||||
generate_ve_shims = True,
|
||||
deps = [
|
||||
"@npm//@angular/core",
|
||||
"@npm//@types",
|
||||
|
|
|
@ -10,6 +10,7 @@ ng_module(
|
|||
["**/*.ts"],
|
||||
exclude = ["**/*.spec.ts"],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
deps = [
|
||||
"//packages:types",
|
||||
"//packages/common",
|
||||
|
|
|
@ -10,6 +10,7 @@ ng_module(
|
|||
["**/*.ts"],
|
||||
exclude = ["**/*.spec.ts"],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
deps = [
|
||||
"//packages:types",
|
||||
"//packages/common",
|
||||
|
|
|
@ -9,6 +9,7 @@ package(default_visibility = ["//modules/benchmarks:__subpackages__"])
|
|||
ng_module(
|
||||
name = "ng2",
|
||||
srcs = glob(["*.ts"]),
|
||||
generate_ve_shims = True,
|
||||
# FIXME-IVY(FW-998): ExpressionTranslatorVisitor#visitWriteKeyExpr is not implemented.
|
||||
tags = ["fixme-ivy-aot"],
|
||||
tsconfig = "//modules/benchmarks:tsconfig-build.json",
|
||||
|
|
|
@ -10,6 +10,7 @@ package(default_visibility = ["//modules/benchmarks:__subpackages__"])
|
|||
ng_module(
|
||||
name = "ng2",
|
||||
srcs = glob(["*.ts"]),
|
||||
generate_ve_shims = True,
|
||||
tsconfig = "//modules/benchmarks:tsconfig-build.json",
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
|
|
|
@ -7,6 +7,7 @@ package(default_visibility = ["//modules/benchmarks:__subpackages__"])
|
|||
ng_module(
|
||||
name = "ng2_switch",
|
||||
srcs = glob(["*.ts"]),
|
||||
generate_ve_shims = True,
|
||||
tsconfig = "//modules/benchmarks:tsconfig-build.json",
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
|
|
|
@ -10,6 +10,7 @@ package(default_visibility = ["//modules/benchmarks:__subpackages__"])
|
|||
ng_module(
|
||||
name = "ng2",
|
||||
srcs = glob(["*.ts"]),
|
||||
generate_ve_shims = True,
|
||||
tsconfig = "//modules/benchmarks:tsconfig-build.json",
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
|
|
|
@ -7,6 +7,7 @@ package(default_visibility = ["//modules/benchmarks:__subpackages__"])
|
|||
ng_module(
|
||||
name = "ng2_switch",
|
||||
srcs = glob(["*.ts"]),
|
||||
generate_ve_shims = True,
|
||||
tsconfig = "//modules/benchmarks:tsconfig-build.json",
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
|
|
|
@ -9,6 +9,7 @@ ng_module(
|
|||
["**/*.ts"],
|
||||
exclude = ["**/*.spec.ts"],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
deps = [
|
||||
"//packages:types",
|
||||
"//packages/common",
|
||||
|
|
|
@ -38,6 +38,7 @@ ng_module(
|
|||
"**/*.css",
|
||||
"**/*.html",
|
||||
]) + ([":styles"] if len(glob(["**/*.scss"])) else []),
|
||||
generate_ve_shims = True,
|
||||
deps = [
|
||||
"@npm//@angular/core",
|
||||
"@npm//@angular/platform-browser",
|
||||
|
|
|
@ -208,11 +208,14 @@ def _expected_outs(ctx):
|
|||
if short_path.endswith(".ts") and not short_path.endswith(".d.ts"):
|
||||
basename = short_path[len(package_prefix):-len(".ts")]
|
||||
if (len(factory_basename_set.to_list()) == 0 or basename in factory_basename_set.to_list()):
|
||||
devmode_js = [
|
||||
".ngfactory.js",
|
||||
".ngsummary.js",
|
||||
".js",
|
||||
]
|
||||
if _generate_ve_shims(ctx):
|
||||
devmode_js = [
|
||||
".ngfactory.js",
|
||||
".ngsummary.js",
|
||||
".js",
|
||||
]
|
||||
else:
|
||||
devmode_js = [".js"]
|
||||
|
||||
# Only ngc produces .json files, they're not needed in Ivy.
|
||||
if is_legacy_ngc:
|
||||
|
@ -293,7 +296,18 @@ def _expected_outs(ctx):
|
|||
i18n_messages = i18n_messages_files,
|
||||
)
|
||||
|
||||
# Determines if we need to generate View Engine shims (.ngfactory and .ngsummary files)
|
||||
def _generate_ve_shims(ctx):
|
||||
# we are checking the workspace name here, because otherwise this would be a breaking change
|
||||
# (the shims used to be on by default)
|
||||
# we can remove this check once angular/components and angular/angular-cli repos no longer depend
|
||||
# on the presence of shims, or if they explicitly opt-in to their generation via ng_modules' generate_ve_shims attr
|
||||
return _is_bazel() and _is_view_engine_enabled(ctx) or (
|
||||
getattr(ctx.attr, "generate_ve_shims", False) == True or ctx.workspace_name != "angular"
|
||||
)
|
||||
|
||||
def _ngc_tsconfig(ctx, files, srcs, **kwargs):
|
||||
generate_ve_shims = _generate_ve_shims(ctx)
|
||||
outs = _expected_outs(ctx)
|
||||
is_legacy_ngc = _is_view_engine_enabled(ctx)
|
||||
if "devmode_manifest" in kwargs:
|
||||
|
@ -305,8 +319,8 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
|
|||
"enableResourceInlining": ctx.attr.inline_resources,
|
||||
"generateCodeForLibraries": False,
|
||||
"allowEmptyCodegenFiles": True,
|
||||
"generateNgFactoryShims": True,
|
||||
"generateNgSummaryShims": True,
|
||||
"generateNgFactoryShims": True if generate_ve_shims else False,
|
||||
"generateNgSummaryShims": True if generate_ve_shims else False,
|
||||
# Summaries are only enabled if Angular outputs are to be produced.
|
||||
"enableSummariesForJit": is_legacy_ngc,
|
||||
"enableIvy": _is_ivy_enabled(ctx),
|
||||
|
@ -771,6 +785,8 @@ NG_MODULE_RULE_ATTRS = dict(dict(COMMON_ATTRIBUTES, **NG_MODULE_ATTRIBUTES), **{
|
|||
executable = True,
|
||||
cfg = "host",
|
||||
),
|
||||
# Should the rule generate ngfactory and ngsummary shim files?
|
||||
"generate_ve_shims": attr.bool(default = False),
|
||||
})
|
||||
|
||||
ng_module = rule(
|
||||
|
|
|
@ -10,6 +10,7 @@ ng_module(
|
|||
"src/**/*.ts",
|
||||
],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
module_name = "app_built",
|
||||
deps = [
|
||||
"//packages/compiler-cli/integrationtest/bazel/injectable_def/lib2",
|
||||
|
|
|
@ -9,6 +9,7 @@ ng_module(
|
|||
["**/*.ts"],
|
||||
exclude = ["**/*_spec.ts"],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
deps = [
|
||||
|
|
|
@ -12,6 +12,7 @@ ng_module(
|
|||
"**/*_howto.ts",
|
||||
],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
deps = [
|
||||
|
|
|
@ -9,6 +9,7 @@ ng_module(
|
|||
["**/*.ts"],
|
||||
exclude = ["**/*_spec.ts"],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
deps = [
|
||||
|
|
|
@ -8,6 +8,7 @@ ng_module(
|
|||
srcs = glob(
|
||||
["**/*.ts"],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
deps = [
|
||||
|
|
|
@ -9,6 +9,7 @@ ng_module(
|
|||
["**/*.ts"],
|
||||
exclude = ["**/*_spec.ts"],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
deps = [
|
||||
|
|
|
@ -9,6 +9,7 @@ ng_module(
|
|||
["**/*.ts"],
|
||||
exclude = ["**/*_spec.ts"],
|
||||
),
|
||||
generate_ve_shims = True,
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
deps = [
|
||||
|
|
|
@ -12,6 +12,7 @@ def create_upgrade_example_targets(name, srcs, e2e_srcs, entry_module, assets =
|
|||
ng_module(
|
||||
name = "%s_sources" % name,
|
||||
srcs = srcs,
|
||||
generate_ve_shims = True,
|
||||
# TODO: FW-1004 Type checking is currently not complete.
|
||||
type_check = False,
|
||||
deps = [
|
||||
|
|
|
@ -4,6 +4,7 @@ ng_module(
|
|||
name = "aot_routing_module",
|
||||
testonly = True,
|
||||
srcs = ["aot_router_module.ts"],
|
||||
generate_ve_shims = True,
|
||||
deps = [
|
||||
"//packages/core",
|
||||
"//packages/router",
|
||||
|
|
Loading…
Reference in New Issue