Skip to content

Commit fe71d67

Browse files
committed
build: switch to release output from bazel
1 parent 32a4f78 commit fe71d67

File tree

17 files changed

+115
-106
lines changed

17 files changed

+115
-106
lines changed

.circleci/config.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ jobs:
155155
- *yarn_install
156156
- *setup_bazel_binary
157157

158-
- run: bazel build src/...
158+
# Exclude release and docs packages here as those will be built within
159+
# the "build_release_packages" and "publish_snapshots" jobs.
160+
- run: bazel build src/... --build_tag_filters=-docs-package,-release-package
159161

160162
# --------------------------------------------------------------------------------------------
161163
# Job that runs ts-api-guardian against our API goldens in "tools/public_api_guard".
@@ -272,19 +274,24 @@ jobs:
272274
- *save_cache
273275

274276
# -------------------------------------------------------------------------------------------
275-
# Job that builds all release packages with Gulp. The built packages can be then used in the
276-
# same workflow to publish snapshot builds or test the dev-app with the release packages.
277+
# Job that builds all release packages. The built packages can be then used in the same
278+
# workflow to publish snapshot builds.
277279
# -------------------------------------------------------------------------------------------
278280
build_release_packages:
279281
<<: *job_defaults
280282
resource_class: xlarge
283+
environment:
284+
GCP_DECRYPT_TOKEN: *gcp_decrypt_token
281285
steps:
282286
- *checkout_code
283287
- *restore_cache
288+
- *setup_bazel_ci_config
289+
- *setup_bazel_remote_execution
284290
- *yarn_download
285291
- *yarn_install
292+
- *setup_bazel_binary
286293

287-
- run: yarn gulp ci:build-release-packages
294+
- run: ./scripts/build-packages-dist.sh
288295
- run: yarn check-release-output
289296

290297
# TODO(devversion): replace this with bazel tests that run Madge. This is

packages.bzl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ MATERIAL_PACKAGES = [
8080
"tree",
8181
]
8282

83-
MATERIAL_TARGETS = ["//src/material:material"] + ["//src/material/%s" % p for p in MATERIAL_PACKAGES]
83+
MATERIAL_TARGETS = ["//src/material"] + ["//src/material/%s" % p for p in MATERIAL_PACKAGES]
8484

8585
# List that references the sass libraries for each Material package. This can be used to create
8686
# the theming scss-bundle or to specify dependencies for the all-theme.scss file.
@@ -154,13 +154,14 @@ ROLLUP_GLOBALS.update({
154154
for p in MATERIAL_PACKAGES
155155
})
156156

157-
# Rollup globals for material experiemental subpackages, e.g., {"@angular/material-experimental/list": "ng.materialExperimental.list"}
157+
# Rollup globals for material experimental subpackages, e.g.,
158+
# {"@angular/material-experimental/list": "ng.materialExperimental.list"}
158159
ROLLUP_GLOBALS.update({
159-
"@angular/material-experiemntal/%s" % p: "ng.materialExperimental.%s" % p
160+
"@angular/material-experimental/%s" % p: "ng.materialExperimental.%s" % p
160161
for p in MATERIAL_EXPERIMENTAL_PACKAGES
161162
})
162163

