build: create bazel define flag, `angular_ivy_enabled`, to build using ivy (#33975)

This introduces a second possible define flag for informing bazel to build with ivy, but
does not remove the old `compile=aot` flag for configuration.

This is the first step in migrating away from using the `compile=aot` define flag.

PR Close #33975
This commit is contained in:
Joey Perrott 2019-11-21 13:39:30 -08:00 committed by Matias Niemelä
parent 3d69693692
commit 7d579b913c
1 changed files with 36 additions and 36 deletions

View File

@ -54,6 +54,31 @@ def compile_strategy(ctx):
return strategy return strategy
def _is_ivy_enabled(ctx):
"""Determine if the ivy compiler should be used to by the ng_module.
Args:
ctx: skylark rule execution context
Returns:
Boolean, Whether the ivy compiler should be used.
"""
# TODO(josephperrott): Remove configuration via compile=aot define flag.
if ctx.var.get("compile", None) == "aot":
return True
if ctx.var.get("angular_ivy_enabled", None) == "True":
return True
# Enable Angular targets extracted by Kythe Angular indexer to be compiled with the Ivy compiler architecture.
# TODO(ayazhafiz): remove once Ivy has landed as the default in g3.
if ctx.var.get("GROK_ELLIPSIS_BUILD", None) != None:
return True
# Return false to default to ViewEngine compiler
return False
def _compiler_name(ctx): def _compiler_name(ctx):
"""Selects a user-visible name depending on the current compilation strategy. """Selects a user-visible name depending on the current compilation strategy.
@ -61,36 +86,12 @@ def _compiler_name(ctx):
ctx: skylark rule execution context ctx: skylark rule execution context
Returns: Returns:
the name of the current compiler to be displayed in build output The name of the current compiler to be displayed in build output
""" """
strategy = compile_strategy(ctx) return "ngtsc" if _is_ivy_enabled(ctx) else "ngc"
if strategy == "legacy":
return "ngc"
elif strategy == "aot":
return "ngtsc"
else:
fail("unreachable")
def _enable_ivy_value(ctx): def _is_view_engine_enabled(ctx):
"""Determines the value of the enableIvy option in the generated tsconfig.
Args:
ctx: skylark rule execution context
Returns:
the value of enableIvy that needs to be set in angularCompilerOptions in the generated tsconfig
"""
strategy = compile_strategy(ctx)
if strategy == "legacy":
return False
elif strategy == "aot":
return True
else:
fail("unreachable")
def _is_legacy_ngc(ctx):
"""Determines whether Angular outputs will be produced by the current compilation strategy. """Determines whether Angular outputs will be produced by the current compilation strategy.
Args: Args:
@ -101,8 +102,7 @@ def _is_legacy_ngc(ctx):
factory files), false otherwise factory files), false otherwise
""" """
strategy = compile_strategy(ctx) return not _is_ivy_enabled(ctx)
return strategy == "legacy"
def _basename_of(ctx, file): def _basename_of(ctx, file):
ext_len = len(".ts") ext_len = len(".ts")
@ -149,7 +149,7 @@ def _should_produce_dts_bundle(ctx):
# At the moment we cannot use this with ngtsc compiler since it emits # At the moment we cannot use this with ngtsc compiler since it emits
# import * as ___ from local modules which is not supported # import * as ___ from local modules which is not supported
# see: https://github.com/Microsoft/web-build-tools/issues/1029 # see: https://github.com/Microsoft/web-build-tools/issues/1029
return _is_legacy_ngc(ctx) and hasattr(ctx.attr, "bundle_dts") and ctx.attr.bundle_dts return _is_view_engine_enabled(ctx) and hasattr(ctx.attr, "bundle_dts") and ctx.attr.bundle_dts
def _should_produce_r3_symbols_bundle(ctx): def _should_produce_r3_symbols_bundle(ctx):
"""Should we produce r3_symbols bundle. """Should we produce r3_symbols bundle.
@ -168,7 +168,7 @@ def _should_produce_r3_symbols_bundle(ctx):
# because ngcc relies on having this file. # because ngcc relies on having this file.
# see: https://github.com/angular/angular/blob/84406e4d6d93b28b23efbb1701bc5ae1084da67b/packages/compiler-cli/src/ngcc/src/packages/entry_point_bundle.ts#L56 # see: https://github.com/angular/angular/blob/84406e4d6d93b28b23efbb1701bc5ae1084da67b/packages/compiler-cli/src/ngcc/src/packages/entry_point_bundle.ts#L56
# todo: alan-agius4: remove when ngcc doesn't need this anymore # todo: alan-agius4: remove when ngcc doesn't need this anymore
return _is_legacy_ngc(ctx) and ctx.attr.module_name == "@angular/core" return _is_view_engine_enabled(ctx) and ctx.attr.module_name == "@angular/core"
def _should_produce_flat_module_outs(ctx): def _should_produce_flat_module_outs(ctx):
"""Should we produce flat module outputs. """Should we produce flat module outputs.
@ -188,7 +188,7 @@ def _should_produce_flat_module_outs(ctx):
# 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.
def _expected_outs(ctx): def _expected_outs(ctx):
is_legacy_ngc = _is_legacy_ngc(ctx) is_legacy_ngc = _is_view_engine_enabled(ctx)
devmode_js_files = [] devmode_js_files = []
closure_js_files = [] closure_js_files = []
@ -295,7 +295,7 @@ def _expected_outs(ctx):
def _ngc_tsconfig(ctx, files, srcs, **kwargs): def _ngc_tsconfig(ctx, files, srcs, **kwargs):
outs = _expected_outs(ctx) outs = _expected_outs(ctx)
is_legacy_ngc = _is_legacy_ngc(ctx) is_legacy_ngc = _is_view_engine_enabled(ctx)
if "devmode_manifest" in kwargs: if "devmode_manifest" in kwargs:
expected_outs = outs.devmode_js + outs.declarations + outs.summaries + outs.metadata expected_outs = outs.devmode_js + outs.declarations + outs.summaries + outs.metadata
else: else:
@ -309,7 +309,7 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
"generateNgSummaryShims": True, "generateNgSummaryShims": True,
# Summaries are only enabled if Angular outputs are to be produced. # Summaries are only enabled if Angular outputs are to be produced.
"enableSummariesForJit": is_legacy_ngc, "enableSummariesForJit": is_legacy_ngc,
"enableIvy": _enable_ivy_value(ctx), "enableIvy": _is_ivy_enabled(ctx),
"fullTemplateTypeCheck": ctx.attr.type_check, "fullTemplateTypeCheck": ctx.attr.type_check,
# TODO(alxhub/arick): template type-checking for Ivy needs to be tested in g3 before it can # TODO(alxhub/arick): template type-checking for Ivy needs to be tested in g3 before it can
# be enabled here. # be enabled here.
@ -399,7 +399,7 @@ def ngc_compile_action(
the parameters of the compilation which will be used to replay the ngc action for i18N. the parameters of the compilation which will be used to replay the ngc action for i18N.
""" """
is_legacy_ngc = _is_legacy_ngc(ctx) is_legacy_ngc = _is_view_engine_enabled(ctx)
mnemonic = "AngularTemplateCompile" mnemonic = "AngularTemplateCompile"
progress_message = "Compiling Angular templates (%s - %s) %s" % (_compiler_name(ctx), compile_mode, label) progress_message = "Compiling Angular templates (%s - %s) %s" % (_compiler_name(ctx), compile_mode, label)
@ -578,7 +578,7 @@ def ng_module_impl(ctx, ts_compile_actions):
conversion by ts_providers_dict_to_struct conversion by ts_providers_dict_to_struct
""" """
is_legacy_ngc = _is_legacy_ngc(ctx) is_legacy_ngc = _is_view_engine_enabled(ctx)
providers = ts_compile_actions( providers = ts_compile_actions(
ctx, ctx,