Skip to content

Commit 920ee85

Browse files
clydinmgechev
authored andcommitted
build: update bazel dependencies and configuration (angular#15291)
This leverages the configuration from FW where possible. Bazel updated to 28.1 Rules for nodejs/typescript/karma/jasmine updated to 0.35.0
1 parent fb60046 commit 920ee85

File tree

7 files changed

+498
-190
lines changed

7 files changed

+498
-190
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.git
12
dist
23
node_modules

.bazelrc

+113-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,88 @@
22
# running as daemons, and cache SourceFile AST's to reduce parse time.
33
build --strategy=TypeScriptCompile=worker
44

5-
# Performance: avoid stat'ing input files
6-
build --watchfs
5+
# Enable debugging tests with --config=debug
6+
test:debug --test_arg=--node_options=--inspect-brk --test_output=streamed --test_strategy=exclusive --test_timeout=9999 --nocache_test_results
77

8+
###############################
9+
# Filesystem interactions #
10+
###############################
11+
12+
# Create symlinks in the project:
13+
# - dist/bin for outputs
14+
# - dist/testlogs, dist/genfiles
15+
# - bazel-out
16+
# NB: bazel-out should be excluded from the editor configuration.
17+
# The checked-in /.vscode/settings.json does this for VSCode.
18+
# Other editors may require manual config to ignore this directory.
19+
# In the past, we saw a problem where VSCode traversed a massive tree, opening file handles and
20+
# eventually a surprising failure with auto-discovery of the C++ toolchain in
21+
# MacOS High Sierra.
22+
# See https://github.com/bazelbuild/bazel/issues/4603
23+
build --symlink_prefix=dist/
24+
25+
# Disable watchfs as it causes tests to be flaky on Windows
26+
# https://github.com/angular/angular/issues/29541
27+
build --nowatchfs
28+
29+
# Turn off legacy external runfiles
30+
run --nolegacy_external_runfiles
31+
test --nolegacy_external_runfiles
32+
33+
# Turn on --incompatible_strict_action_env which was on by default
34+
# in Bazel 0.21.0 but turned off again in 0.22.0. Follow
35+
# https://github.com/bazelbuild/bazel/issues/7026 for more details.
36+
# This flag is needed to so that the bazel cache is not invalidated
37+
# when running bazel via `yarn bazel`.
38+
# See https://github.com/angular/angular/issues/27514.
39+
build --incompatible_strict_action_env
40+
run --incompatible_strict_action_env
41+
test --incompatible_strict_action_env
42+
43+
###############################
44+
# Saucelabs support #
45+
# Turn on these settings with #
46+
# --config=saucelabs #
47+
###############################
48+
49+
# Expose SauceLabs environment to actions
50+
# These environment variables are needed by
51+
# web_test_karma to run on Saucelabs
52+
test:saucelabs --action_env=SAUCE_USERNAME
53+
test:saucelabs --action_env=SAUCE_ACCESS_KEY
54+
test:saucelabs --action_env=SAUCE_READY_FILE
55+
test:saucelabs --action_env=SAUCE_PID_FILE
56+
test:saucelabs --action_env=SAUCE_TUNNEL_IDENTIFIER
57+
test:saucelabs --define=KARMA_WEB_TEST_MODE=SL_REQUIRED
58+
59+
###############################
60+
# Release support #
61+
# Turn on these settings with #
62+
# --config=release #
63+
###############################
64+
65+
# Releases should always be stamped with version control info
66+
# This command assumes node on the path and is a workaround for
67+
# https://github.com/bazelbuild/bazel/issues/4802
68+
build:release --workspace_status_command="node ./tools/bazel_stamp_vars.js"
69+
70+
###############################
71+
# Output #
72+
###############################
73+
74+
# A more useful default output mode for bazel query
75+
# Prints eg. "ng_module rule //foo:bar" rather than just "//foo:bar"
76+
query --output=label_kind
77+
78+
# By default, failing tests don't print any output, it goes to the log file
879
test --test_output=errors
980

81+
################################
82+
# Settings for CircleCI #
83+
################################
84+
85+
# Bazel flags for CircleCI are in /.circleci/bazel.rc
86+
1087
################################
1188
# Remote Execution Setup #
1289
################################
@@ -52,6 +129,40 @@ build:remote --bes_results_url="https://source.cloud.google.com/results/invocati
52129
# Set remote caching settings
53130
build:remote --remote_accept_cached=true
54131

132+
###############################
133+
# NodeJS rules settings
134+
# These settings are required for rules_nodejs
135+
###############################
136+
137+
# Turn on managed directories feature in Bazel
138+
# This allows us to avoid installing a second copy of node_modules
139+
common --experimental_allow_incremental_repository_updates
140+
141+
# This option is changed to true in Bazel 0.27 and exposes a possible
142+
# regression in Bazel 0.27.0.
143+
# Error observed is in npm_package target `//packages/common/locales:package`:
144+
# ```
145+
# ERROR: /home/circleci/ng/packages/common/locales/BUILD.bazel:13:1: Assembling
146+
# npm package packages/common/locales/package failed: No usable spawn strategy found
147+
# for spawn with mnemonic SkylarkAction. Your --spawn_strategy or --strategy flags
148+
# are probably too strict. Visit https://github.com/bazelbuild/bazel/issues/7480 for
149+
# migration advises
150+
# ```
151+
# Suspect is https://github.com/bazelbuild/rules_nodejs/blob/master/internal/npm_package/npm_package.bzl#L75-L82:
152+
# ```
153+
# execution_requirements = {
154+
# # Never schedule this action remotely because it's not computationally expensive.
155+
# # It just copies files into a directory; it's not worth copying inputs and outputs to a remote worker.
156+
# # Also don't run it in a sandbox, because it resolves an absolute path to the bazel-out directory
157+
# # allowing the .pack and .publish runnables to work with no symlink_prefix
158+
# # See https://github.com/bazelbuild/rules_nodejs/issues/187
159+
# "local": "1",
160+
# },
161+
# ```
162+
build --incompatible_list_based_execution_strategy_selection=false
163+
test --incompatible_list_based_execution_strategy_selection=false
164+
run --incompatible_list_based_execution_strategy_selection=false
165+
55166
####################################################
56167
# User bazel configuration
57168
# NOTE: This needs to be the *last* entry in the config.

WORKSPACE

+66-42
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,77 @@
1-
workspace(name = "angular_cli")
1+
workspace(
2+
name = "angular_cli",
3+
managed_directories = {"@npm": ["node_modules"]},
4+
)
25

3-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
46
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
7+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
58

69
http_archive(
710
name = "build_bazel_rules_nodejs",
8-
sha256 = "fb87ed5965cef93188af9a7287511639403f4b0da418961ce6defb9dcf658f51",
9-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.27.7/rules_nodejs-0.27.7.tar.gz"],
11+
sha256 = "6625259f9f77ef90d795d20df1d0385d9b3ce63b6619325f702b6358abb4ab33",
12+
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.35.0/rules_nodejs-0.35.0.tar.gz"],
1013
)
1114

1215
# We use protocol buffers for the Build Event Protocol
1316
git_repository(
1417
name = "com_google_protobuf",
1518
commit = "beaeaeda34e97a6ff9735b33a66e011102ab506b",
1619
remote = "https://github.com/protocolbuffers/protobuf",
20+
shallow_since = "1559159889 -0400",
1721
)
1822

1923
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
2024

2125
protobuf_deps()
2226

23-
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")
24-
25-
# 0.18.0 is needed for .bazelignore
26-
check_bazel_version(minimum_bazel_version = "0.18.0")
27+
# Check the bazel version and download npm dependencies
28+
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "check_rules_nodejs_version", "node_repositories", "yarn_install")
29+
30+
# Bazel version must be at least the following version because:
31+
# - 0.26.0 managed_directories feature added which is required for nodejs rules 0.30.0
32+
# - 0.27.0 has a fix for managed_directories after `rm -rf node_modules`
33+
check_bazel_version(
34+
message = """
35+
You no longer need to install Bazel on your machine.
36+
Angular has a dependency on the @bazel/bazel package which supplies it.
37+
Try running `yarn bazel` instead.
38+
(If you did run that, check that you've got a fresh `yarn install`)
39+
""",
40+
minimum_bazel_version = "0.27.0",
41+
)
2742

