angular/packages/core/src/ivy_switch.ts
Alex Rickabaugh 1eafd04eb3 build(ivy): support alternate compilation modes to enable Ivy testing (#24056)
Bazel has a restriction that a single output (eg. a compiled version of
//packages/common) can only be produced by a single rule. This precludes
the Angular repo from having multiple rules that build the same code. And
the complexity of having a single rule produce multiple outputs (eg. an
ngc-compiled version of //packages/common and an Ivy-enabled version) is
too high.

Additionally, the Angular repo has lots of existing tests which could be
executed as-is under Ivy. Such testing is very valuable, and it would be
nice to share not only the code, but the dependency graph / build config
as well.

Thus, this change introduces a --define flag 'compile' with three potential
values. When --define=compile=X is set, the entire build system runs in a
particular mode - the behavior of all existing targets is controlled by
the flag. This allows us to reuse our entire build structure for testing
in a variety of different manners. The flag has three possible settings:

* legacy (the default): the traditional View Engine (ngc) build
* local: runs the prototype ngtsc compiler, which does not rely on global
  analysis
* jit: runs ngtsc in a mode which executes tsickle, but excludes the
  Angular related transforms, which approximates the behavior of plain
  tsc. This allows the main packages such as common to be tested with
  the JIT compiler.

Additionally, the ivy_ng_module() rule still exists and runs ngc in a mode
where Ivy-compiled output is produced from global analysis information, as
a stopgap while ngtsc is being developed.

PR Close #24056
2018-05-29 18:02:29 -04:00

37 lines
1.4 KiB
TypeScript

/**
* @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_legacy';
// TODO(alxhub): debug why metadata doesn't properly propagate through this file.