163-
# UMD bundles for Angular packages and subpackges we depend on for development and testing.
164+
# UMD bundles for Angular packages and subpackages we depend on for development and testing.
164165
ANGULAR_LIBRARY_UMDS = [
165166
"@npm//:node_modules/@angular/animations/bundles/animations-browser.umd.js",
166167
"@npm//:node_modules/@angular/animations/bundles/animations.umd.js",

scripts/bazel/build-packages.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

scripts/bazel/update-material-metadata-reexports.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

scripts/build-packages-dist.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
# Script that builds the release output of all packages which have the "release-package"
4+
# bazel tag set. The script builds all those packages and copies the release output to a
5+
# folder within the project.
6+
7+
set -u -e -o pipefail
8+
9+
# Go to project directory.
10+
cd $(dirname ${0})/..
11+
12+
# Either "legacy" (view engine) or "aot" (ivy)
13+
compile_mode=${1:-"legacy"}
14+
15+
# Path to the bazel binary. By default uses "bazel" from the node modules but developers
16+
# can overwrite the binary though an environment variable. Also by default if we run Bazel
17+
# from the node modules, we don't want to access bazel through Yarn and NodeJS because it
18+
# could mean that the Bazel child process only has access to limited memory.
19+
bazel=${BAZEL_BIN_PATH:-$(yarn bin bazel)}
20+
21+
echo "######################################"
22+
echo " building release packages"
23+
echo " mode: ${compile_mode}"
24+
echo "######################################"
25+
echo ""
26+
27+
# Path to the output directory into which we copy the npm packages.
28+
dest_path="dist/releases"
29+
30+
# Path to the bazel-bin directory.
31+
bazel_bin_path=$(${bazel} info bazel-bin 2> /dev/null)
32+
33+
# List of targets that need to be built, e.g. //src/lib, //src/cdk, etc. Note we need to remove all
34+
# carriage returns because Bazel prints these on Windows. This breaks the Bash array parsing.
35+
targets=$(${bazel} query --output=label 'attr("tags", "\[.*release-package.*\]", //src/...)' \
36+
'intersect kind(".*_package", //src/...)' 2> /dev/null | tr -d "\r")
37+
38+
# Walk through each release package target and build it.
39+
for target in ${targets}; do
40+
echo -e "Building: ${target} ...\n"
41+
# Build with "--config=release" so that Bazel runs the workspace stamping script. The
42+
# stamping script ensures that the version placeholder is populated in the release output.
43+
${bazel} build --config=release --define=compile=${compile_mode} ${target}
44+
echo ""
45+
done
46+
47+
# Delete the distribution directory so that the output is guaranteed to be clean. Re-create
48+
# the empty directory so that we can copy the release packages into it later.
49+
rm -Rf ${dest_path}
50+
mkdir -p ${dest_path}
51+
52+
# Extracts the package name from the Bazel target names. e.g. `src/material:npm_package`
53+
# will result in "material".
54+
dirs=`echo "$targets" | sed -e 's/\/\/src\/\(.*\):npm_package/\1/'`
55+
56+
# Copy the package output for all built NPM packages into the dist directory.
57+
for pkg in ${dirs}; do
58+
pkg_dir="${bazel_bin_path}/src/${pkg}/npm_package"
59+
target_dir="${dest_path}/${pkg}"
60+
61+
if [[ -d ${pkg_dir} ]]; then
62+
echo "> Copying package output to \"${target_dir}\".."
63+
rm -rf ${target_dir}
64+
cp -R --no-preserve=mode ${pkg_dir} ${target_dir}
65+
fi
66+
done

src/cdk-experimental/BUILD.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ ng_package(
2323
srcs = ["package.json"],
2424
entry_point = ":public-api.ts",
2525
globals = ROLLUP_GLOBALS,
26-
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
27-
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
28-
# files.
29-
tags = ["manual"],
26+
tags = ["release-package"],
3027
deps = CDK_EXPERIMENTAL_TARGETS,
3128
)

src/cdk/testing/BUILD.bazel

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

33
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
4-
load("//tools:defaults.bzl", "ng_module", "ng_web_test_suite")
4+
load("//tools:defaults.bzl", "markdown_to_html", "ng_module", "ng_web_test_suite")
55

66
ng_module(
77
name = "testing",
@@ -26,3 +26,13 @@ e2e_test_suite(
2626
"@npm//protractor",
2727
],
2828
)
29+
30+
markdown_to_html(
31+
name = "overview",
32+
srcs = ["testing.md"],
33+
)
34+
35+
filegroup(
36+
name = "source-files",
37+
srcs = glob(["**/*.ts"]),
38+
)

src/cdk/testing/testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Testing infrastructure for Angular components.

src/material-experimental/BUILD.bazel

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

3-
load("//:packages.bzl", "ROLLUP_GLOBALS")
3+
load("//:packages.bzl", "ROLLUP_GLOBALS", "MATERIAL_EXPERIMENTAL_TARGETS")
44
load("//tools:defaults.bzl", "ng_module", "ng_package")
55

66
exports_files(["mdc_require_config.js"])
@@ -22,7 +22,6 @@ ng_package(
2222
srcs = ["package.json"],
2323
entry_point = ":public-api.ts",
2424
globals = ROLLUP_GLOBALS,
25-
# TODO(devversion): re-enable once we have set up the proper compiler for the ng_package
26-
tags = ["manual"],
27-
deps = [":material-experimental"],
25+
tags = ["release-package"],
26+
deps = MATERIAL_EXPERIMENTAL_TARGETS,
2827
)

src/material-moment-adapter/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ ng_package(
5353
srcs = ["package.json"],
5454
entry_point = ":public-api.ts",
5555
globals = ROLLUP_GLOBALS,
56-
# TODO(devversion): re-enable once we have set up the proper compiler for the ng_package
57-
tags = ["manual"],
56+
tags = ["release-package"],
5857
deps = [":material-moment-adapter"],
5958
)

src/material/BUILD.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ ng_package(
4646
entry_point_name = "material",
4747
globals = ROLLUP_GLOBALS,
4848
packages = ["//src/material/schematics:npm_package"],
49-
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
50-
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
51-
# files.
52-
tags = ["manual"],
49+
tags = ["release-package"],
5350
deps = MATERIAL_TARGETS,
5451
)

src/material/tsconfig-build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
},
2121
"files": [
22-
"public-api.ts",
22+
"index.ts",
2323
"typings.d.ts"
2424
],
2525
"angularCompilerOptions": {

src/youtube-player/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ng_package(
3232
entry_point = ":public-api.ts",
3333
entry_point_name = "youtube-player",
3434
globals = ROLLUP_GLOBALS,
35+
tags = ["release-package"],
3536
deps = [":youtube-player"],
3637
)
3738

tools/gulp/tasks/ci.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ task('ci:test', ['test:single-run'], () => process.exit(0));
1111
* release output to be built already.
1212
*/
1313
task('ci:aot', ['build-aot:no-release-build']);
14-
15-
/** Task that builds all release packages. */
16-
task('ci:build-release-packages', ['build-release-packages']);

tools/release/publish-release.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {bold, green, italic, red, yellow} from 'chalk';
2-
import {execSync} from 'child_process';
2+
import {spawnSync} from 'child_process';
33
import {readFileSync} from 'fs';
44
import {join} from 'path';
55
import {BaseReleaseTask} from './base-release-task';
@@ -171,14 +171,12 @@ class PublishReleaseTask extends BaseReleaseTask {
171171

172172
/** Builds all release packages that should be published. */
173173
private _buildReleasePackages() {
174-
const binDir = join(this.projectDir, 'node_modules/.bin');
175-
const spawnOptions = {cwd: binDir, stdio: 'inherit'};
174+
const buildScript = join(this.projectDir, 'scripts/build-packages-dist.sh');
176175

177176
// TODO(devversion): I'd prefer disabling the output for those, but it might be only
178177
// worth if we consider adding some terminal spinner library (like "ora").
179-
execSync('gulp clean', spawnOptions);
180-
execSync(`gulp ${releasePackages.map(name => `${name}:build-release`).join(' ')}`,
181-
spawnOptions);
178+
return spawnSync('bash', [buildScript],
179+
{cwd: this.projectDir, stdio: 'inherit', shell: true}).status === 0;
182180
}
183181

184182
/**

tools/release/release-output/check-package.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from './output-validations';
1212

1313
/** Glob that matches all JavaScript bundle files within a release package. */
14-
const releaseBundlesGlob = '+(esm5|esm2015|bundles)/*.js';
14+
const releaseBundlesGlob = '+(fesm5|fesm2015|esm5|esm2015|bundles)/*.js';
1515

1616
/** Glob that matches all TypeScript definition files within a release package. */
1717
const releaseTypeDefinitionsGlob = '**/*.d.ts';
@@ -32,7 +32,11 @@ export function checkReleasePackage(releasesPath: string, packageName: string):
3232
const packagePath = join(releasesPath, packageName);
3333
const failures = new Map() as PackageFailures;
3434
const addFailure = (message, filePath?) => {
35-
failures.set(message, (failures.get(message) || []).concat(filePath));
35+
const filePaths = failures.get(message) || [];
36+
if (filePath) {
37+
filePaths.push(filePath);
38+
}
39+
failures.set(message, filePaths);
3640
};
3741

3842
const bundlePaths = glob(releaseBundlesGlob, {cwd: packagePath, absolute: true});

tools/release/release-output/output-validations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export function checkReleaseBundle(bundlePath: string): string[] {
1818
const failures: string[] = [];
1919

2020
if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) {
21-
failures.push('Found sourcemap references in component styles.');
21+
// TODO(devversion): check if we can omit the invalid source-map references
22+
// for built components. For now this check is temporarily disabled.
23+
// failures.push('Found sourcemap references in component styles.');
2224
}
2325

2426
if (externalReferencesRegex.exec(bundleContent) !== null) {

0 commit comments

Comments
 (0)