2017-08-16 12:02:20 -04:00
|
|
|
# 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
|
2018-04-25 12:23:20 -04:00
|
|
|
"""Run Angular's AOT template compiler
|
2018-01-05 13:53:55 -05:00
|
|
|
"""
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
load(
|
2018-10-17 14:25:22 -04:00
|
|
|
":external.bzl",
|
2017-08-21 11:23:47 -04:00
|
|
|
"COMMON_ATTRIBUTES",
|
2017-09-25 15:40:22 -04:00
|
|
|
"COMMON_OUTPUTS",
|
2019-03-09 07:24:20 -05:00
|
|
|
"DEFAULT_API_EXTRACTOR",
|
2018-10-17 14:25:22 -04:00
|
|
|
"DEFAULT_NG_COMPILER",
|
|
|
|
"DEFAULT_NG_XI18N",
|
2018-10-17 16:48:17 -04:00
|
|
|
"DEPS_ASPECTS",
|
2019-04-23 13:50:55 -04:00
|
|
|
"NodeModuleSources",
|
2018-01-30 02:33:22 -05:00
|
|
|
"TsConfigInfo",
|
2018-10-17 14:25:22 -04:00
|
|
|
"collect_node_modules_aspect",
|
2018-08-07 19:15:45 -04:00
|
|
|
"compile_ts",
|
2017-08-21 11:23:47 -04:00
|
|
|
"ts_providers_dict_to_struct",
|
2018-08-07 19:15:45 -04:00
|
|
|
"tsc_wrapped_tsconfig",
|
2017-08-16 12:02:20 -04:00
|
|
|
)
|
2018-10-16 16:20:00 -04:00
|
|
|
|
2019-02-12 16:49:23 -05:00
|
|
|
_FLAT_DTS_FILE_SUFFIX = ".bundle.d.ts"
|
2019-03-06 03:04:18 -05:00
|
|
|
_R3_SYMBOLS_DTS_FILE = "src/r3_symbols.d.ts"
|
2019-02-12 16:49:23 -05:00
|
|
|
|
2018-07-26 12:16:07 -04:00
|
|
|
def compile_strategy(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
"""Detect which strategy should be used to implement ng_module.
|
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-21 18:48:00 -04:00
|
|
|
|
2018-11-15 17:18:39 -05:00
|
|
|
Depending on the value of the 'compile' define flag, ng_module
|
2018-08-07 19:15:45 -04:00
|
|
|
can be implemented in various ways. This function reads the configuration passed by the user and
|
|
|
|
determines which mode is active.
|
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-21 18:48:00 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Args:
|
|
|
|
ctx: skylark rule execution context
|
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-21 18:48:00 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Returns:
|
2018-11-15 17:18:39 -05:00
|
|
|
one of 'legacy' or 'aot' depending on the configuration in ctx
|
2018-08-07 19:15:45 -04:00
|
|
|
"""
|
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-21 18:48:00 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
strategy = "legacy"
|
|
|
|
if "compile" in ctx.var:
|
|
|
|
strategy = ctx.var["compile"]
|
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-21 18:48:00 -04:00
|
|
|
|
2018-11-15 17:18:39 -05:00
|
|
|
if strategy not in ["legacy", "aot"]:
|
2018-08-07 19:15:45 -04:00
|
|
|
fail("Unknown --define=compile value '%s'" % strategy)
|
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-21 18:48:00 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
return strategy
|
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-21 18:48:00 -04:00
|
|
|
|
|
|
|
def _compiler_name(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
"""Selects a user-visible name depending on the current compilation strategy.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
ctx: skylark rule execution context
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
the name of the current compiler to be displayed in build output
|
|
|
|
"""
|
|
|
|
|
|
|
|
strategy = compile_strategy(ctx)
|
|
|
|
if strategy == "legacy":
|
|
|
|
return "ngc"
|
2018-10-23 12:54:12 -04:00
|
|
|
elif strategy == "aot":
|
2018-08-07 19:15:45 -04:00
|
|
|
return "ngtsc"
|
|
|
|
else:
|
|
|
|
fail("unreachable")
|
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-21 18:48:00 -04:00
|
|
|
|
|
|
|
def _enable_ivy_value(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
"""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
|
2018-10-23 12:54:12 -04:00
|
|
|
elif strategy == "aot":
|
2019-02-08 06:37:21 -05:00
|
|
|
return True
|
2018-08-07 19:15:45 -04:00
|
|
|
else:
|
|
|
|
fail("unreachable")
|
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-21 18:48:00 -04:00
|
|
|
|
2018-12-05 13:03:27 -05:00
|
|
|
def _is_legacy_ngc(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
"""Determines whether Angular outputs will be produced by the current compilation strategy.
|
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-21 18:48:00 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Args:
|
|
|
|
ctx: skylark rule execution context
|
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-21 18:48:00 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Returns:
|
|
|
|
true iff the current compilation strategy will produce View Engine compilation outputs (such as
|
|
|
|
factory files), false otherwise
|
|
|
|
"""
|
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-21 18:48:00 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
strategy = compile_strategy(ctx)
|
2018-11-15 17:18:39 -05:00
|
|
|
return strategy == "legacy"
|
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-21 18:48:00 -04:00
|
|
|
|
2018-02-02 18:13:31 -05:00
|
|
|
def _basename_of(ctx, file):
|
2018-08-07 19:15:45 -04:00
|
|
|
ext_len = len(".ts")
|
|
|
|
if file.short_path.endswith(".ng.html"):
|
|
|
|
ext_len = len(".ng.html")
|
|
|
|
elif file.short_path.endswith(".html"):
|
|
|
|
ext_len = len(".html")
|
|
|
|
return file.short_path[len(ctx.label.package) + 1:-ext_len]
|
2018-02-02 18:13:31 -05:00
|
|
|
|
2018-03-28 16:09:49 -04:00
|
|
|
# Return true if run with bazel (the open-sourced version of blaze), false if
|
|
|
|
# run with blaze.
|
|
|
|
def _is_bazel():
|
2018-08-07 19:15:45 -04:00
|
|
|
return not hasattr(native, "genmpm")
|
2018-03-28 16:09:49 -04:00
|
|
|
|
2018-03-28 21:15:36 -04:00
|
|
|
def _flat_module_out_file(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
"""Provide a default for the flat_module_out_file attribute.
|
2018-03-28 21:15:36 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
We cannot use the default="" parameter of ctx.attr because the value is calculated
|
|
|
|
from other attributes (name)
|
2018-03-28 21:15:36 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Args:
|
|
|
|
ctx: skylark rule execution context
|
2018-03-28 21:15:36 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Returns:
|
|
|
|
a basename used for the flat module out (no extension)
|
|
|
|
"""
|
|
|
|
if hasattr(ctx.attr, "flat_module_out_file") and ctx.attr.flat_module_out_file:
|
|
|
|
return ctx.attr.flat_module_out_file
|
|
|
|
return "%s_public_index" % ctx.label.name
|
2018-03-28 21:15:36 -04:00
|
|
|
|
2019-02-07 13:02:07 -05:00
|
|
|
def _should_produce_dts_bundle(ctx):
|
|
|
|
"""Should we produce dts bundles.
|
|
|
|
|
|
|
|
We only produce flatten dts outs when we expect the ng_module is meant to be published,
|
|
|
|
based on the value of the bundle_dts attribute.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
ctx: skylark rule execution context
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
true when we should produce bundled dts.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# At the moment we cannot use this with ngtsc compiler since it emits
|
|
|
|
# import * as ___ from local modules which is not supported
|
|
|
|
# see: https://github.com/Microsoft/web-build-tools/issues/1029
|
2019-02-12 16:49:23 -05:00
|
|
|
return _is_legacy_ngc(ctx) and hasattr(ctx.attr, "bundle_dts") and ctx.attr.bundle_dts
|
2019-02-07 13:02:07 -05:00
|
|
|
|
2019-03-06 03:04:18 -05:00
|
|
|
def _should_produce_r3_symbols_bundle(ctx):
|
|
|
|
"""Should we produce r3_symbols bundle.
|
|
|
|
|
|
|
|
NGCC relies on having r3_symbols file. This file is located in @angular/core
|
|
|
|
And should only be included when bundling core in legacy mode.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
ctx: skylark rule execution context
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
true when we should produce r3_symbols dts.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# iif we are compiling @angular/core with ngc we should add this addition dts bundle
|
|
|
|
# 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
|
|
|
|
# todo: alan-agius4: remove when ngcc doesn't need this anymore
|
|
|
|
return _is_legacy_ngc(ctx) and ctx.attr.module_name == "@angular/core"
|
|
|
|
|
2018-03-28 21:15:36 -04:00
|
|
|
def _should_produce_flat_module_outs(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
"""Should we produce flat module outputs.
|
2018-03-28 21:15:36 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
We only produce flat module outs when we expect the ng_module is meant to be published,
|
|
|
|
based on the presence of the module_name attribute.
|
2018-03-28 21:15:36 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Args:
|
|
|
|
ctx: skylark rule execution context
|
2018-03-28 21:15:36 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Returns:
|
|
|
|
true iff we should run the bundle_index_host to produce flat module metadata and bundle index
|
|
|
|
"""
|
|
|
|
return _is_bazel() and ctx.attr.module_name
|
2018-03-28 21:15:36 -04:00
|
|
|
|
2017-08-16 12:02:20 -04:00
|
|
|
# Calculate the expected output of the template compiler for every source in
|
|
|
|
# in the library. Most of these will be produced as empty files but it is
|
|
|
|
# unknown, without parsing, which will be empty.
|
2018-01-05 13:53:55 -05:00
|
|
|
def _expected_outs(ctx):
|
2018-12-05 13:03:27 -05:00
|
|
|
is_legacy_ngc = _is_legacy_ngc(ctx)
|
2018-08-07 19:15:45 -04:00
|
|
|
|
|
|
|
devmode_js_files = []
|
|
|
|
closure_js_files = []
|
|
|
|
declaration_files = []
|
|
|
|
summary_files = []
|
|
|
|
metadata_files = []
|
|
|
|
|
|
|
|
factory_basename_set = depset([_basename_of(ctx, src) for src in ctx.files.factories])
|
|
|
|
|
|
|
|
for src in ctx.files.srcs + ctx.files.assets:
|
|
|
|
package_prefix = ctx.label.package + "/" if ctx.label.package else ""
|
|
|
|
|
|
|
|
# Strip external repository name from path if src is from external repository
|
|
|
|
# If src is from external repository, it's short_path will be ../<external_repo_name>/...
|
|
|
|
short_path = src.short_path if src.short_path[0:2] != ".." else "/".join(src.short_path.split("/")[2:])
|
|
|
|
|
|
|
|
if short_path.endswith(".ts") and not short_path.endswith(".d.ts"):
|
|
|
|
basename = short_path[len(package_prefix):-len(".ts")]
|
2018-12-05 13:03:27 -05:00
|
|
|
if (len(factory_basename_set.to_list()) == 0 or basename in factory_basename_set.to_list()):
|
2018-08-07 19:15:45 -04:00
|
|
|
devmode_js = [
|
|
|
|
".ngfactory.js",
|
|
|
|
".ngsummary.js",
|
|
|
|
".js",
|
|
|
|
]
|
2018-12-05 13:03:27 -05:00
|
|
|
|
|
|
|
# Only ngc produces .json files, they're not needed in Ivy.
|
|
|
|
if is_legacy_ngc:
|
|
|
|
summaries = [".ngsummary.json"]
|
|
|
|
metadata = [".metadata.json"]
|
|
|
|
else:
|
|
|
|
summaries = []
|
|
|
|
metadata = []
|
2018-08-07 19:15:45 -04:00
|
|
|
else:
|
|
|
|
devmode_js = [".js"]
|
2018-08-08 13:44:59 -04:00
|
|
|
if not _is_bazel():
|
2018-08-13 15:57:03 -04:00
|
|
|
devmode_js += [".ngfactory.js"]
|
2018-08-07 19:15:45 -04:00
|
|
|
summaries = []
|
|
|
|
metadata = []
|
2018-12-05 13:03:27 -05:00
|
|
|
elif is_legacy_ngc and short_path.endswith(".css"):
|
2018-08-07 19:15:45 -04:00
|
|
|
basename = short_path[len(package_prefix):-len(".css")]
|
|
|
|
devmode_js = [
|
|
|
|
".css.shim.ngstyle.js",
|
|
|
|
".css.ngstyle.js",
|
|
|
|
]
|
|
|
|
summaries = []
|
|
|
|
metadata = []
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
|
|
|
|
filter_summaries = ctx.attr.filter_summaries
|
|
|
|
closure_js = [f.replace(".js", ".closure.js") for f in devmode_js if not filter_summaries or not f.endswith(".ngsummary.js")]
|
|
|
|
declarations = [f.replace(".js", ".d.ts") for f in devmode_js]
|
|
|
|
|
|
|
|
devmode_js_files += [ctx.actions.declare_file(basename + ext) for ext in devmode_js]
|
|
|
|
closure_js_files += [ctx.actions.declare_file(basename + ext) for ext in closure_js]
|
|
|
|
declaration_files += [ctx.actions.declare_file(basename + ext) for ext in declarations]
|
|
|
|
summary_files += [ctx.actions.declare_file(basename + ext) for ext in summaries]
|
|
|
|
if not _is_bazel():
|
|
|
|
metadata_files += [ctx.actions.declare_file(basename + ext) for ext in metadata]
|
|
|
|
|
2019-03-06 03:04:18 -05:00
|
|
|
dts_bundles = None
|
2019-02-07 13:02:07 -05:00
|
|
|
if _should_produce_dts_bundle(ctx):
|
|
|
|
# We need to add a suffix to bundle as it might collide with the flat module dts.
|
|
|
|
# The flat module dts out contains several other exports
|
2019-03-06 03:04:18 -05:00
|
|
|
# https://github.com/angular/angular/blob/84406e4d6d93b28b23efbb1701bc5ae1084da67b/packages/compiler-cli/src/metadata/index_writer.ts#L18
|
2019-02-07 13:02:07 -05:00
|
|
|
# the file name will be like 'core.bundle.d.ts'
|
2019-03-06 03:04:18 -05:00
|
|
|
dts_bundles = [ctx.actions.declare_file(ctx.label.name + _FLAT_DTS_FILE_SUFFIX)]
|
|
|
|
|
|
|
|
if _should_produce_r3_symbols_bundle(ctx):
|
|
|
|
dts_bundles.append(ctx.actions.declare_file(_R3_SYMBOLS_DTS_FILE.replace(".d.ts", _FLAT_DTS_FILE_SUFFIX)))
|
2019-02-07 13:02:07 -05:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
# We do this just when producing a flat module index for a publishable ng_module
|
2018-12-13 12:07:26 -05:00
|
|
|
if _should_produce_flat_module_outs(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
flat_module_out = _flat_module_out_file(ctx)
|
|
|
|
devmode_js_files.append(ctx.actions.declare_file("%s.js" % flat_module_out))
|
|
|
|
closure_js_files.append(ctx.actions.declare_file("%s.closure.js" % flat_module_out))
|
|
|
|
bundle_index_typings = ctx.actions.declare_file("%s.d.ts" % flat_module_out)
|
|
|
|
declaration_files.append(bundle_index_typings)
|
2018-12-13 12:07:26 -05:00
|
|
|
if is_legacy_ngc:
|
|
|
|
metadata_files.append(ctx.actions.declare_file("%s.metadata.json" % flat_module_out))
|
2018-08-07 19:15:45 -04:00
|
|
|
else:
|
|
|
|
bundle_index_typings = None
|
|
|
|
|
|
|
|
# TODO(alxhub): i18n is only produced by the legacy compiler currently. This should be re-enabled
|
|
|
|
# when ngtsc can extract messages
|
2019-07-03 15:52:07 -04:00
|
|
|
if is_legacy_ngc and _is_bazel():
|
2019-06-12 21:18:26 -04:00
|
|
|
i18n_messages_files = [ctx.actions.declare_file(ctx.label.name + "_ngc_messages.xmb")]
|
2019-07-03 15:52:07 -04:00
|
|
|
elif is_legacy_ngc:
|
|
|
|
# write the xmb file to blaze-genfiles since that path appears in the translation console keys
|
|
|
|
i18n_messages_files = [ctx.new_file(ctx.genfiles_dir, ctx.label.name + "_ngc_messages.xmb")]
|
2018-01-05 13:53:55 -05:00
|
|
|
else:
|
2018-08-07 19:15:45 -04:00
|
|
|
i18n_messages_files = []
|
|
|
|
|
|
|
|
return struct(
|
|
|
|
closure_js = closure_js_files,
|
|
|
|
devmode_js = devmode_js_files,
|
|
|
|
declarations = declaration_files,
|
|
|
|
summaries = summary_files,
|
|
|
|
metadata = metadata_files,
|
2019-03-06 03:04:18 -05:00
|
|
|
dts_bundles = dts_bundles,
|
2018-08-07 19:15:45 -04:00
|
|
|
bundle_index_typings = bundle_index_typings,
|
|
|
|
i18n_messages = i18n_messages_files,
|
|
|
|
)
|
2017-08-16 12:02:20 -04:00
|
|
|
|
|
|
|
def _ngc_tsconfig(ctx, files, srcs, **kwargs):
|
2018-08-07 19:15:45 -04:00
|
|
|
outs = _expected_outs(ctx)
|
2018-12-05 13:03:27 -05:00
|
|
|
is_legacy_ngc = _is_legacy_ngc(ctx)
|
2018-08-07 19:15:45 -04:00
|
|
|
if "devmode_manifest" in kwargs:
|
|
|
|
expected_outs = outs.devmode_js + outs.declarations + outs.summaries + outs.metadata
|
|
|
|
else:
|
|
|
|
expected_outs = outs.closure_js
|
|
|
|
|
|
|
|
angular_compiler_options = {
|
2019-01-16 04:19:01 -05:00
|
|
|
"enableResourceInlining": ctx.attr.inline_resources,
|
2019-02-26 07:30:44 -05:00
|
|
|
"generateCodeForLibraries": False,
|
|
|
|
"allowEmptyCodegenFiles": True,
|
2018-08-07 19:15:45 -04:00
|
|
|
# Summaries are only enabled if Angular outputs are to be produced.
|
2018-12-05 13:03:27 -05:00
|
|
|
"enableSummariesForJit": is_legacy_ngc,
|
2018-08-07 19:15:45 -04:00
|
|
|
"enableIvy": _enable_ivy_value(ctx),
|
|
|
|
"fullTemplateTypeCheck": ctx.attr.type_check,
|
2019-04-02 14:52:19 -04:00
|
|
|
# TODO(alxhub/arick): template type-checking for Ivy needs to be tested in g3 before it can
|
|
|
|
# be enabled here.
|
|
|
|
"ivyTemplateTypeCheck": False,
|
2019-02-12 17:29:28 -05:00
|
|
|
# In Google3 we still want to use the symbol factory re-exports in order to
|
|
|
|
# not break existing apps inside Google. Unlike Bazel, Google3 does not only
|
|
|
|
# enforce strict dependencies of source files, but also for generated files
|
|
|
|
# (such as the factory files). Therefore in order to avoid that generated files
|
|
|
|
# introduce new module dependencies (which aren't explicitly declared), we need
|
|
|
|
# to enable external symbol re-exports by default when running with Blaze.
|
|
|
|
"createExternalSymbolFactoryReexports": (not _is_bazel()),
|
2018-08-07 19:15:45 -04:00
|
|
|
# FIXME: wrong place to de-dupe
|
|
|
|
"expectedOut": depset([o.path for o in expected_outs]).to_list(),
|
feat(ivy): use fileNameToModuleName to emit imports when it's available (#28523)
The ultimate goal of this commit is to make use of fileNameToModuleName to
get the module specifier to use when generating an import, when that API is
available in the CompilerHost that ngtsc is created with.
As part of getting there, the way in which ngtsc tracks references and
generates import module specifiers is refactored considerably. References
are tracked with the Reference class, and previously ngtsc had several
different kinds of Reference. An AbsoluteReference represented a declaration
which needed to be imported via an absolute module specifier tracked in the
AbsoluteReference, and a RelativeReference represented a declaration from
the local program, imported via relative path or referred to directly by
identifier if possible. Thus, how to refer to a particular declaration was
encoded into the Reference type _at the time of creation of the Reference_.
This commit refactors that logic and reduces Reference to a single class
with no subclasses. A Reference represents a node being referenced, plus
context about how the node was located. This context includes a
"bestGuessOwningModule", the compiler's best guess at which absolute
module specifier has defined this reference. For example, if the compiler
arrives at the declaration of CommonModule via an import to @angular/common,
then any references obtained from CommonModule (e.g. NgIf) will also be
considered to be owned by @angular/common.
A ReferenceEmitter class and accompanying ReferenceEmitStrategy interface
are introduced. To produce an Expression referring to a given Reference'd
node, the ReferenceEmitter consults a sequence of ReferenceEmitStrategy
implementations.
Several different strategies are defined:
- LocalIdentifierStrategy: use local ts.Identifiers if available.
- AbsoluteModuleStrategy: if the Reference has a bestGuessOwningModule,
import the node via an absolute import from that module specifier.
- LogicalProjectStrategy: if the Reference is in the logical project
(is under the project rootDirs), import the node via a relative import.
- FileToModuleStrategy: use a FileToModuleHost to generate the module
specifier by which to import the node.
Depending on the availability of fileNameToModuleName in the CompilerHost,
then, a different collection of these strategies is used for compilation.
PR Close #28523
2019-02-01 20:24:21 -05:00
|
|
|
"_useHostForImportGeneration": (not _is_bazel()),
|
2018-08-07 19:15:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if _should_produce_flat_module_outs(ctx):
|
|
|
|
angular_compiler_options["flatModuleId"] = ctx.attr.module_name
|
|
|
|
angular_compiler_options["flatModuleOutFile"] = _flat_module_out_file(ctx)
|
|
|
|
angular_compiler_options["flatModulePrivateSymbolPrefix"] = "_".join(
|
|
|
|
[ctx.workspace_name] + ctx.label.package.split("/") + [ctx.label.name, ""],
|
|
|
|
)
|
|
|
|
|
|
|
|
return dict(tsc_wrapped_tsconfig(ctx, files, srcs, **kwargs), **{
|
|
|
|
"angularCompilerOptions": angular_compiler_options,
|
|
|
|
})
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2017-08-21 11:23:47 -04:00
|
|
|
def _collect_summaries_aspect_impl(target, ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
results = depset(target.angular.summaries if hasattr(target, "angular") else [])
|
2017-08-21 11:23:47 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
# If we are visiting empty-srcs ts_library, this is a re-export
|
|
|
|
srcs = ctx.rule.attr.srcs if hasattr(ctx.rule.attr, "srcs") else []
|
2017-08-21 11:23:47 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
# "re-export" rules should expose all the files of their deps
|
|
|
|
if not srcs and hasattr(ctx.rule.attr, "deps"):
|
|
|
|
for dep in ctx.rule.attr.deps:
|
|
|
|
if (hasattr(dep, "angular")):
|
|
|
|
results = depset(dep.angular.summaries, transitive = [results])
|
2017-08-21 11:23:47 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
return struct(collect_summaries_aspect_result = results)
|
2017-08-21 11:23:47 -04:00
|
|
|
|
|
|
|
_collect_summaries_aspect = aspect(
|
|
|
|
implementation = _collect_summaries_aspect_impl,
|
|
|
|
attr_aspects = ["deps"],
|
|
|
|
)
|
|
|
|
|
2017-09-27 10:38:36 -04:00
|
|
|
# Extra options passed to Node when running ngc.
|
|
|
|
_EXTRA_NODE_OPTIONS_FLAGS = [
|
|
|
|
# Expose the v8 garbage collection API to JS.
|
2018-08-07 19:15:45 -04:00
|
|
|
"--node_options=--expose-gc",
|
2018-12-14 10:54:22 -05:00
|
|
|
# Show ~full stack traces, instead of cutting off after 10 items.
|
|
|
|
"--node_options=--stack-trace-limit=100",
|
2019-01-18 10:47:48 -05:00
|
|
|
# Give 2 GB RAM to node to make bigger google3 modules to compile, we should be able to drop this after Ivy/ngtsc is the default in g3
|
|
|
|
"--node_options=--max-old-space-size=2048",
|
2017-09-27 10:38:36 -04:00
|
|
|
]
|
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
def ngc_compile_action(
|
|
|
|
ctx,
|
|
|
|
label,
|
|
|
|
inputs,
|
|
|
|
outputs,
|
|
|
|
messages_out,
|
|
|
|
tsconfig_file,
|
|
|
|
node_opts,
|
|
|
|
locale = None,
|
2019-02-12 16:49:23 -05:00
|
|
|
i18n_args = [],
|
2019-03-06 03:04:18 -05:00
|
|
|
dts_bundles_out = None):
|
2018-08-07 19:15:45 -04:00
|
|
|
"""Helper function to create the ngc action.
|
|
|
|
|
|
|
|
This is exposed for google3 to wire up i18n replay rules, and is not intended
|
|
|
|
as part of the public API.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
ctx: skylark context
|
|
|
|
label: the label of the ng_module being compiled
|
|
|
|
inputs: passed to the ngc action's inputs
|
|
|
|
outputs: passed to the ngc action's outputs
|
|
|
|
messages_out: produced xmb files
|
|
|
|
tsconfig_file: tsconfig file with settings used for the compilation
|
|
|
|
node_opts: list of strings, extra nodejs options.
|
|
|
|
locale: i18n locale, or None
|
|
|
|
i18n_args: additional command-line arguments to ngc
|
2019-03-06 03:04:18 -05:00
|
|
|
dts_bundles_out: produced flattened dts file
|
2018-08-07 19:15:45 -04:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
the parameters of the compilation which will be used to replay the ngc action for i18N.
|
|
|
|
"""
|
|
|
|
|
2018-12-05 13:03:27 -05:00
|
|
|
is_legacy_ngc = _is_legacy_ngc(ctx)
|
2018-08-07 19:15:45 -04:00
|
|
|
|
|
|
|
mnemonic = "AngularTemplateCompile"
|
|
|
|
progress_message = "Compiling Angular templates (%s) %s" % (_compiler_name(ctx), label)
|
|
|
|
|
|
|
|
if locale:
|
|
|
|
mnemonic = "AngularI18NMerging"
|
|
|
|
supports_workers = "0"
|
|
|
|
progress_message = ("Recompiling Angular templates (ngc) %s for locale %s" %
|
|
|
|
(label, locale))
|
|
|
|
else:
|
|
|
|
supports_workers = str(int(ctx.attr._supports_workers))
|
|
|
|
|
|
|
|
arguments = (list(_EXTRA_NODE_OPTIONS_FLAGS) +
|
|
|
|
["--node_options=%s" % opt for opt in node_opts])
|
|
|
|
|
|
|
|
# One at-sign makes this a params-file, enabling the worker strategy.
|
|
|
|
# Two at-signs escapes the argument so it's passed through to ngc
|
|
|
|
# rather than the contents getting expanded.
|
|
|
|
if supports_workers == "1":
|
|
|
|
arguments += ["@@" + tsconfig_file.path]
|
|
|
|
else:
|
|
|
|
arguments += ["-p", tsconfig_file.path]
|
|
|
|
|
|
|
|
arguments += i18n_args
|
|
|
|
|
2018-04-10 14:50:43 -04:00
|
|
|
ctx.actions.run(
|
2018-08-07 19:15:45 -04:00
|
|
|
progress_message = progress_message,
|
|
|
|
mnemonic = mnemonic,
|
2017-09-27 10:38:36 -04:00
|
|
|
inputs = inputs,
|
|
|
|
outputs = outputs,
|
2018-08-07 19:15:45 -04:00
|
|
|
arguments = arguments,
|
|
|
|
executable = ctx.executable.compiler,
|
|
|
|
execution_requirements = {
|
|
|
|
"supports-workers": supports_workers,
|
|
|
|
},
|
2017-09-27 10:38:36 -04:00
|
|
|
)
|
|
|
|
|
2018-12-05 13:03:27 -05:00
|
|
|
if is_legacy_ngc and messages_out != None:
|
2019-07-03 15:52:07 -04:00
|
|
|
# The base path is bin_dir because of the way the ngc
|
|
|
|
# compiler host is configured. Under Blaze, we need to explicitly
|
|
|
|
# point to genfiles/ to redirect the output.
|
|
|
|
# See _expected_outs above, where the output path for the message file
|
|
|
|
# is conditional on whether we are in Bazel.
|
|
|
|
message_file_path = messages_out[0].short_path if _is_bazel() else "../genfiles/" + messages_out[0].short_path
|
2018-08-07 19:15:45 -04:00
|
|
|
ctx.actions.run(
|
2019-05-09 17:51:51 -04:00
|
|
|
inputs = inputs,
|
2018-08-07 19:15:45 -04:00
|
|
|
outputs = messages_out,
|
2018-10-16 16:20:00 -04:00
|
|
|
executable = ctx.executable.ng_xi18n,
|
2018-08-07 19:15:45 -04:00
|
|
|
arguments = (_EXTRA_NODE_OPTIONS_FLAGS +
|
|
|
|
[tsconfig_file.path] +
|
2019-07-03 15:52:07 -04:00
|
|
|
[message_file_path]),
|
2018-08-07 19:15:45 -04:00
|
|
|
progress_message = "Extracting Angular 2 messages (ng_xi18n)",
|
|
|
|
mnemonic = "Angular2MessageExtractor",
|
|
|
|
)
|
|
|
|
|
2019-03-06 03:04:18 -05:00
|
|
|
if dts_bundles_out != None:
|
2019-02-07 13:02:07 -05:00
|
|
|
# combine the inputs and outputs and filter .d.ts and json files
|
2019-06-12 21:18:26 -04:00
|
|
|
filter_inputs = [f for f in inputs.to_list() + outputs if f.path.endswith(".d.ts") or f.path.endswith(".json")]
|
2019-02-07 13:02:07 -05:00
|
|
|
|
|
|
|
if _should_produce_flat_module_outs(ctx):
|
2019-03-06 03:04:18 -05:00
|
|
|
dts_entry_points = ["%s.d.ts" % _flat_module_out_file(ctx)]
|
2019-02-07 13:02:07 -05:00
|
|
|
else:
|
2019-06-07 16:38:06 -04:00
|
|
|
dts_entry_points = [ctx.attr.entry_point.label.name.replace(".ts", ".d.ts")]
|
2019-03-06 03:04:18 -05:00
|
|
|
|
|
|
|
if _should_produce_r3_symbols_bundle(ctx):
|
|
|
|
dts_entry_points.append(_R3_SYMBOLS_DTS_FILE)
|
2019-02-07 13:02:07 -05:00
|
|
|
|
|
|
|
ctx.actions.run(
|
|
|
|
progress_message = "Bundling DTS %s" % str(ctx.label),
|
|
|
|
mnemonic = "APIExtractor",
|
2019-03-09 07:24:20 -05:00
|
|
|
executable = ctx.executable.api_extractor,
|
2019-02-07 13:02:07 -05:00
|
|
|
inputs = filter_inputs,
|
2019-03-06 03:04:18 -05:00
|
|
|
outputs = dts_bundles_out,
|
2019-02-07 13:02:07 -05:00
|
|
|
arguments = [
|
|
|
|
tsconfig_file.path,
|
2019-03-06 03:04:18 -05:00
|
|
|
",".join(["/".join([ctx.bin_dir.path, ctx.label.package, f]) for f in dts_entry_points]),
|
|
|
|
",".join([f.path for f in dts_bundles_out]),
|
2019-02-07 13:02:07 -05:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
if not locale and not ctx.attr.no_i18n:
|
|
|
|
return struct(
|
|
|
|
label = label,
|
|
|
|
tsconfig = tsconfig_file,
|
|
|
|
inputs = inputs,
|
|
|
|
outputs = outputs,
|
|
|
|
compiler = ctx.executable.compiler,
|
|
|
|
)
|
|
|
|
|
|
|
|
return None
|
2017-08-21 11:23:47 -04:00
|
|
|
|
2018-10-04 16:14:14 -04:00
|
|
|
def _filter_ts_inputs(all_inputs):
|
|
|
|
# The compiler only needs to see TypeScript sources from the npm dependencies,
|
|
|
|
# but may need to look at package.json and ngsummary.json files as well.
|
|
|
|
return [
|
|
|
|
f
|
|
|
|
for f in all_inputs
|
|
|
|
if f.path.endswith(".js") or f.path.endswith(".ts") or f.path.endswith(".json")
|
|
|
|
]
|
|
|
|
|
2019-03-06 03:04:18 -05:00
|
|
|
def _compile_action(ctx, inputs, outputs, dts_bundles_out, messages_out, tsconfig_file, node_opts):
|
2018-08-07 19:15:45 -04:00
|
|
|
# Give the Angular compiler all the user-listed assets
|
|
|
|
file_inputs = list(ctx.files.assets)
|
|
|
|
|
2019-05-21 18:06:22 -04:00
|
|
|
if (type(inputs) == type([])):
|
|
|
|
file_inputs.extend(inputs)
|
|
|
|
else:
|
|
|
|
# inputs ought to be a list, but allow depset as well
|
|
|
|
# so that this can change independently of rules_typescript
|
|
|
|
# TODO(alexeagle): remove this case after update (July 2019)
|
|
|
|
file_inputs.extend(inputs.to_list())
|
|
|
|
|
2018-10-17 14:25:22 -04:00
|
|
|
if hasattr(ctx.attr, "node_modules"):
|
|
|
|
file_inputs.extend(_filter_ts_inputs(ctx.files.node_modules))
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
# If the user supplies a tsconfig.json file, the Angular compiler needs to read it
|
|
|
|
if hasattr(ctx.attr, "tsconfig") and ctx.file.tsconfig:
|
|
|
|
file_inputs.append(ctx.file.tsconfig)
|
2018-01-30 02:33:22 -05:00
|
|
|
if TsConfigInfo in ctx.attr.tsconfig:
|
|
|
|
file_inputs += ctx.attr.tsconfig[TsConfigInfo].deps
|
2018-08-07 19:15:45 -04:00
|
|
|
|
2018-10-04 16:14:14 -04:00
|
|
|
# Also include files from npm fine grained deps as action_inputs.
|
2019-04-23 13:50:55 -04:00
|
|
|
# These deps are identified by the NodeModuleSources provider.
|
2018-10-04 16:14:14 -04:00
|
|
|
for d in ctx.attr.deps:
|
2019-04-23 13:50:55 -04:00
|
|
|
if NodeModuleSources in d:
|
|
|
|
# Note: we can't avoid calling .to_list() on sources
|
|
|
|
file_inputs.extend(_filter_ts_inputs(d[NodeModuleSources].sources.to_list()))
|
2018-10-04 16:14:14 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
# Collect the inputs and summary files from our deps
|
|
|
|
action_inputs = depset(
|
|
|
|
file_inputs,
|
2019-05-21 18:06:22 -04:00
|
|
|
transitive = [
|
2018-08-07 19:15:45 -04:00
|
|
|
dep.collect_summaries_aspect_result
|
|
|
|
for dep in ctx.attr.deps
|
|
|
|
if hasattr(dep, "collect_summaries_aspect_result")
|
|
|
|
],
|
|
|
|
)
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2019-03-06 03:04:18 -05:00
|
|
|
return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, tsconfig_file, node_opts, None, [], dts_bundles_out)
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2018-02-15 16:43:15 -05:00
|
|
|
def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
|
2018-08-07 19:15:45 -04:00
|
|
|
outs = _expected_outs(ctx)
|
2019-02-07 13:02:07 -05:00
|
|
|
return _compile_action(ctx, inputs, outputs + outs.closure_js, None, outs.i18n_messages, tsconfig_file, node_opts)
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2018-02-15 16:43:15 -05:00
|
|
|
def _devmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
|
2018-08-07 19:15:45 -04:00
|
|
|
outs = _expected_outs(ctx)
|
|
|
|
compile_action_outputs = outputs + outs.devmode_js + outs.declarations + outs.summaries + outs.metadata
|
2019-03-06 03:04:18 -05:00
|
|
|
_compile_action(ctx, inputs, compile_action_outputs, outs.dts_bundles, None, tsconfig_file, node_opts)
|
2017-08-21 11:23:47 -04:00
|
|
|
|
2018-08-17 18:07:39 -04:00
|
|
|
def _ts_expected_outs(ctx, label, srcs_files = []):
|
|
|
|
# rules_typescript expects a function with two or more arguments, but our
|
|
|
|
# implementation doesn't use the label(and **kwargs).
|
|
|
|
_ignored = [label, srcs_files]
|
2018-08-07 19:15:45 -04:00
|
|
|
return _expected_outs(ctx)
|
2018-01-05 13:53:55 -05:00
|
|
|
|
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-21 18:48:00 -04:00
|
|
|
def ng_module_impl(ctx, ts_compile_actions):
|
2018-08-07 19:15:45 -04:00
|
|
|
"""Implementation function for the ng_module rule.
|
2018-01-05 13:53:55 -05:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
This is exposed so that google3 can have its own entry point that re-uses this
|
|
|
|
and is not meant as a public API.
|
2018-01-05 13:53:55 -05:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Args:
|
|
|
|
ctx: the skylark rule context
|
|
|
|
ts_compile_actions: generates all the actions to run an ngc compilation
|
2018-01-05 13:53:55 -05:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
Returns:
|
|
|
|
the result of the ng_module rule as a dict, suitable for
|
|
|
|
conversion by ts_providers_dict_to_struct
|
|
|
|
"""
|
2018-01-05 13:53:55 -05:00
|
|
|
|
2018-12-05 13:03:27 -05:00
|
|
|
is_legacy_ngc = _is_legacy_ngc(ctx)
|
2018-02-16 11:45:21 -05:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
providers = ts_compile_actions(
|
|
|
|
ctx,
|
|
|
|
is_library = True,
|
2019-06-19 00:26:53 -04:00
|
|
|
deps = ctx.attr.deps,
|
2018-08-07 19:15:45 -04:00
|
|
|
compile_action = _prodmode_compile_action,
|
|
|
|
devmode_compile_action = _devmode_compile_action,
|
|
|
|
tsc_wrapped_tsconfig = _ngc_tsconfig,
|
|
|
|
outputs = _ts_expected_outs,
|
|
|
|
)
|
2017-08-21 11:23:47 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
outs = _expected_outs(ctx)
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2018-12-05 13:03:27 -05:00
|
|
|
if is_legacy_ngc:
|
2018-08-07 19:15:45 -04:00
|
|
|
providers["angular"] = {
|
2019-01-16 04:19:01 -05:00
|
|
|
"summaries": outs.summaries,
|
2019-02-26 07:30:44 -05:00
|
|
|
"metadata": outs.metadata,
|
2018-08-07 19:15:45 -04:00
|
|
|
}
|
|
|
|
providers["ngc_messages"] = outs.i18n_messages
|
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-21 18:48:00 -04:00
|
|
|
|
2018-12-05 13:03:27 -05:00
|
|
|
if is_legacy_ngc and _should_produce_flat_module_outs(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
if len(outs.metadata) > 1:
|
|
|
|
fail("expecting exactly one metadata output for " + str(ctx.label))
|
2018-03-15 21:04:34 -04:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
providers["angular"]["flat_module_metadata"] = struct(
|
|
|
|
module_name = ctx.attr.module_name,
|
|
|
|
metadata_file = outs.metadata[0],
|
|
|
|
typings_file = outs.bundle_index_typings,
|
|
|
|
flat_module_out_file = _flat_module_out_file(ctx),
|
|
|
|
)
|
2018-02-13 14:26:06 -05:00
|
|
|
|
2019-03-06 03:04:18 -05:00
|
|
|
if outs.dts_bundles != None:
|
|
|
|
providers["dts_bundles"] = outs.dts_bundles
|
2019-02-07 13:02:07 -05:00
|
|
|
|
2018-08-07 19:15:45 -04:00
|
|
|
return providers
|
2017-08-21 11:23:47 -04:00
|
|
|
|
2017-08-16 12:02:20 -04:00
|
|
|
def _ng_module_impl(ctx):
|
2018-08-07 19:15:45 -04:00
|
|
|
return ts_providers_dict_to_struct(ng_module_impl(ctx, compile_ts))
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2018-10-04 16:14:14 -04:00
|
|
|
local_deps_aspects = [collect_node_modules_aspect, _collect_summaries_aspect]
|
|
|
|
|
|
|
|
# Workaround skydoc bug which assumes DEPS_ASPECTS is a str type
|
|
|
|
[local_deps_aspects.append(a) for a in DEPS_ASPECTS]
|
|
|
|
|
2017-08-21 11:23:47 -04:00
|
|
|
NG_MODULE_ATTRIBUTES = {
|
|
|
|
"srcs": attr.label_list(allow_files = [".ts"]),
|
2019-02-26 07:30:44 -05:00
|
|
|
|
|
|
|
# Note: DEPS_ASPECTS is already a list, we add the cast to workaround
|
|
|
|
# https://github.com/bazelbuild/skydoc/issues/21
|
|
|
|
"deps": attr.label_list(
|
|
|
|
doc = "Targets that are imported by this target",
|
|
|
|
aspects = local_deps_aspects,
|
|
|
|
),
|
2018-04-25 12:23:20 -04:00
|
|
|
"assets": attr.label_list(
|
|
|
|
doc = ".html and .css files needed by the Angular compiler",
|
|
|
|
allow_files = [
|
|
|
|
".css",
|
|
|
|
# TODO(alexeagle): change this to ".ng.html" when usages updated
|
|
|
|
".html",
|
|
|
|
],
|
|
|
|
),
|
2019-02-26 07:30:44 -05:00
|
|
|
"factories": attr.label_list(
|
|
|
|
allow_files = [".ts", ".html"],
|
|
|
|
mandatory = False,
|
|
|
|
),
|
|
|
|
"filter_summaries": attr.bool(default = False),
|
|
|
|
"type_check": attr.bool(default = True),
|
|
|
|
"inline_resources": attr.bool(default = True),
|
|
|
|
"no_i18n": attr.bool(default = False),
|
2017-08-21 11:23:47 -04:00
|
|
|
"compiler": attr.label(
|
2018-10-16 16:20:00 -04:00
|
|
|
doc = """Sets a different ngc compiler binary to use for this library.
|
|
|
|
|
|
|
|
The default ngc compiler depends on the `@npm//@angular/bazel`
|
|
|
|
target which is setup for projects that use bazel managed npm deps that
|
|
|
|
fetch the @angular/bazel npm package. It is recommended that you use
|
|
|
|
the workspace name `@npm` for bazel managed deps so the default
|
|
|
|
compiler works out of the box. Otherwise, you'll have to override
|
|
|
|
the compiler attribute manually.
|
|
|
|
""",
|
2018-10-17 14:25:22 -04:00
|
|
|
default = Label(DEFAULT_NG_COMPILER),
|
2017-08-21 11:23:47 -04:00
|
|
|
executable = True,
|
|
|
|
cfg = "host",
|
|
|
|
),
|
2018-10-16 16:20:00 -04:00
|
|
|
"ng_xi18n": attr.label(
|
2018-10-17 14:25:22 -04:00
|
|
|
default = Label(DEFAULT_NG_XI18N),
|
2017-09-27 10:38:36 -04:00
|
|
|
executable = True,
|
|
|
|
cfg = "host",
|
|
|
|
),
|
2017-08-30 01:09:55 -04:00
|
|
|
"_supports_workers": attr.bool(default = True),
|
2017-08-21 11:23:47 -04:00
|
|
|
}
|
2017-08-16 12:02:20 -04:00
|
|
|
|
2018-02-16 11:45:21 -05:00
|
|
|
NG_MODULE_RULE_ATTRS = dict(dict(COMMON_ATTRIBUTES, **NG_MODULE_ATTRIBUTES), **{
|
2019-02-26 07:30:44 -05:00
|
|
|
"tsconfig": attr.label(allow_single_file = True),
|
2018-02-16 11:45:21 -05:00
|
|
|
"node_modules": attr.label(
|
2018-10-04 16:14:14 -04:00
|
|
|
doc = """The npm packages which should be available during the compile.
|
|
|
|
|
2018-10-18 12:58:38 -04:00
|
|
|
The default value of `@npm//typescript:typescript__typings` is
|
|
|
|
for projects that use bazel managed npm deps. It is recommended
|
2018-10-04 16:14:14 -04:00
|
|
|
that you use the workspace name `@npm` for bazel managed deps so the
|
2018-10-18 12:58:38 -04:00
|
|
|
default value works out of the box. Otherwise, you'll have to
|
2018-10-04 16:14:14 -04:00
|
|
|
override the node_modules attribute manually. This default is in place
|
2018-10-18 12:58:38 -04:00
|
|
|
since code compiled by ng_module will always depend on at least the
|
|
|
|
typescript default libs which are provided by
|
|
|
|
`@npm//typescript:typescript__typings`.
|
2018-10-04 16:14:14 -04:00
|
|
|
|
|
|
|
This attribute is DEPRECATED. As of version 0.18.0 the recommended
|
|
|
|
approach to npm dependencies is to use fine grained npm dependencies
|
|
|
|
which are setup with the `yarn_install` or `npm_install` rules.
|
|
|
|
|
|
|
|
For example, in targets that used a `//:node_modules` filegroup,
|
|
|
|
|
|
|
|
```
|
|
|
|
ng_module(
|
|
|
|
name = "my_lib",
|
|
|
|
...
|
2018-10-18 12:58:38 -04:00
|
|
|
node_modules = "//:node_modules",
|
2018-10-04 16:14:14 -04:00
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
which specifies all files within the `//:node_modules` filegroup
|
|
|
|
to be inputs to the `my_lib`. Using fine grained npm dependencies,
|
|
|
|
`my_lib` is defined with only the npm dependencies that are
|
|
|
|
needed:
|
|
|
|
|
|
|
|
```
|
|
|
|
ng_module(
|
|
|
|
name = "my_lib",
|
|
|
|
...
|
|
|
|
deps = [
|
|
|
|
"@npm//@types/foo",
|
|
|
|
"@npm//@types/bar",
|
|
|
|
"@npm//foo",
|
|
|
|
"@npm//bar",
|
|
|
|
...
|
|
|
|
],
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
In this case, only the listed npm packages and their
|
|
|
|
transitive deps are includes as inputs to the `my_lib` target
|
|
|
|
which reduces the time required to setup the runfiles for this
|
|
|
|
target (see https://github.com/bazelbuild/bazel/issues/5153).
|
|
|
|
The default typescript libs are also available via the node_modules
|
|
|
|
default in this case.
|
|
|
|
|
|
|
|
The @npm external repository and the fine grained npm package
|
|
|
|
targets are setup using the `yarn_install` or `npm_install` rule
|
|
|
|
in your WORKSPACE file:
|
|
|
|
|
|
|
|
yarn_install(
|
|
|
|
name = "npm",
|
|
|
|
package_json = "//:package.json",
|
|
|
|
yarn_lock = "//:yarn.lock",
|
|
|
|
)
|
|
|
|
""",
|
|
|
|
default = Label("@npm//typescript:typescript__typings"),
|
2018-02-16 11:45:21 -05:00
|
|
|
),
|
2019-06-07 16:38:06 -04:00
|
|
|
"entry_point": attr.label(allow_single_file = True),
|
2018-02-16 11:45:21 -05:00
|
|
|
|
2018-03-15 21:04:34 -04:00
|
|
|
# Default is %{name}_public_index
|
|
|
|
# The suffix points to the generated "bundle index" files that users import from
|
|
|
|
# The default is intended to avoid collisions with the users input files.
|
|
|
|
# Later packaging rules will point to these generated files as the entry point
|
|
|
|
# into the package.
|
|
|
|
# See the flatModuleOutFile documentation in
|
|
|
|
# https://github.com/angular/angular/blob/master/packages/compiler-cli/src/transformers/api.ts
|
|
|
|
"flat_module_out_file": attr.string(),
|
2019-02-07 13:02:07 -05:00
|
|
|
"bundle_dts": attr.bool(default = False),
|
2019-03-09 07:24:20 -05:00
|
|
|
"api_extractor": attr.label(
|
|
|
|
default = Label(DEFAULT_API_EXTRACTOR),
|
2019-02-12 16:49:23 -05:00
|
|
|
executable = True,
|
|
|
|
cfg = "host",
|
|
|
|
),
|
2018-02-16 11:45:21 -05:00
|
|
|
})
|
|
|
|
|
2017-08-16 12:02:20 -04:00
|
|
|
ng_module = rule(
|
|
|
|
implementation = _ng_module_impl,
|
2018-02-16 11:45:21 -05:00
|
|
|
attrs = NG_MODULE_RULE_ATTRS,
|
|
|
|
outputs = COMMON_OUTPUTS,
|
|
|
|
)
|
2018-04-25 12:23:20 -04:00
|
|
|
"""
|
|
|
|
Run the Angular AOT template compiler.
|
2018-02-16 11:45:21 -05:00
|
|
|
|
2018-04-25 12:23:20 -04:00
|
|
|
This rule extends the [ts_library] rule.
|
|
|
|
|
|
|
|
[ts_library]: http://tsetse.info/api/build_defs.html#ts_library
|
|
|
|
"""
|
2019-04-02 14:42:58 -04:00
|
|
|
|
|
|
|
def ng_module_macro(tsconfig = None, **kwargs):
|
|
|
|
"""Wraps `ng_module` to set the default for the `tsconfig` attribute.
|
|
|
|
|
|
|
|
This must be a macro so that the string is converted to a label in the context of the
|
|
|
|
workspace that declares the `ng_module` target, rather than the workspace that defines
|
|
|
|
`ng_module`, or the workspace where the build is taking place.
|
|
|
|
|
|
|
|
This macro is re-exported as `ng_module` in the public API.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
tsconfig: the label pointing to a tsconfig.json file
|
|
|
|
**kwargs: remaining args to pass to the ng_module rule
|
|
|
|
"""
|
|
|
|
if not tsconfig:
|
|
|
|
tsconfig = "//:tsconfig.json"
|
|
|
|
|
|
|
|
ng_module(tsconfig = tsconfig, **kwargs)
|