43+
# The NodeJS rules version must be at least the following version because:
44+
# - 0.15.2 Re-introduced the prod_only attribute on yarn_install
45+
# - 0.15.3 Includes a fix for the `jasmine_node_test` rule ignoring target tags
46+
# - 0.16.8 Supports npm installed bazel workspaces
47+
# - 0.26.0 Fix for data files in yarn_install and npm_install
48+
# - 0.27.12 Adds NodeModuleSources provider for transtive npm deps support
49+
# - 0.30.0 yarn_install now uses symlinked node_modules with new managed directories Bazel 0.26.0 feature
50+
# - 0.31.1 entry_point attribute of nodejs_binary & rollup_bundle is now a label
51+
# - 0.32.0 yarn_install and npm_install no longer puts build files under symlinked node_modules
52+
# - 0.32.1 remove override of @bazel/tsetse & exclude typescript lib declarations in node_module_library transitive_declarations
53+
# - 0.32.2 resolves bug in @bazel/hide-bazel-files postinstall step
54+
# - 0.34.0 introduces protractor rule
55+
check_rules_nodejs_version(minimum_version_string = "0.34.0")
56+
57+
# Setup the Node.js toolchain
2858
node_repositories(
2959
node_repositories = {
30-
"10.9.0-darwin_amd64": (
31-
"node-v10.9.0-darwin-x64.tar.gz",
32-
"node-v10.9.0-darwin-x64",
33-
"3c4fe75dacfcc495a432a7ba2dec9045cff359af2a5d7d0429c84a424ef686fc",
34-
),
35-
"10.9.0-linux_amd64": (
36-
"node-v10.9.0-linux-x64.tar.xz",
37-
"node-v10.9.0-linux-x64",
38-
"c5acb8b7055ee0b6ac653dc4e458c5db45348cecc564b388f4ed1def84a329ff",
39-
),
40-
"10.9.0-windows_amd64": (
41-
"node-v10.9.0-win-x64.zip",
42-
"node-v10.9.0-win-x64",
43-
"6a75cdbb69d62ed242d6cbf0238a470bcbf628567ee339d4d098a5efcda2401e",
44-
),
45-
},
46-
node_version = "10.9.0",
47-
yarn_repositories = {
48-
"1.9.2": (
49-
"yarn-v1.9.2.tar.gz",
50-
"yarn-v1.9.2",
51-
"3ad69cc7f68159a562c676e21998eb21b44138cae7e8fe0749a7d620cf940204",
52-
),
60+
"10.16.0-darwin_amd64": ("node-v10.16.0-darwin-x64.tar.gz", "node-v10.16.0-darwin-x64", "6c009df1b724026d84ae9a838c5b382662e30f6c5563a0995532f2bece39fa9c"),
61+
"10.16.0-linux_amd64": ("node-v10.16.0-linux-x64.tar.xz", "node-v10.16.0-linux-x64", "1827f5b99084740234de0c506f4dd2202a696ed60f76059696747c34339b9d48"),
62+
"10.16.0-windows_amd64": ("node-v10.16.0-win-x64.zip", "node-v10.16.0-win-x64", "aa22cb357f0fb54ccbc06b19b60e37eefea5d7dd9940912675d3ed988bf9a059"),
5363
},
54-
yarn_version = "1.9.2",
64+
node_version = "10.16.0",
65+
package_json = ["//:package.json"],
66+
# yarn 1.13.0 under Bazel has a regression on Windows that causes build errors on rebuilds:
67+
# ```
68+
# ERROR: Source forest creation failed: C:/.../fyuc5c3n/execroot/angular/external (Directory not empty)
69+
# ```
70+
# See https://github.com/angular/angular/pull/29431 for more information.
71+
# It possible that versions of yarn past 1.13.0 do not have this issue, however, before
72+
# advancing this version we need to test manually on Windows that the above error does not
73+
# happen as the issue is not caught by CI.
74+
yarn_version = "1.12.1",
5575
)
5676

