style: format .bzl files with buildifier (#23544)

PR Close #23544
This commit is contained in:
Alex Eagle 2018-08-07 16:15:45 -07:00 committed by Kara Erickson
parent 090824526b
commit a3f1e2cb42
16 changed files with 1329 additions and 1239 deletions

View File

@ -12,11 +12,13 @@ from source downstream. Alternately, this API is available from the
used in a downstream project.
"""
load("//packages/bazel:index.bzl",
load(
"//packages/bazel:index.bzl",
_ng_module = "ng_module",
_ng_package = "ng_package",
_protractor_web_test = "protractor_web_test",
_protractor_web_test_suite = "protractor_web_test_suite")
_protractor_web_test_suite = "protractor_web_test_suite",
)
load("//tools:ng_setup_workspace.bzl", _ng_setup_workspace = "ng_setup_workspace")
ng_module = _ng_module

View File

@ -10,9 +10,11 @@ Users should not load files under "/src"
load("//packages/bazel/src:ng_module.bzl", _ng_module = "ng_module")
load("//packages/bazel/src:ng_setup_workspace.bzl", _ng_setup_workspace = "ng_setup_workspace")
load("//packages/bazel/src/ng_package:ng_package.bzl", _ng_package = "ng_package")
load("//packages/bazel/src/protractor:protractor_web_test.bzl",
load(
"//packages/bazel/src/protractor:protractor_web_test.bzl",
_protractor_web_test = "protractor_web_test",
_protractor_web_test_suite = "protractor_web_test_suite")
_protractor_web_test_suite = "protractor_web_test_suite",
)
ng_module = _ng_module
ng_package = _ng_package

View File

@ -29,6 +29,7 @@ ESM5Info = provider(
def _map_closure_path(file):
result = file.short_path[:-len(".closure.js")]
# short_path is meant to be used when accessing runfiles in a binary, where
# the CWD is inside the current repo. Therefore files in external repo have a
# short_path of ../external/wkspc/path/to/package
@ -54,9 +55,11 @@ def _esm5_outputs_aspect(target, ctx):
if workspace:
out_dir = out_dir + "/" + workspace
outputs = [ctx.actions.declare_file(_join([out_dir, _map_closure_path(f)]))
outputs = [
ctx.actions.declare_file(_join([out_dir, _map_closure_path(f)]))
for f in target.typescript.replay_params.outputs
if not f.short_path.endswith(".externs.js")]
if not f.short_path.endswith(".externs.js")
]
ctx.actions.run(
executable = ctx.executable._modify_tsconfig,
@ -66,7 +69,7 @@ def _esm5_outputs_aspect(target, ctx):
target.typescript.replay_params.tsconfig.path,
tsconfig.path,
_join([workspace, target.label.package, ctx.label.name + ".esm5"]),
ctx.bin_dir.path
ctx.bin_dir.path,
],
)
@ -89,7 +92,7 @@ def _esm5_outputs_aspect(target, ctx):
ctx.label.name + ".esm5",
])
transitive_output={root_dir: depset(outputs)}
transitive_output = {root_dir: depset(outputs)}
for dep in ctx.rule.attr.deps:
if ESM5Info in dep:
transitive_output.update(dep[ESM5Info].transitive_output)
@ -104,12 +107,13 @@ def _esm5_outputs_aspect(target, ctx):
esm5_outputs_aspect = aspect(
implementation = _esm5_outputs_aspect,
# Recurse to the deps of any target we visit
attr_aspects = ['deps'],
attr_aspects = ["deps"],
attrs = {
"_modify_tsconfig": attr.label(
default = Label("//packages/bazel/src:modify_tsconfig"),
executable = True,
cfg = "host"),
cfg = "host",
),
# We must list tsc_wrapped here to ensure it's built before the action runs
# For some reason, having the compiler output as an input to the action above
# is not sufficient.
@ -161,6 +165,7 @@ def flatten_esm5(ctx):
path = "external/" + path[3:]
rerooted_file = ctx.actions.declare_file("/".join([esm5_root_dir(ctx), path]))
result.append(rerooted_file)
# print("copy", f.short_path, "to", rerooted_file.short_path)
ctx.actions.expand_template(
output = rerooted_file,

View File

@ -5,13 +5,14 @@
"""Run Angular's AOT template compiler
"""
load(":rules_typescript.bzl",
"tsc_wrapped_tsconfig",
load(
":rules_typescript.bzl",
"COMMON_ATTRIBUTES",
"COMMON_OUTPUTS",
"compile_ts",
"DEPS_ASPECTS",
"compile_ts",
"ts_providers_dict_to_struct",
"tsc_wrapped_tsconfig",
)
def compile_strategy(ctx):
@ -28,15 +29,15 @@ def compile_strategy(ctx):
one of 'legacy', 'local', 'jit', or 'global' depending on the configuration in ctx
"""
strategy = 'legacy'
if 'compile' in ctx.var:
strategy = ctx.var['compile']
strategy = "legacy"
if "compile" in ctx.var:
strategy = ctx.var["compile"]
if strategy not in ['legacy', 'local', 'jit']:
if strategy not in ["legacy", "local", "jit"]:
fail("Unknown --define=compile value '%s'" % strategy)
if strategy == 'legacy' and hasattr(ctx.attr, '_global_mode') and ctx.attr._global_mode:
strategy = 'global'
if strategy == "legacy" and hasattr(ctx.attr, "_global_mode") and ctx.attr._global_mode:
strategy = "global"
return strategy
@ -51,16 +52,16 @@ def _compiler_name(ctx):
"""
strategy = compile_strategy(ctx)
if strategy == 'legacy':
return 'ngc'
elif strategy == 'global':
return 'ngc.ivy'
elif strategy == 'local':
return 'ngtsc'
elif strategy == 'jit':
return 'tsc'
if strategy == "legacy":
return "ngc"
elif strategy == "global":
return "ngc.ivy"
elif strategy == "local":
return "ngtsc"
elif strategy == "jit":
return "tsc"
else:
fail('unreachable')
fail("unreachable")
def _enable_ivy_value(ctx):
"""Determines the value of the enableIvy option in the generated tsconfig.
@ -73,16 +74,16 @@ def _enable_ivy_value(ctx):
"""
strategy = compile_strategy(ctx)
if strategy == 'legacy':
if strategy == "legacy":
return False
elif strategy == 'global':
elif strategy == "global":
return True
elif strategy == 'local':
return 'ngtsc'
elif strategy == 'jit':
return 'tsc'
elif strategy == "local":
return "ngtsc"
elif strategy == "jit":
return "tsc"
else:
fail('unreachable')
fail("unreachable")
def _include_ng_files(ctx):
"""Determines whether Angular outputs will be produced by the current compilation strategy.
@ -96,7 +97,7 @@ def _include_ng_files(ctx):
"""
strategy = compile_strategy(ctx)
return strategy == 'legacy' or strategy == 'global'
return strategy == "legacy" or strategy == "global"
def _basename_of(ctx, file):
ext_len = len(".ts")
@ -243,17 +244,18 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
"enableIvy": _enable_ivy_value(ctx),
"fullTemplateTypeCheck": ctx.attr.type_check,
# FIXME: wrong place to de-dupe
"expectedOut": depset([o.path for o in expected_outs]).to_list()
"expectedOut": depset([o.path for o in expected_outs]).to_list(),
}
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, ""])
[ctx.workspace_name] + ctx.label.package.split("/") + [ctx.label.name, ""],
)
return dict(tsc_wrapped_tsconfig(ctx, files, srcs, **kwargs), **{
"angularCompilerOptions": angular_compiler_options
"angularCompilerOptions": angular_compiler_options,
})
def _collect_summaries_aspect_impl(target, ctx):
@ -278,11 +280,19 @@ _collect_summaries_aspect = aspect(
# Extra options passed to Node when running ngc.
_EXTRA_NODE_OPTIONS_FLAGS = [
# Expose the v8 garbage collection API to JS.
"--node_options=--expose-gc"
"--node_options=--expose-gc",
]
def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file,
node_opts, locale=None, i18n_args=[]):
def ngc_compile_action(
ctx,
label,
inputs,
outputs,
messages_out,
tsconfig_file,
node_opts,
locale = None,
i18n_args = []):
"""Helper function to create the ngc action.
This is exposed for google3 to wire up i18n replay rules, and is not intended
@ -318,6 +328,7 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file,
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.
@ -352,7 +363,8 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file,
# point to genfiles/ to redirect the output.
["../genfiles/" + messages_out[0].short_path]),
progress_message = "Extracting Angular 2 messages (ng_xi18n)",
mnemonic = "Angular2MessageExtractor")
mnemonic = "Angular2MessageExtractor",
)
if not locale and not ctx.attr.no_i18n:
return struct(
@ -372,21 +384,28 @@ def _compile_action(ctx, inputs, outputs, messages_out, tsconfig_file, node_opts
# 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.
if hasattr(ctx.attr, "node_modules"):
file_inputs += [f for f in ctx.files.node_modules
if f.path.endswith(".ts") or f.path.endswith(".json")]
file_inputs += [
f
for f in ctx.files.node_modules
if f.path.endswith(".ts") or f.path.endswith(".json")
]
# 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)
# Collect the inputs and summary files from our deps
action_inputs = depset(file_inputs,
transitive = [inputs] + [dep.collect_summaries_aspect_result for dep in ctx.attr.deps
if hasattr(dep, "collect_summaries_aspect_result")])
action_inputs = depset(
file_inputs,
transitive = [inputs] + [
dep.collect_summaries_aspect_result
for dep in ctx.attr.deps
if hasattr(dep, "collect_summaries_aspect_result")
],
)
return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, tsconfig_file, node_opts)
def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
outs = _expected_outs(ctx)
return _compile_action(ctx, inputs, outputs + outs.closure_js, outs.i18n_messages, tsconfig_file, node_opts)
@ -420,17 +439,20 @@ def ng_module_impl(ctx, ts_compile_actions):
include_ng_files = _include_ng_files(ctx)
providers = ts_compile_actions(
ctx, is_library=True, compile_action=_prodmode_compile_action,
devmode_compile_action=_devmode_compile_action,
tsc_wrapped_tsconfig=_ngc_tsconfig,
outputs = _ts_expected_outs)
ctx,
is_library = True,
compile_action = _prodmode_compile_action,
devmode_compile_action = _devmode_compile_action,
tsc_wrapped_tsconfig = _ngc_tsconfig,
outputs = _ts_expected_outs,
)
outs = _expected_outs(ctx)
if include_ng_files:
providers["angular"] = {
"summaries": outs.summaries,
"metadata": outs.metadata
"metadata": outs.metadata,
}
providers["ngc_messages"] = outs.i18n_messages
@ -457,9 +479,8 @@ NG_MODULE_ATTRIBUTES = {
# https://github.com/bazelbuild/skydoc/issues/21
"deps": attr.label_list(
doc = "Targets that are imported by this target",
aspects = list(DEPS_ASPECTS) + [_collect_summaries_aspect]
aspects = list(DEPS_ASPECTS) + [_collect_summaries_aspect],
),
"assets": attr.label_list(
doc = ".html and .css files needed by the Angular compiler",
allow_files = [
@ -468,31 +489,24 @@ NG_MODULE_ATTRIBUTES = {
".html",
],
),
"factories": attr.label_list(
allow_files = [".ts", ".html"],
mandatory = False),
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),
"compiler": attr.label(
default = Label("//packages/bazel/src/ngc-wrapped"),
executable = True,
cfg = "host",
),
"_ng_xi18n": attr.label(
default = Label("//packages/bazel/src/ngc-wrapped:xi18n"),
executable = True,
cfg = "host",
),
"_supports_workers": attr.bool(default = True),
}
@ -503,9 +517,8 @@ NG_MODULE_RULE_ATTRS = dict(dict(COMMON_ATTRIBUTES, **NG_MODULE_ATTRIBUTES), **{
# The default assumes the user specified a target "node_modules" in their
# root BUILD file.
"node_modules": attr.label(
default = Label("@//:node_modules")
default = Label("@//:node_modules"),
),
"entry_point": attr.string(),
# Default is %{name}_public_index

View File

@ -14,21 +14,26 @@ specification of this format at https://goo.gl/jB3GVv
"""
load("@build_bazel_rules_nodejs//:internal/collect_es6_sources.bzl", "collect_es6_sources")
load("@build_bazel_rules_nodejs//:internal/rollup/rollup_bundle.bzl",
"write_rollup_config",
load(
"@build_bazel_rules_nodejs//:internal/rollup/rollup_bundle.bzl",
"ROLLUP_ATTRS",
"rollup_module_mappings_aspect",
"run_uglify",
"ROLLUP_ATTRS")
load("@build_bazel_rules_nodejs//:internal/npm_package/npm_package.bzl",
"write_rollup_config",
)
load(
"@build_bazel_rules_nodejs//:internal/npm_package/npm_package.bzl",
"NPM_PACKAGE_ATTRS",
"NPM_PACKAGE_OUTPUTS",
"create_package")
"create_package",
)
load("@build_bazel_rules_nodejs//:internal/node.bzl", "sources_aspect")
load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "flatten_esm5", "esm5_root_dir")
load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "esm5_root_dir", "flatten_esm5")
# Convert from some-dash-case to someCamelCase
def _convert_dash_case_to_camel_case(s):
parts = s.split("-")
# First letter in the result is always unchanged
return s[0] + "".join([p.title() for p in parts])[1:]
@ -48,7 +53,7 @@ def _global_name(package_name):
result_parts.append(_convert_dash_case_to_camel_case(p))
return ".".join(result_parts)
WELL_KNOWN_GLOBALS = { p: _global_name(p) for p in [
WELL_KNOWN_GLOBALS = {p: _global_name(p) for p in [
"@angular/upgrade",
"@angular/upgrade/static",
"@angular/forms",
@ -106,12 +111,13 @@ def _rollup(ctx, bundle_name, rollup_config, entry_point, inputs, js_output, for
external = globals.keys()
if not include_tslib:
external.append("tslib")
args.add_joined("--external", external, join_with=",")
args.add_joined("--external", external, join_with = ",")
args.add_joined(
"--globals",
["%s:%s" % g for g in globals.items()],
join_with=",")
join_with = ",",
)
args.add("--silent")
@ -143,20 +149,17 @@ def _flatten_paths(directory):
result.append(f.map.path)
return result
# takes an depset of files and returns an array that doesn't contain any generated files by ngc
def _filter_out_generated_files(files):
result = []
for file in files:
if (not(file.path.endswith(".ngfactory.js") or file.path.endswith(".ngsummary.js") or file.path.endswith(".ngstyle.js"))):
if (not (file.path.endswith(".ngfactory.js") or file.path.endswith(".ngsummary.js") or file.path.endswith(".ngstyle.js"))):
result.append(file)
return depset(result)
def _esm2015_root_dir(ctx):
return ctx.label.name + ".es6"
# ng_package produces package that is npm-ready.
def _ng_package_impl(ctx):
npm_package_directory = ctx.actions.declare_directory("%s.ng_pkg" % ctx.label.name)
@ -186,6 +189,7 @@ def _ng_package_impl(ctx):
# - in this package or a subpackage
# - those that have a module_name attribute (they produce flat module metadata)
flat_module_metadata = []
# Name given in the package.json name field, eg. @angular/core/testing
package_name = ""
deps_in_package = [d for d in ctx.attr.deps if d.label.package.startswith(ctx.label.package)]
@ -231,28 +235,45 @@ def _ng_package_impl(ctx):
umd_output = ctx.outputs.umd
min_output = ctx.outputs.umd_min
esm2015_config = write_rollup_config(ctx, [], "/".join([ctx.bin_dir.path, ctx.label.package, _esm2015_root_dir(ctx)]), filename="_%s.rollup_esm2015.conf.js")
esm5_config = write_rollup_config(ctx, [], "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]), filename="_%s.rollup_esm5.conf.js")
esm2015_config = write_rollup_config(ctx, [], "/".join([ctx.bin_dir.path, ctx.label.package, _esm2015_root_dir(ctx)]), filename = "_%s.rollup_esm2015.conf.js")
esm5_config = write_rollup_config(ctx, [], "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]), filename = "_%s.rollup_esm5.conf.js")
fesm2015.append(_rollup(ctx, "fesm2015", esm2015_config, es2015_entry_point, esm_2015_files + ctx.files.node_modules, fesm2015_output))
fesm5.append(_rollup(ctx, "fesm5", esm5_config, es5_entry_point, esm5_sources + ctx.files.node_modules, fesm5_output))
bundles.append(
_rollup(ctx, "umd", esm5_config, es5_entry_point, esm5_sources + ctx.files.node_modules, umd_output,
format = "umd", package_name = package_name, include_tslib = True))
uglify_sourcemap = run_uglify(ctx, umd_output, min_output,
config_name = entry_point.replace("/", "_"))
_rollup(
ctx,
"umd",
esm5_config,
es5_entry_point,
esm5_sources + ctx.files.node_modules,
umd_output,
format = "umd",
package_name = package_name,
include_tslib = True,
),
)
uglify_sourcemap = run_uglify(
ctx,
umd_output,
min_output,
config_name = entry_point.replace("/", "_"),
)
bundles.append(struct(js = min_output, map = uglify_sourcemap))
packager_inputs = (
ctx.files.srcs +
ctx.files.data +
esm5_sources.to_list() +
depset(transitive = [d.typescript.transitive_declarations
depset(transitive = [
d.typescript.transitive_declarations
for d in ctx.attr.deps
if hasattr(d, "typescript")]).to_list() +
if hasattr(d, "typescript")
]).to_list() +
[f.js for f in fesm2015 + fesm5 + esm2015 + esm5 + bundles] +
[f.map for f in fesm2015 + fesm5 + esm2015 + esm5 + bundles if f.map])
[f.map for f in fesm2015 + fesm5 + esm2015 + esm5 + bundles if f.map]
)
packager_args = ctx.actions.args()
packager_args.use_param_file("%s", use_always = True)
@ -260,8 +281,8 @@ def _ng_package_impl(ctx):
# The order of arguments matters here, as they are read in order in packager.ts.
packager_args.add(npm_package_directory.path)
packager_args.add(ctx.label.package)
packager_args.add_joined([ctx.bin_dir.path, ctx.label.package], join_with="/")
packager_args.add_joined([ctx.genfiles_dir.path, ctx.label.package], join_with="/")
packager_args.add_joined([ctx.bin_dir.path, ctx.label.package], join_with = "/")
packager_args.add_joined([ctx.genfiles_dir.path, ctx.label.package], join_with = "/")
# Marshal the metadata into a JSON string so we can parse the data structure
# in the TypeScript program easily.
@ -282,15 +303,15 @@ def _ng_package_impl(ctx):
# placeholder
packager_args.add("")
packager_args.add_joined(_flatten_paths(fesm2015), join_with=",")
packager_args.add_joined(_flatten_paths(fesm5), join_with=",")
packager_args.add_joined(_flatten_paths(esm2015), join_with=",")
packager_args.add_joined(_flatten_paths(esm5), join_with=",")
packager_args.add_joined(_flatten_paths(bundles), join_with=",")
packager_args.add_joined([s.path for s in ctx.files.srcs], join_with=",")
packager_args.add_joined(_flatten_paths(fesm2015), join_with = ",")
packager_args.add_joined(_flatten_paths(fesm5), join_with = ",")
packager_args.add_joined(_flatten_paths(esm2015), join_with = ",")
packager_args.add_joined(_flatten_paths(esm5), join_with = ",")
packager_args.add_joined(_flatten_paths(bundles), join_with = ",")
packager_args.add_joined([s.path for s in ctx.files.srcs], join_with = ",")
# TODO: figure out a better way to gather runfiles providers from the transitive closure.
packager_args.add_joined([d.path for d in ctx.files.data], join_with=",")
packager_args.add_joined([d.path for d in ctx.files.data], join_with = ",")
if ctx.file.license_banner:
packager_inputs.append(ctx.file.license_banner)
@ -317,9 +338,10 @@ def _ng_package_impl(ctx):
package_dir = create_package(
ctx,
devfiles.to_list(),
[npm_package_directory] + ctx.files.packages)
[npm_package_directory] + ctx.files.packages,
)
return [DefaultInfo(
files = depset([package_dir])
files = depset([package_dir]),
)]
NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{
@ -335,22 +357,29 @@ NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{
),
"include_devmode_srcs": attr.bool(default = False),
"readme_md": attr.label(allow_single_file = FileType([".md"])),
"globals": attr.string_dict(default={}),
"globals": attr.string_dict(default = {}),
"entry_point_name": attr.string(
doc = "Name to use when generating bundle files for the primary entry-point.",
),
"_ng_packager": attr.label(
default=Label("//packages/bazel/src/ng_package:packager"),
executable=True, cfg="host"),
default = Label("//packages/bazel/src/ng_package:packager"),
executable = True,
cfg = "host",
),
"_rollup": attr.label(
default=Label("@build_bazel_rules_nodejs//internal/rollup"),
executable=True, cfg="host"),
default = Label("@build_bazel_rules_nodejs//internal/rollup"),
executable = True,
cfg = "host",
),
"_rollup_config_tmpl": attr.label(
default=Label("@build_bazel_rules_nodejs//internal/rollup:rollup.config.js"),
allow_single_file=True),
default = Label("@build_bazel_rules_nodejs//internal/rollup:rollup.config.js"),
allow_single_file = True,
),
"_uglify": attr.label(
default=Label("@build_bazel_rules_nodejs//internal/rollup:uglify"),
executable=True, cfg="host"),
default = Label("@build_bazel_rules_nodejs//internal/rollup:uglify"),
executable = True,
cfg = "host",
),
}))
# Angular wants these named after the entry_point,

View File

@ -14,22 +14,25 @@
[rollup_bundle]: https://bazelbuild.github.io/rules_nodejs/rollup/rollup_bundle.html
"""
load("@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl",
"rollup_module_mappings_aspect",
load(
"@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl",
"ROLLUP_ATTRS",
"ROLLUP_OUTPUTS",
"write_rollup_config",
"rollup_module_mappings_aspect",
"run_rollup",
"run_sourcemapexplorer",
"run_uglify",
"run_sourcemapexplorer")
"write_rollup_config",
)
load("@build_bazel_rules_nodejs//internal:collect_es6_sources.bzl", collect_es2015_sources = "collect_es6_sources")
load(":esm5.bzl", "esm5_outputs_aspect", "flatten_esm5", "esm5_root_dir")
load(":esm5.bzl", "esm5_outputs_aspect", "esm5_root_dir", "flatten_esm5")
PACKAGES=["packages/core/src", "packages/common/src", "packages/compiler/src", "external/rxjs"]
PLUGIN_CONFIG="{sideEffectFreeModules: [\n%s]}" % ",\n".join(
[" '.esm5/{0}'".format(p) for p in PACKAGES])
BO_ROLLUP="angular_cli/packages/angular_devkit/build_optimizer/src/build-optimizer/rollup-plugin.js"
BO_PLUGIN="require('%s').default(%s)" % (BO_ROLLUP, PLUGIN_CONFIG)
PACKAGES = ["packages/core/src", "packages/common/src", "packages/compiler/src", "external/rxjs"]
PLUGIN_CONFIG = "{sideEffectFreeModules: [\n%s]}" % ",\n".join(
[" '.esm5/{0}'".format(p) for p in PACKAGES],
)
BO_ROLLUP = "angular_cli/packages/angular_devkit/build_optimizer/src/build-optimizer/rollup-plugin.js"
BO_PLUGIN = "require('%s').default(%s)" % (BO_ROLLUP, PLUGIN_CONFIG)
def _use_plain_rollup(ctx):
"""Determine whether to use the Angular or upstream versions of the rollup_bundle rule.
@ -47,12 +50,11 @@ def _use_plain_rollup(ctx):
true iff the Angular version of rollup with build optimizer should be used, false otherwise
"""
if 'compile' not in ctx.var:
if "compile" not in ctx.var:
return False
strategy = ctx.var['compile']
return strategy == 'jit'
strategy = ctx.var["compile"]
return strategy == "jit"
def run_brotli(ctx, input, output):
"""Execute the Brotli compression utility.
@ -81,7 +83,7 @@ def _run_tsc(ctx, input, output):
executable = ctx.executable._tsc,
inputs = [input],
outputs = [output],
arguments = [args]
arguments = [args],
)
# Borrowed from bazelbuild/rules_nodejs, with the addition of brotli compression output
@ -115,15 +117,20 @@ def _ng_rollup_bundle(ctx):
rollup_config = write_rollup_config(ctx, [BO_PLUGIN], "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]))
rollup_sourcemap = run_rollup(ctx, esm5_sources, rollup_config, ctx.outputs.build_es5)
sourcemap = run_uglify(ctx,
sourcemap = run_uglify(
ctx,
ctx.outputs.build_es5,
ctx.outputs.build_es5_min,
comments = False,
in_source_map = rollup_sourcemap)
run_uglify(ctx,
in_source_map = rollup_sourcemap,
)
run_uglify(
ctx,
ctx.outputs.build_es5,
ctx.outputs.build_es5_min_debug,
debug = True, comments = False)
debug = True,
comments = False,
)
umd_rollup_config = write_rollup_config(ctx, filename = "_%s_umd.rollup.conf.js", output_format = "umd")
run_rollup(ctx, collect_es2015_sources(ctx), umd_rollup_config, ctx.outputs.build_umd)
@ -132,7 +139,7 @@ def _ng_rollup_bundle(ctx):
run_sourcemapexplorer(ctx, ctx.outputs.build_es5_min, sourcemap, ctx.outputs.explore_html)
return DefaultInfo(files=depset([ctx.outputs.build_es5_min, sourcemap]))
return DefaultInfo(files = depset([ctx.outputs.build_es5_min, sourcemap]))
ng_rollup_bundle = rule(
implementation = _ng_rollup_bundle,
@ -143,16 +150,18 @@ ng_rollup_bundle = rule(
aspects = [
rollup_module_mappings_aspect,
esm5_outputs_aspect,
]
],
),
"_rollup": attr.label(
executable = True,
cfg = "host",
default = Label("@angular//packages/bazel/src:rollup_with_build_optimizer")),
default = Label("@angular//packages/bazel/src:rollup_with_build_optimizer"),
),
"_brotli": attr.label(
executable = True,
cfg = "host",
default = Label("@org_brotli//:brotli")),
default = Label("@org_brotli//:brotli"),
),
}),
outputs = dict(ROLLUP_OUTPUTS, **{
"build_es5_min_compressed": "%{name}.min.js.br",

View File

@ -4,9 +4,10 @@
# found in the LICENSE file at https://angular.io/license
"Run end-to-end tests with Protractor"
load("@build_bazel_rules_nodejs//internal:node.bzl",
"sources_aspect",
load(
"@build_bazel_rules_nodejs//internal:node.bzl",
"expand_path_into_runfiles",
"sources_aspect",
)
load("@io_bazel_rules_webtesting//web:web.bzl", "web_test_suite")
load("@io_bazel_rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS")
@ -17,7 +18,8 @@ _CONF_TMPL = "//packages/bazel/src/protractor:protractor.conf.js"
def _protractor_web_test_impl(ctx):
configuration = ctx.actions.declare_file(
"%s.conf.js" % ctx.label.name,
sibling=ctx.outputs.executable)
sibling = ctx.outputs.executable,
)
files = depset(ctx.files.srcs)
for d in ctx.attr.deps:
@ -52,13 +54,13 @@ def _protractor_web_test_impl(ctx):
on_prepare_file = ctx.attr.on_prepare.typescript.es5_sources.to_list()[0]
protractor_executable_path = ctx.executable.protractor.short_path
if protractor_executable_path.startswith('..'):
if protractor_executable_path.startswith(".."):
protractor_executable_path = "external" + protractor_executable_path[2:]
server_executable_path = ''
server_executable_path = ""
if ctx.executable.server:
server_executable_path = ctx.executable.server.short_path
if server_executable_path.startswith('..'):
if server_executable_path.startswith(".."):
server_executable_path = "external" + protractor_executable_path[2:]
ctx.actions.expand_template(
@ -70,7 +72,8 @@ def _protractor_web_test_impl(ctx):
"TMPL_workspace": ctx.workspace_name,
"TMPL_server": server_executable_path,
"TMPL_specs": "\n".join([" '%s'," % e for e in specs]),
})
},
)
runfiles = [configuration] + configuration_sources + on_prepare_sources
@ -100,8 +103,11 @@ echo "Protractor $PROTRACTOR_VERSION"
# Run the protractor binary
$PROTRACTOR $CONF
""".format(TMPL_protractor = protractor_executable_path,
TMPL_conf = configuration.short_path))
""".format(
TMPL_protractor = protractor_executable_path,
TMPL_conf = configuration.short_path,
),
)
return [DefaultInfo(
files = depset([ctx.outputs.executable]),
runfiles = ctx.runfiles(
@ -123,36 +129,43 @@ _protractor_web_test = rule(
doc = "Protractor configuration file",
allow_single_file = True,
cfg = "data",
aspects = [sources_aspect]),
aspects = [sources_aspect],
),
"srcs": attr.label_list(
doc = "A list of JavaScript test files",
allow_files = [".js"]),
allow_files = [".js"],
),
"on_prepare": attr.label(
doc = """A file with a node.js script to run once before all tests run.
If the script exports a function which returns a promise, protractor
will wait for the promise to resolve before beginning tests.""",
allow_single_file = True,
cfg = "data",
aspects = [sources_aspect]),
aspects = [sources_aspect],
),
"deps": attr.label_list(
doc = "Other targets which produce JavaScript such as `ts_library`",
allow_files = True,
aspects = [sources_aspect]),
aspects = [sources_aspect],
),
"data": attr.label_list(
doc = "Runtime dependencies",
cfg = "data"),
cfg = "data",
),
"server": attr.label(
doc = "Optional server executable target",
executable = True,
cfg = "data",
single_file = False,
allow_files = True),
allow_files = True,
),
"protractor": attr.label(
doc = "Protractor executable target (set by protractor_web_test macro)",
executable = True,
cfg = "data",
single_file = False,
allow_files = True),
allow_files = True,
),
"_conf_tmpl": attr.label(
default = Label(_CONF_TMPL),
allow_single_file = True,
@ -206,7 +219,7 @@ def protractor_web_test(
_protractor_web_test(
name = name,
configuration = configuration,
on_prepare=on_prepare,
on_prepare = on_prepare,
srcs = srcs,
deps = deps,
data = web_test_data,
@ -216,7 +229,8 @@ def protractor_web_test(
# Users don't need to know that this tag is required to run under ibazel
"ibazel_notify_changes",
],
**kwargs)
**kwargs
)
def protractor_web_test_suite(
name,
@ -226,20 +240,20 @@ def protractor_web_test_suite(
deps = [],
data = [],
server = None,
browsers=["@io_bazel_rules_webtesting//browsers:chromium-local"],
args=None,
browser_overrides=None,
config=None,
flaky=None,
local=None,
shard_count=None,
size=None,
browsers = ["@io_bazel_rules_webtesting//browsers:chromium-local"],
args = None,
browser_overrides = None,
config = None,
flaky = None,
local = None,
shard_count = None,
size = None,
tags = [],
test_suite_tags=None,
timeout=None,
visibility=None,
web_test_data=[],
wrapped_test_tags=None,
test_suite_tags = None,
timeout = None,
visibility = None,
web_test_data = [],
wrapped_test_tags = None,
**remaining_keyword_args):
"""Defines a test_suite of web_test targets that wrap a protractor_web_test target.
@ -275,6 +289,7 @@ def protractor_web_test_suite(
wrapped_test_tags: A list of test tag strings to use for the wrapped test
**remaining_keyword_args: Arguments for the wrapped test target.
"""
# Check explicitly for None so that users can set this to the empty list
if wrapped_test_tags == None:
wrapped_test_tags = DEFAULT_WRAPPED_TEST_TAGS
@ -303,38 +318,40 @@ def protractor_web_test_suite(
web_test_data += [server]
_protractor_web_test(
name=wrapped_test_name,
configuration=configuration,
on_prepare=on_prepare,
srcs=srcs,
deps=deps,
data=web_test_data,
server=server,
protractor=protractor_bin_name,
args=args,
flaky=flaky,
local=local,
shard_count=shard_count,
size=size,
tags=wrapped_test_tags,
timeout=timeout,
visibility=["//visibility:private"],
**remaining_keyword_args)
name = wrapped_test_name,
configuration = configuration,
on_prepare = on_prepare,
srcs = srcs,
deps = deps,
data = web_test_data,
server = server,
protractor = protractor_bin_name,
args = args,
flaky = flaky,
local = local,
shard_count = shard_count,
size = size,
tags = wrapped_test_tags,
timeout = timeout,
visibility = ["//visibility:private"],
**remaining_keyword_args
)
web_test_suite(
name=name,
launcher=":"+wrapped_test_name,
args=args,
browsers=browsers,
browser_overrides=browser_overrides,
config=config,
data=web_test_data,
flaky=flaky,
local=local,
shard_count=shard_count,
size=size,
tags=tags,
test=wrapped_test_name,
test_suite_tags=test_suite_tags,
timeout=timeout,
visibility=visibility)
name = name,
launcher = ":" + wrapped_test_name,
args = args,
browsers = browsers,
browser_overrides = browser_overrides,
config = config,
data = web_test_data,
flaky = flaky,
local = local,
shard_count = shard_count,
size = size,
tags = tags,
test = wrapped_test_name,
test_suite_tags = test_suite_tags,
timeout = timeout,
visibility = visibility,
)

View File

@ -1,19 +1,20 @@
"""Allows different paths for these imports in google3.
"""
load("@build_bazel_rules_typescript//internal:build_defs.bzl",
load(
"@build_bazel_rules_typescript//internal:build_defs.bzl",
_tsc_wrapped_tsconfig = "tsc_wrapped_tsconfig",
)
load("@build_bazel_rules_typescript//internal:common/compilation.bzl",
load(
"@build_bazel_rules_typescript//internal:common/compilation.bzl",
_COMMON_ATTRIBUTES = "COMMON_ATTRIBUTES",
_COMMON_OUTPUTS = "COMMON_OUTPUTS",
_compile_ts = "compile_ts",
_DEPS_ASPECTS = "DEPS_ASPECTS",
_compile_ts = "compile_ts",
_ts_providers_dict_to_struct = "ts_providers_dict_to_struct",
)
load("@build_bazel_rules_typescript//internal:common/json_marshal.bzl",
load(
"@build_bazel_rules_typescript//internal:common/json_marshal.bzl",
_json_marshal = "json_marshal",
)

View File

@ -9,14 +9,15 @@ This allows editors and other tools to easily use the language service bundle
without having to provide all of the angular specific peer dependencies.
"""
load("@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl",
load(
"@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl",
"ROLLUP_ATTRS",
"rollup_module_mappings_aspect",
"write_rollup_config",
"run_rollup",
"run_uglify"
"run_uglify",
"write_rollup_config",
)
load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "flatten_esm5", "esm5_root_dir")
load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "esm5_root_dir", "flatten_esm5")
# Note: the file is called "umd.js" and "umd.min.js" because of historical
# reasons. The format is actually amd and not umd, but we are afraid to rename
@ -29,12 +30,14 @@ _ROLLUP_OUTPUTS = {
def _ls_rollup_bundle(ctx):
esm5_sources = flatten_esm5(ctx)
rollup_config = write_rollup_config(ctx,
rollup_config = write_rollup_config(
ctx,
root_dir = "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]),
output_format = "amd")
output_format = "amd",
)
run_rollup(ctx, esm5_sources, rollup_config, ctx.outputs.build_umd)
source_map = run_uglify(ctx, ctx.outputs.build_umd, ctx.outputs.build_umd_min)
return DefaultInfo(files=depset([ctx.outputs.build_umd, ctx.outputs.build_umd_min, source_map]))
return DefaultInfo(files = depset([ctx.outputs.build_umd, ctx.outputs.build_umd_min, source_map]))
ls_rollup_bundle = rule(
implementation = _ls_rollup_bundle,

View File

@ -1,4 +1,5 @@
"""Re-export of some bazel rules with repository-wide defaults."""
load("@build_bazel_rules_nodejs//:defs.bzl", _npm_package = "npm_package")
load("@build_bazel_rules_typescript//:defs.bzl", _ts_library = "ts_library", _ts_web_test_suite = "ts_web_test_suite")
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
@ -35,7 +36,7 @@ ANGULAR_SCOPED_PACKAGES = ["@angular/%s" % p for p in [
PKG_GROUP_REPLACEMENTS = {
"\"NG_UPDATE_PACKAGE_GROUP\"": """[
%s
]""" % ",\n ".join(["\"%s\"" % s for s in ANGULAR_SCOPED_PACKAGES])
]""" % ",\n ".join(["\"%s\"" % s for s in ANGULAR_SCOPED_PACKAGES]),
}
def ts_library(tsconfig = None, node_modules = DEFAULT_NODE_MODULES, **kwargs):
@ -71,13 +72,15 @@ def ng_package(name, readme_md = None, license_banner = None, **kwargs):
readme_md = readme_md,
license_banner = license_banner,
replacements = PKG_GROUP_REPLACEMENTS,
**kwargs)
**kwargs
)
def npm_package(name, replacements = {}, **kwargs):
_npm_package(
name = name,
replacements = dict(replacements, **PKG_GROUP_REPLACEMENTS),
**kwargs)
**kwargs
)
def ts_web_test_suite(bootstrap = [], deps = [], **kwargs):
if not bootstrap:
@ -101,4 +104,5 @@ def ts_web_test_suite(bootstrap = [], deps = [], **kwargs):
# "@io_bazel_rules_webtesting//browsers:firefox-local",
# TODO(alexeagle): add remote browsers on SauceLabs
],
**kwargs)
**kwargs
)

View File

@ -2,6 +2,7 @@
See https://www.npmjs.com/package/http-server
"""
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
def http_server(templated_args = [], **kwargs):
@ -15,4 +16,5 @@ def http_server(templated_args = [], **kwargs):
node_modules = "@http-server_runtime_deps//:node_modules",
entry_point = "http-server/bin/http-server",
templated_args = templated_args,
**kwargs)
**kwargs
)

View File

@ -239,6 +239,7 @@ filegroup(
"node_modules/protractor/**",
"node_modules/@schematics/angular/**",
]))
""")
""",
)
_ng_setup_workspace()

