build: make api-extractor work in google3 (#28588)

PR Close #28588
This commit is contained in:
Alex Eagle 2019-02-12 13:49:23 -08:00 committed by Misko Hevery
parent 9e5d1357fe
commit 8cec4b3ff7
2 changed files with 14 additions and 12 deletions

View File

@ -41,6 +41,7 @@ merge:
exclude: exclude:
- "packages/*" - "packages/*"
- "packages/bazel/*" - "packages/bazel/*"
- "packages/bazel/src/api-extractor/**"
- "packages/bazel/src/builders/**" - "packages/bazel/src/builders/**"
- "packages/bazel/src/ng_package/**" - "packages/bazel/src/ng_package/**"
- "packages/bazel/src/protractor/**" - "packages/bazel/src/protractor/**"

View File

@ -12,7 +12,6 @@ load(
"DEFAULT_NG_COMPILER", "DEFAULT_NG_COMPILER",
"DEFAULT_NG_XI18N", "DEFAULT_NG_XI18N",
"DEPS_ASPECTS", "DEPS_ASPECTS",
"FLAT_DTS_FILE_SUFFIX",
"NodeModuleInfo", "NodeModuleInfo",
"collect_node_modules_aspect", "collect_node_modules_aspect",
"compile_ts", "compile_ts",
@ -20,6 +19,8 @@ load(
"tsc_wrapped_tsconfig", "tsc_wrapped_tsconfig",
) )
_FLAT_DTS_FILE_SUFFIX = ".bundle.d.ts"
def compile_strategy(ctx): def compile_strategy(ctx):
"""Detect which strategy should be used to implement ng_module. """Detect which strategy should be used to implement ng_module.
@ -138,7 +139,7 @@ def _should_produce_dts_bundle(ctx):
# At the moment we cannot use this with ngtsc compiler since it emits # At the moment we cannot use this with ngtsc compiler since it emits
# import * as ___ from local modules which is not supported # import * as ___ from local modules which is not supported
# see: https://github.com/Microsoft/web-build-tools/issues/1029 # see: https://github.com/Microsoft/web-build-tools/issues/1029
return _is_legacy_ngc(ctx) and ctx.attr.bundle_dts return _is_legacy_ngc(ctx) and hasattr(ctx.attr, "bundle_dts") and ctx.attr.bundle_dts
def _should_produce_flat_module_outs(ctx): def _should_produce_flat_module_outs(ctx):
"""Should we produce flat module outputs. """Should we produce flat module outputs.
@ -225,7 +226,7 @@ def _expected_outs(ctx):
# The flat module dts out contains several other exports # The flat module dts out contains several other exports
# https://github.com/angular/angular/blob/master/packages/compiler-cli/src/metadata/index_writer.ts#L18 # https://github.com/angular/angular/blob/master/packages/compiler-cli/src/metadata/index_writer.ts#L18
# the file name will be like 'core.bundle.d.ts' # the file name will be like 'core.bundle.d.ts'
dts_bundle = ctx.actions.declare_file(ctx.label.name + FLAT_DTS_FILE_SUFFIX) dts_bundle = ctx.actions.declare_file(ctx.label.name + _FLAT_DTS_FILE_SUFFIX)
# We do this just when producing a flat module index for a publishable ng_module # We do this just when producing a flat module index for a publishable ng_module
if _should_produce_flat_module_outs(ctx): if _should_produce_flat_module_outs(ctx):
@ -330,12 +331,12 @@ def ngc_compile_action(
label, label,
inputs, inputs,
outputs, outputs,
dts_bundle_out,
messages_out, messages_out,
tsconfig_file, tsconfig_file,
node_opts, node_opts,
locale = None, locale = None,
i18n_args = []): i18n_args = [],
dts_bundle_out = None):
"""Helper function to create the ngc action. """Helper function to create the ngc action.
This is exposed for google3 to wire up i18n replay rules, and is not intended This is exposed for google3 to wire up i18n replay rules, and is not intended
@ -346,12 +347,12 @@ def ngc_compile_action(
label: the label of the ng_module being compiled label: the label of the ng_module being compiled
inputs: passed to the ngc action's inputs inputs: passed to the ngc action's inputs
outputs: passed to the ngc action's outputs outputs: passed to the ngc action's outputs
dts_bundle_out: produced flattened dts file
messages_out: produced xmb files messages_out: produced xmb files
tsconfig_file: tsconfig file with settings used for the compilation tsconfig_file: tsconfig file with settings used for the compilation
node_opts: list of strings, extra nodejs options. node_opts: list of strings, extra nodejs options.
locale: i18n locale, or None locale: i18n locale, or None
i18n_args: additional command-line arguments to ngc i18n_args: additional command-line arguments to ngc
dts_bundle_out: produced flattened dts file
Returns: Returns:
the parameters of the compilation which will be used to replay the ngc action for i18N. the parameters of the compilation which will be used to replay the ngc action for i18N.
@ -479,7 +480,7 @@ def _compile_action(ctx, inputs, outputs, dts_bundle_out, messages_out, tsconfig
], ],
) )
return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, dts_bundle_out, messages_out, tsconfig_file, node_opts) return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, tsconfig_file, node_opts, None, [], dts_bundle_out)
def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts): def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
outs = _expected_outs(ctx) outs = _expected_outs(ctx)
@ -606,11 +607,6 @@ NG_MODULE_ATTRIBUTES = {
executable = True, executable = True,
cfg = "host", cfg = "host",
), ),
"_api_extractor": attr.label(
default = Label("//packages/bazel/src/api-extractor:api_extractor"),
executable = True,
cfg = "host",
),
"_supports_workers": attr.bool(default = True), "_supports_workers": attr.bool(default = True),
} }
@ -691,6 +687,11 @@ NG_MODULE_RULE_ATTRS = dict(dict(COMMON_ATTRIBUTES, **NG_MODULE_ATTRIBUTES), **{
# https://github.com/angular/angular/blob/master/packages/compiler-cli/src/transformers/api.ts # https://github.com/angular/angular/blob/master/packages/compiler-cli/src/transformers/api.ts
"flat_module_out_file": attr.string(), "flat_module_out_file": attr.string(),
"bundle_dts": attr.bool(default = False), "bundle_dts": attr.bool(default = False),
"_api_extractor": attr.label(
default = Label("//packages/bazel/src/api-extractor:api_extractor"),
executable = True,
cfg = "host",
),
}) })
ng_module = rule( ng_module = rule(