5777
yarn_install(
@@ -60,6 +80,7 @@ yarn_install(
6080
"//:tools/yarn/check-yarn.js",
6181
],
6282
package_json = "//:package.json",
83+
symlink_node_modules = False,
6384
yarn_lock = "//:yarn.lock",
6485
)
6586

@@ -87,27 +108,30 @@ web_test_repositories()
87108
# Bring in bazel_toolchains for RBE setup configuration.
88109
http_archive(
89110
name = "bazel_toolchains",
90-
sha256 = "54764b510cf45754c01ac65c9ba83e5f8fc8a033b8296ef74c4e4d6d1dbfaf21",
91-
strip_prefix = "bazel-toolchains-d67435097bd65153a592ecdcc83094474914c205",
92-
urls = ["https://github.com/xingao267/bazel-toolchains/archive/d67435097bd65153a592ecdcc83094474914c205.tar.gz"],
111+
sha256 = "dcb58e7e5f0b4da54c6c5f8ebc65e63fcfb37414466010cf82ceff912162296e",
112+
strip_prefix = "bazel-toolchains-0.28.2",
113+
url = "https://github.com/bazelbuild/bazel-toolchains/archive/0.28.2.tar.gz",
93114
)
94115

95116
load("@bazel_toolchains//rules:environments.bzl", "clang_env")
96117
load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
97118

