Skip to content

Commit 16d2eb8

Browse files
devversionmmalerba
authored andcommitted
build: reduce manual setup for entry-points of packages (#17460)
Reduces the manual setup for entry-poitns of packages. With this change, we no longer need to update the dev-app system config if we add/remove entry-points. We basically only need to configure entry-points in the `config.bzl` file. Though this is not 100% complete yet, because we still have legacy karma tests which need another system config. The bazel karma tests do not need this anymore.
1 parent c6bcce9 commit 16d2eb8

File tree

4 files changed

+57
-75
lines changed

4 files changed

+57
-75
lines changed

src/dev-app/BUILD.bazel

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package(default_visibility = ["//visibility:public"])
22

3+
load("//src/cdk:config.bzl", "CDK_ENTRYPOINTS")
4+
load("//src/cdk-experimental:config.bzl", "CDK_EXPERIMENTAL_ENTRYPOINTS")
5+
load("//src/material:config.bzl", "MATERIAL_ENTRYPOINTS")
6+
load("//src/material-experimental:config.bzl", "MATERIAL_EXPERIMENTAL_ENTRYPOINTS")
37
load("//tools:defaults.bzl", "ng_module", "sass_binary")
8+
load("//tools/bazel:expand_template.bzl", "expand_template")
49
load("//tools/dev-server:index.bzl", "dev_server")
510

611
ng_module(
@@ -92,20 +97,26 @@ sass_binary(
9297
],
9398
)
9499

95-
genrule(
96-
name = "setup_compile_mode_script",
97-
outs = ["setup_compile_mode.js"],
98-
cmd = "echo window.bazelCompileMode = \"'$(compile)'\"\; > $@",
100+
expand_template(
101+
name = "system-config",
102+
configuration_env_vars = ["compile"],
103+
output_name = "system-config.js",
104+
substitutions = {
105+
"$CDK_ENTRYPOINTS_TMPL": str(CDK_ENTRYPOINTS),
106+
"$CDK_EXPERIMENTAL_ENTRYPOINTS_TMPL": str(CDK_EXPERIMENTAL_ENTRYPOINTS),
107+
"$MATERIAL_ENTRYPOINTS_TMPL": str(MATERIAL_ENTRYPOINTS),
108+
"$MATERIAL_EXPERIMENTAL_ENTRYPOINTS_TMPL": str(MATERIAL_EXPERIMENTAL_ENTRYPOINTS),
109+
},
110+
template = "system-config-tmpl.js",
99111
)
100112

101113
dev_server(
102114
name = "devserver",
103115
srcs = [
104116
"favicon.ico",
105117
"index.html",
106-
"system-config.js",
107118
"system-rxjs-operators.js",
108-
":setup_compile_mode_script",
119+
":system-config",
109120
":theme",
110121
"//src/dev-app/icon:icon_demo_assets",
111122
"@npm//:node_modules/@material/animation/dist/mdc.animation.js",

src/dev-app/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<script src="core-js/client/core.js"></script>
2929
<script src="zone.js/dist/zone.js"></script>
3030
<script src="systemjs/dist/system.js"></script>
31-
<script src="setup_compile_mode.js"></script>
3231
<script src="system-config.js"></script>
3332
<script src="https://www.youtube.com/iframe_api"></script>
3433
<script src="https://maps.googleapis.com/maps/api/js"></script>

src/dev-app/system-config.js renamed to src/dev-app/system-config-tmpl.js

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,17 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// Note that this file isn't being transpiled so we need to keep it in ES5.
10-
11-
var CDK_PACKAGES = [
12-
'a11y',
13-
'accordion',
14-
'bidi',
15-
'clipboard',
16-
'coercion',
17-
'collections',
18-
'drag-drop',
19-
'keycodes',
20-
'layout',
21-
'observers',
22-
'overlay',
23-
'platform',
24-
'portal',
25-
'scrolling',
26-
'stepper',
27-
'table',
28-
'text-field',
29-
'tree',
30-
];
31-
32-
var CDK_EXPERIMENTAL_PACKAGES = [
33-
'dialog',
34-
'popover-edit',
35-
'scrolling',
36-
];
37-
38-
var MATERIAL_PACKAGES = [
39-
'autocomplete', 'badge',
40-
'bottom-sheet', 'button',
41-
'button-toggle', 'card',
42-
'checkbox', 'chips',
43-
'core', 'datepicker',
44-
'dialog', 'divider',
45-
'expansion', 'form-field',
46-
'grid-list', 'icon',
47-
'input', 'list',
48-
'menu', 'paginator',
49-
'progress-bar', 'progress-spinner',
50-
'radio', 'select',
51-
'sidenav', 'slide-toggle',
52-
'slider', 'snack-bar',
53-
'sort', 'stepper',
54-
'table', 'tabs',
55-
'toolbar', 'tooltip',
56-
'tree',
57-
];
58-
59-
var MATERIAL_EXPERIMENTAL_PACKAGES = [
60-
'mdc-button',
61-
'mdc-card',
62-
'mdc-checkbox',
63-
'mdc-chips',
64-
'mdc-tabs',
65-
'mdc-helpers',
66-
'mdc-menu',
67-
'mdc-radio',
68-
'mdc-progress-bar',
69-
'mdc-slide-toggle',
70-
'mdc-slider',
71-
'popover-edit',
72-
];
9+
// Note that this file isn't being transpiled so we need to keep it in ES5. Also
10+
// identifiers of the format "$NAME_TMPL" will be replaced by the Bazel rule that
11+
// converts this template file into the actual SystemJS configuration file.
12+
13+
var CDK_PACKAGES = $CDK_ENTRYPOINTS_TMPL;
14+
var CDK_EXPERIMENTAL_PACKAGES = $CDK_EXPERIMENTAL_ENTRYPOINTS_TMPL;
15+
var MATERIAL_PACKAGES = $MATERIAL_ENTRYPOINTS_TMPL;
16+
var MATERIAL_EXPERIMENTAL_PACKAGES = $MATERIAL_EXPERIMENTAL_ENTRYPOINTS_TMPL;
17+
18+
/** Whether the dev-app is served with Ivy enabled. */
19+
var isRunningWithIvy = '$COMPILE_TMPL' === 'aot';
7320

7421
/** Bazel runfile path referring to the "src/" folder of the project. */
7522
var srcRunfilePath = 'angular_material/src';
@@ -80,10 +27,7 @@ var pathMapping = {};
8027
/** Package configurations that will be used in SystemJS. */
8128
var packagesConfig = {};
8229

83-
// The "bazelCompileMode" property will be set globally by the "setup-compile-mode.js"
84-
// script. This allows us to switch between Ivy and View Engine UMD bundles automatically.
85-
/** Whether the dev-app is served with Ivy enabled. */
86-
var isRunningWithIvy = window.bazelCompileMode === 'aot';
30+
8731

8832
// Configure all primary entry-points.
8933
configureEntryPoint('cdk');

tools/bazel/expand_template.bzl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Implementation of the expand_template rule """
2+
3+
def expand_template_impl(ctx):
4+
replacements = dict(**ctx.attr.substitutions)
5+
6+
for k in ctx.attr.configuration_env_vars:
7+
if k in ctx.var.keys():
8+
replacements["$%s_TMPL" % k.upper()] = ctx.var[k]
9+
10+
ctx.actions.expand_template(
11+
template = ctx.file.template,
12+
output = ctx.outputs.output_name,
13+
substitutions = replacements,
14+
)
15+
16+
"""
17+
Rule that can be used to output a file from a specified
18+
template by applying given substitutions.
19+
"""
20+
expand_template = rule(
21+
implementation = expand_template_impl,
22+
attrs = {
23+
"configuration_env_vars": attr.string_list(default = []),
24+
"output_name": attr.output(mandatory = True),
25+
"substitutions": attr.string_dict(mandatory = True),
26+
"template": attr.label(mandatory = True, allow_single_file = True),
27+
},
28+
)

0 commit comments

Comments
 (0)