diff --git a/packages/core/BUILD.bazel b/packages/core/BUILD.bazel index 80550ecf11..7bbfa1911e 100644 --- a/packages/core/BUILD.bazel +++ b/packages/core/BUILD.bazel @@ -9,7 +9,10 @@ ng_module( "*.ts", "src/**/*.ts", ], - ), + exclude = ["src/ivy_switch.ts"], + ) + [ + ":ivy_switch", + ], module_name = "@angular/core", deps = [ "//packages:types", @@ -30,3 +33,20 @@ ng_package( "//packages/core/testing", ], ) + +## Controls if Ivy is enabled. (Temporary target until we permanently switch over to Ivy) +## +## This file generates `src/ivy_switch.ts` file which reexports symbols for `ViewEngine` or `Ivy.` +## - append `--define=ivy=false` (default) to `bazel` command to reexport `./ivy_switch_false` +## and use `ViewEngine`; +## - append `--define=ivy=true` to `bazel` command to rexport `./ivy_switch_true` and use `Ivy`; +## +## NOTE: `--define=ivy=true` works with any `bazel` command or target across the repo. +## +## See: `//tools/bazel.rc` where `--define=ivy=false` is defined as default. +## See: `./src/ivy_switch.ts` for more details. +genrule( + name = "ivy_switch", + outs = ["src/ivy_switch.ts"], + cmd = "echo export '*' from \"'./ivy_switch_$(ivy)';\" > $@", +) diff --git a/packages/core/src/core_private_export.ts b/packages/core/src/core_private_export.ts index 7b6101355e..f56c13e4e5 100644 --- a/packages/core/src/core_private_export.ts +++ b/packages/core/src/core_private_export.ts @@ -15,6 +15,7 @@ export {ChangeDetectorStatus as ɵChangeDetectorStatus, isDefaultChangeDetection export {Console as ɵConsole} from './console'; export {inject as ɵinject, setCurrentInjector as ɵsetCurrentInjector} from './di/injector'; export {APP_ROOT as ɵAPP_ROOT} from './di/scope'; +export {ivyEnabled as ɵivyEnabled} from './ivy_switch'; export {ComponentFactory as ɵComponentFactory} from './linker/component_factory'; export {CodegenComponentFactoryResolver as ɵCodegenComponentFactoryResolver} from './linker/component_factory_resolver'; export {ReflectionCapabilities as ɵReflectionCapabilities} from './reflection/reflection_capabilities'; diff --git a/packages/core/src/ivy_switch.ts b/packages/core/src/ivy_switch.ts new file mode 100644 index 0000000000..a584e99587 --- /dev/null +++ b/packages/core/src/ivy_switch.ts @@ -0,0 +1,34 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * This file is used to control if the default rendering pipeline should be `ViewEngine` or `Ivy`. + * + * Reexport from: + * - `./ivy_switch_false` => Use `ViewEngine`. + * - `./ivy_switch_true` => Use `Ivy`. + * + * This file is here for your IDE as well as for `google3`. The `bazel` build system + * specifically excludes this file and instead generates a new file which is controlled by + * command line: + * + * - `bazel build packages/core` => Use `ViewEngine` + * - `bazel build packages/core --define=ivy=true` => Use `Ivy` + * + * See: `bazel build packages/core:ivy_switch` for more details. + * + * ## How to use this + * + * Use this mechanism to have the same symbol be aliased to different implementation. + * 1) Create two implementations of a symbol (most likely a `function` or a `class`). + * 2) Export the two implementation under same name in `./ivy_switch_false` and `./ivy_switch_false` + * respectively. + * 3) Import the symbol from `./ivy_switch`. The imported symbol will that point to either the + * symbol in `./ivy_switch_false` and `./ivy_switch_false` depending on the compilation mode. + */ +export * from './ivy_switch_false'; diff --git a/packages/core/src/ivy_switch_false.ts b/packages/core/src/ivy_switch_false.ts new file mode 100644 index 0000000000..599a11d63e --- /dev/null +++ b/packages/core/src/ivy_switch_false.ts @@ -0,0 +1,9 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export const ivyEnabled = false; \ No newline at end of file diff --git a/packages/core/src/ivy_switch_true.ts b/packages/core/src/ivy_switch_true.ts new file mode 100644 index 0000000000..fc5c97d002 --- /dev/null +++ b/packages/core/src/ivy_switch_true.ts @@ -0,0 +1,9 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export const ivyEnabled = true; \ No newline at end of file diff --git a/tools/bazel.rc b/tools/bazel.rc index 1d0f39dfd2..52af863bea 100644 --- a/tools/bazel.rc +++ b/tools/bazel.rc @@ -53,3 +53,10 @@ test --experimental_ui ################################ # Bazel flags for CircleCI are in /.circleci/bazel.rc + +################################ +# Temporary Settings for Ivy # +################################ +# to determine if the compiler used should be Ivy or ViewEngine one can use `--define=ivy=true` on +# any bazel target. This is a temporary flag until codebase is permanently switched to ViewEngine. +build --define=ivy=false \ No newline at end of file