From 692c587f17aff216d3e1e6798ebb591c0de53b6b Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Tue, 9 Jun 2020 14:56:23 -0700 Subject: [PATCH] build(bazel): check for renderer flag in `ng_module()` 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. --- packages/bazel/src/external.bzl | 5 +++++ packages/bazel/src/ng_module.bzl | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/bazel/src/external.bzl b/packages/bazel/src/external.bzl index 32b640ae30f94..73c74ddf59d3b 100644 --- a/packages/bazel/src/external.bzl +++ b/packages/bazel/src/external.bzl @@ -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" diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index 35da43a23966a..eb158626b79ef 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -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(