98119
rbe_autoconfig(
99120
name = "rbe_ubuntu1604_angular",
100-
# The sha256 of marketplace.gcr.io/google/rbe-ubuntu16-04 container that is
101-
# used by rbe_autoconfig() to pair toolchain configs in the @bazel_toolchains repo.
102-
base_container_digest = "sha256:677c1317f14c6fd5eba2fd8ec645bfdc5119f64b3e5e944e13c89e0525cc8ad1",
121+
# Need to specify a base container digest in order to ensure that we can use the checked-in
122+
# platform configurations for the "ubuntu16_04" image. Otherwise the autoconfig rule would
123+
# need to pull the image and run it in order determine the toolchain configuration. See:
124+
# https://github.com/bazelbuild/bazel-toolchains/blob/0.27.0/configs/ubuntu16_04_clang/versions.bzl
125+
base_container_digest = "sha256:94d7d8552902d228c32c8c148cc13f0effc2b4837757a6e95b73fdc5c5e4b07b",
103126
# Note that if you change the `digest`, you might also need to update the
104127
# `base_container_digest` to make sure marketplace.gcr.io/google/rbe-ubuntu16-04-webtest:<digest>
105128
# and marketplace.gcr.io/google/rbe-ubuntu16-04:<base_container_digest> have
106-
# the same Clang and JDK installed.
107-
# Clang is needed because of the dependency on @com_google_protobuf.
108-
# Java is needed for the Bazel's test executor Java tool.
109-
digest = "sha256:74a8e9dca4781d5f277a7bd8e7ea7ed0f5906c79c9cd996205b6d32f090c62f3",
129+
# the same Clang and JDK installed. Clang is needed because of the dependency on
130+
# @com_google_protobuf. Java is needed for the Bazel's test executor Java tool.
131+
digest = "sha256:76e2e4a894f9ffbea0a0cb2fbde741b5d223d40f265dbb9bca78655430173990",
110132
env = clang_env(),
111133
registry = "marketplace.gcr.io",
134+
# We can't use the default "ubuntu16_04" RBE image provided by the autoconfig because we need
135+
# a specific Linux kernel that comes with "libx11" in order to run headless browser tests.
112136
repository = "google/rbe-ubuntu16-04-webtest",
113137
)

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@
8282
"devDependencies": {
8383
"@angular/compiler": "~8.2.0-rc.0",
8484
"@angular/compiler-cli": "~8.2.0-rc.0",
85-
"@bazel/bazel": "0.24.1",
86-
"@bazel/buildifier": "^0.22.0",
87-
"@bazel/jasmine": "~0.26.0",
88-
"@bazel/karma": "~0.26.0",
89-
"@bazel/typescript": "~0.26.0",
85+
"@bazel/bazel": "0.28.1",
86+
"@bazel/buildifier": "^0.26.0",
87+
"@bazel/jasmine": "0.35.0",
88+
"@bazel/karma": "0.35.0",
89+
"@bazel/typescript": "0.35.0",
9090
"@types/browserslist": "^4.4.0",
9191
"@types/caniuse-lite": "^1.0.0",
9292
"@types/clean-css": "^4.2.1",
@@ -134,7 +134,7 @@
134134
"tar": "^4.4.4",
135135
"through2": "^2.0.3",
136136
"tree-kill": "^1.2.0",
137-
"ts-api-guardian": "0.4.4",
137+
"ts-api-guardian": "0.4.6",
138138
"ts-node": "^5.0.0",
139139
"tslint-no-circular-imports": "^0.7.0",
140140
"tslint-sonarts": "1.9.0",

packages/angular_devkit/core/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ ts_library(
125125
jasmine_node_test(
126126
name = "node_test",
127127
srcs = [":node_test_lib"],
128+
# TODO: Audit tests to determine if tests can be run in RBE environments
129+
local = True,
128130
deps = [
129131
"@npm//chokidar",
130132
"@npm//jasmine",

tools/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nodejs_binary(
1212
data = [
1313
"quicktype_runner.js",
1414
],
15-
entry_point = "angular_cli/tools/quicktype_runner.js",
15+
entry_point = "quicktype_runner.js",
1616
install_source_map_support = False,
1717
node_modules = "@npm//quicktype-core",
1818
templated_args = [

0 commit comments

Comments
 (0)