build(bazel): update to bazel 0.27.0 and fix compat in @angular/bazel package (#31019)

ctx.actions.declare_file now used in @angular/bazel ng_module rule as ctx.new_file is now deprecated. Fixes error:

```
        File "ng_module.bzl", line 272, in _expected_outs
                ctx.new_file(ctx.genfiles_dir, (ctx.label.name ..."))
Use ctx.actions.declare_file instead of ctx.new_file.
Use --incompatible_new_actions_api=false to temporarily disable this check.
```

This can be worked around with incompatible_new_actions_api flag but may as well fix it proper so downstream doesn't require this flag due to this code.

Also, depset() is no longer iterable by default without a flag. This required fixing in a few spots in @angular/bazel.

fix: foo

PR Close #31019
This commit is contained in:
Greg Magolan
2019-06-12 18:18:26 -07:00
committed by Kara Erickson
parent f7e9659c4d
commit 28d3bfc416
12 changed files with 51 additions and 29 deletions

View File

@ -49,7 +49,7 @@ Try running `yarn bazel` instead.
(If you did run that, check that you've got a fresh `yarn install`)
""",
minimum_bazel_version = "0.26.0",
minimum_bazel_version = "0.27.0",
)
# Setup the Node repositories. We need a NodeJS version that is more recent than v10.15.0

View File

@ -33,3 +33,6 @@ build --define=compile=legacy
# Turn on managed directories feature in Bazel
# This allows us to avoid installing a second copy of node_modules
common --experimental_allow_incremental_repository_updates
# Compatibility flag for Bazel 0.27.0
common --incompatible_depset_is_not_iterable=false

View File

@ -269,7 +269,7 @@ def _expected_outs(ctx):
# TODO(alxhub): i18n is only produced by the legacy compiler currently. This should be re-enabled
# when ngtsc can extract messages
if is_legacy_ngc:
i18n_messages_files = [ctx.new_file(ctx.genfiles_dir, ctx.label.name + "_ngc_messages.xmb")]
i18n_messages_files = [ctx.actions.declare_file(ctx.label.name + "_ngc_messages.xmb")]
else:
i18n_messages_files = []
@ -442,7 +442,7 @@ def ngc_compile_action(
if dts_bundles_out != None:
# combine the inputs and outputs and filter .d.ts and json files
filter_inputs = [f for f in list(inputs) + outputs if f.path.endswith(".d.ts") or f.path.endswith(".json")]
filter_inputs = [f for f in inputs.to_list() + outputs if f.path.endswith(".d.ts") or f.path.endswith(".json")]
if _should_produce_flat_module_outs(ctx):
dts_entry_points = ["%s.d.ts" % _flat_module_out_file(ctx)]

View File

@ -94,6 +94,10 @@ WELL_KNOWN_GLOBALS = {p: _global_name(p) for p in [
"rxjs/operators",
]}
# skydoc fails with type(depset()) so using "depset" here instead
# TODO(gregmagolan): clean this up
_DEPSET_TYPE = "depset"
def _rollup(ctx, bundle_name, rollup_config, entry_point, inputs, js_output, format = "es", package_name = "", include_tslib = False):
map_output = ctx.actions.declare_file(js_output.basename + ".map", sibling = js_output)
@ -133,7 +137,7 @@ def _rollup(ctx, bundle_name, rollup_config, entry_point, inputs, js_output, for
args.add("--silent")
other_inputs = [ctx.executable._rollup, rollup_config]
other_inputs = [rollup_config]
if ctx.file.license_banner:
other_inputs.append(ctx.file.license_banner)
if ctx.version_file:
@ -144,6 +148,7 @@ def _rollup(ctx, bundle_name, rollup_config, entry_point, inputs, js_output, for
inputs = inputs.to_list() + other_inputs,
outputs = [js_output, map_output],
executable = ctx.executable._rollup,
tools = [ctx.executable._rollup],
arguments = [args],
)
return struct(
@ -165,7 +170,8 @@ def _flatten_paths(directory):
# Optionally can filter out files that do not belong to a specified package path.
def _filter_out_generated_files(files, extension, package_path = None):
result = []
for file in files:
files_list = files.to_list() if type(files) == _DEPSET_TYPE else files
for file in files_list:
# If the "package_path" parameter has been specified, filter out files
# that do not start with the the specified package path.
if package_path and not file.short_path.startswith(package_path):
@ -183,9 +189,10 @@ def _esm2015_root_dir(ctx):
return ctx.label.name + ".es6"
def _filter_js_inputs(all_inputs):
all_inputs_list = all_inputs.to_list() if type(all_inputs) == _DEPSET_TYPE else all_inputs
return [
f
for f in all_inputs
for f in all_inputs_list
if f.path.endswith(".js") or f.path.endswith(".json")
]

View File

@ -48,7 +48,7 @@ function addDevDependenciesToPackageJson(options: Schema) {
const devDependencies: {[k: string]: string} = {
'@angular/bazel': angularCoreVersion,
'@bazel/bazel': '^0.26.0',
'@bazel/bazel': '^0.27.0',
'@bazel/ibazel': '^0.10.2',
'@bazel/karma': '0.31.1',
'@bazel/typescript': '0.31.1',

View File

@ -113,6 +113,7 @@ describe('ng-add schematic', () => {
const json = JSON.parse(content);
const devDeps = Object.keys(json.devDependencies);
expect(devDeps).toContain('@bazel/bazel');
expect(devDeps).toContain('@bazel/hide-bazel-files');
expect(devDeps).toContain('@bazel/ibazel');
expect(devDeps).toContain('@bazel/karma');
});