View File

@ -8,7 +8,7 @@
# This does a deep import under //internal because of not wanting the wrapper macro
# because it introduces an extra target_bin target.
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_test", "nodejs_binary")
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary", "nodejs_test")
def js_expected_symbol_test(name, src, golden, **kwargs):
"""This test verifies that a set of top level symbols from a javascript file match a gold file.
@ -27,9 +27,9 @@ def js_expected_symbol_test(name, src, golden, **kwargs):
)
nodejs_binary(
name = name + '.accept',
name = name + ".accept",
data = all_data,
entry_point = entry_point,
templated_args = ["$(location %s)" % src, "$(location %s)" % golden, '--accept'],
templated_args = ["$(location %s)" % src, "$(location %s)" % golden, "--accept"],
**kwargs
)

View File

@ -14,7 +14,8 @@
"""Runs ts_api_guardian
"""
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_test", "nodejs_binary")
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary", "nodejs_test")
COMMON_MODULE_IDENTIFIERS = ["angular", "jasmine", "protractor"]
@ -31,7 +32,8 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
# Needed so that node doesn't walk back to the source directory.
# From there, the relative imports would point to .ts files.
"--node_options=--preserve-symlinks",
"--stripExportPattern", "^\(__\\)",
"--stripExportPattern",
"^\(__\\)",
]
for i in COMMON_MODULE_IDENTIFIERS:
args += ["--allowModuleIdentifiers", i]