build(bazel): check for renderer flag in `ng_module()` (#37529)
This checks for a Bazel flag in `ng_module()` in the `_renderer` attribute which specifies the renderer to use for the build. The main advantage of this flag is that it can be overridden with [Bazel transitions](https://docs.bazel.build/versions/master/skylark/config.html), giving much more flexibility for migrating individual applications in a Bazel workspace to Ivy. This flag is not intended to replace `--config ivy` or `--define angular_ivy_enabled=True` (although it technically could). As a result, this flag is not and will not actually be used anywhere in the `angular/angular` repo. Instead, a `string_flag()` is provided internally which sets the renderer via a transition. See http://cl/315749946. Note that this does **not** introduce a dependency on Skylib for `angular/angular`. The dependency isn't actually necessary because `BuildSettingInfo` is not used externally anyways. By doing this, it is not necessary for downstream, external workspaces to depend on Skylib. PR Close #37529
This commit is contained in:
parent
b45acb8d32
commit
1091ddbb8e
|
@ -35,6 +35,11 @@ compile_ts = _compile_ts
|
|||
DEPS_ASPECTS = _DEPS_ASPECTS
|
||||
ts_providers_dict_to_struct = _ts_providers_dict_to_struct
|
||||
|
||||
# Should be defined as `BuildSettingInfo` from Skylib, but a dependency on
|
||||
# Skylib is not necessary here because this is only used in google3 where Skylib
|
||||
# is loaded differently anyways where this file is overridden.
|
||||
BuildSettingInfo = provider(doc = "Not used outside google3.")
|
||||
|
||||
DEFAULT_API_EXTRACTOR = "@npm//@angular/bazel/bin:api-extractor"
|
||||
DEFAULT_NG_COMPILER = "@npm//@angular/bazel/bin:ngc-wrapped"
|
||||
DEFAULT_NG_XI18N = "@npm//@angular/bazel/bin:xi18n"
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
load(
|
||||
":external.bzl",
|
||||
"BuildSettingInfo",
|
||||
"COMMON_ATTRIBUTES",
|
||||
"COMMON_OUTPUTS",
|
||||
"DEFAULT_API_EXTRACTOR",
|
||||
|
@ -36,6 +37,15 @@ def is_ivy_enabled(ctx):
|
|||
Boolean, Whether the ivy compiler should be used.
|
||||
"""
|
||||
|
||||
# Check the renderer flag to see if Ivy is enabled.
|
||||
# This is intended to support a transition use case for google3 migration.
|
||||
# The `_renderer` attribute will never be set externally, but will always be
|
||||
# set internally as a `string_flag()` with the allowed values of:
|
||||
# "view_engine" or "ivy".
|
||||
if ((hasattr(ctx.attr, "_renderer") and
|
||||
ctx.attr._renderer[BuildSettingInfo].value == "ivy")):
|
||||
return True
|
||||
|
||||
# TODO(josephperott): Remove after ~Feb 2020, to allow local script migrations
|
||||
if "compile" in ctx.var and ctx.workspace_name == "angular":
|
||||
fail(
|
||||
|
|
Loading…
Reference in New Issue