Skip to content

Commit 46fe8fb

Browse files
alexeagleAndrewKushnir
authored andcommitted
build: depend on bazelisk rather than directly on Bazel (angular#36078)
This has a couple benefits: - we now use a .bazelversion file rather than package.json to pin the version of bazel we want. This means even if you install bazel on your computer rather than via yarn, you'll still get a warning if your bazel version is wrong. - you no longer end up downloading three copies of bazel due to bugs in both npm and yarn where they download all tarballs before checking the metadata to see which are usable on the local platform. - bazelisk correctly handles the tools/bazel trick for wrapping functionality, which we want to use to instrument developer build latencies PR Close angular#36078
1 parent 31bec8c commit 46fe8fb

File tree

18 files changed

+323
-542
lines changed

18 files changed

+323
-542
lines changed

.bazelversion

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2.1.1
2+
# [NB: this comment has to be after the first line, see https://github.com/bazelbuild/bazelisk/issues/117]
3+
# When updating the Bazel version you also need to update the RBE toolchains version in package.bzl

.circleci/config.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,11 @@ commands:
195195
- *cache_key_win_fallback
196196
# Reinstall to get windows binaries.
197197
- run: yarn install --frozen-lockfile --non-interactive
198-
# Install @bazel/bazel globally and use that for the first run.
198+
# Install @bazel/bazelisk globally and use that for the first run.
199199
# Workaround for https://github.com/bazelbuild/rules_nodejs/issues/894
200-
- run: yarn global add @bazel/bazel@$env:BAZEL_VERSION
201-
- run: bazel info
200+
# NB: the issue was for @bazel/bazel but the same problem applies to @bazel/bazelisk
201+
- run: yarn global add @bazel/bazelisk@$env:BAZELISK_VERSION
202+
- run: bazelisk info
202203

203204
notify_webhook_on_fail:
204205
description: Notify a webhook about failure

.circleci/windows-env.ps1

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ Add-Content $profile '$Env:path = "${Env:ProgramFiles}\nodejs\;C:\Users\circleci
1414
# Environment variables for Bazel
1515
Add-Content $profile '$Env:BAZEL_SH = "C:\tools\msys64\usr\bin\bash.exe"'
1616

17-
# Get the bazel version devdep and store it in a global var for use in the circleci job.
18-
$bazelVersion = & ${Env:ProgramFiles}\nodejs\node.exe -e "console.log(require('./package.json').devDependencies['@bazel/bazel'])"
19-
# This is a tricky situation: we want $bazelVersion to be evaluated but not $Env:BAZEL_VERSION.
17+
# Get the bazelisk version devdep and store it in a global var for use in the circleci job.
18+
$bazeliskVersion = & ${Env:ProgramFiles}\nodejs\node.exe -e "console.log(require('./package.json').devDependencies['@bazel/bazelisk'])"
19+
# This is a tricky situation: we want $bazeliskVersion to be evaluated but not $Env:BAZELISK_VERSION.
2020
# Formatting works https://stackoverflow.com/questions/32127583/expand-variable-inside-single-quotes
21-
$bazelVersionGlobalVar = '$Env:BAZEL_VERSION = "{0}"' -f $bazelVersion
22-
Add-Content $profile $bazelVersionGlobalVar
21+
$bazeliskVersionGlobalVar = '$Env:BAZELISK_VERSION = "{0}"' -f $bazeliskVersion
22+
Add-Content $profile $bazeliskVersionGlobalVar
2323

2424
# Remove the CircleCI checkout SSH override, because it breaks cloning repositories through Bazel.
2525
# See https://circleci.com/gh/angular/angular/401454 for an example.

WORKSPACE

+4-17
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,10 @@ http_archive(
1212
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/1.4.1/rules_nodejs-1.4.1.tar.gz"],
1313
)
1414

15-
# Check the bazel version and download npm dependencies
16-
load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version", "check_rules_nodejs_version", "node_repositories", "yarn_install")
17-
18-
# Bazel version must be at least the following version because:
19-
# - 0.26.0 managed_directories feature added which is required for nodejs rules 0.30.0
20-
# - 0.27.0 has a fix for managed_directories after `rm -rf node_modules`
21-
# - 2.1.0 feature added to honor .bazelignore in external repositories
22-
check_bazel_version(
23-
message = """
24-
You no longer need to install Bazel on your machine.
25-
Angular has a dependency on the @bazel/bazel package which supplies it.
26-
Try running `yarn bazel` instead.
27-
(If you did run that, check that you've got a fresh `yarn install`)
28-
29-
""",
30-
minimum_bazel_version = "2.1.0",
31-
)
15+
# Check the rules_nodejs version and download npm dependencies
16+
# Note: bazel (version 2 and after) will check the .bazelversion file so we don't need to
17+
# assert on that.
18+
load("@build_bazel_rules_nodejs//:index.bzl", "check_rules_nodejs_version", "node_repositories", "yarn_install")
3219

3320
check_rules_nodejs_version(minimum_version_string = "1.4.1")
3421

aio/content/guide/bazel.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ Documentation for using Bazel for frontend projects is linked from https://docs.
8282
## Running Bazel directly
8383

8484
In some cases you'll want to bypass the Angular CLI builder, and run the Bazel CLI directly.
85-
The Bazel CLI is in the `@bazel/bazel` npm package.
86-
You can install it globally to get the `bazel` command in your path, or use `$(npm bin)/bazel` in place of bazel below.
85+
The Bazel tool is managed by the `@bazel/bazelisk` package (similar to how Node.js can be managed by `nvm`).
86+
You can install it globally to get the `bazelisk` command in your path, or use `$(npm bin)/bazelisk` in place of bazelisk below.
8787

8888
The common commands in Bazel are:
8989

90-
* `bazel build [targets]`: Compile the default output artifacts of the given targets.
91-
* `bazel test [targets]`: For whichever `*_test` targets are found in the patterns, run the tests.
92-
* `bazel run [target]`: Compile the program represented by target, and then run it.
90+
* `bazelisk build [targets]`: Compile the default output artifacts of the given targets.
91+
* `bazelisk test [targets]`: For whichever `*_test` targets are found in the patterns, run the tests.
92+
* `bazelisk run [target]`: Compile the program represented by target, and then run it.
9393

94-
To repeat the command any time the inputs change (watch mode), replace `bazel` with `ibazel` in these commands.
94+
To repeat the command any time the inputs change (watch mode), replace `bazelisk` with `ibazel` in these commands.
9595

9696
The output locations are printed in the output.
9797

docs/BAZEL.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ In order to ensure that everyone builds Angular in a _consistent_ way, Bazel
1313
will be installed through NPM and therefore it's not necessary to install Bazel
1414
manually.
1515

16-
The binaries for Bazel will be provided by the [`@bazel/bazel`](https://github.com/bazelbuild/rules_nodejs/tree/master/packages)
16+
The binaries for Bazel will be provided by the [`@bazel/bazelisk`](https://github.com/bazelbuild/bazelisk)
1717
NPM package and its platform-specific dependencies.
1818

1919
You can access Bazel with the `yarn bazel` command

integration/angular_integration_test.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ NPM_PACKAGE_ARCHIVES = [
2626
"webdriver-manager",
2727
"@angular/cli",
2828
"@angular-devkit/build-angular",
29-
"@bazel/bazel",
29+
"@bazel/bazelisk",
3030
"@types/jasmine",
3131
"@types/jasminewd2",
3232
"@types/node",

integration/bazel-schematics/package.json

+9-10
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
"@angular/animations": "file:../../dist/packages-dist/animations",
99
"@angular/bazel": "file:../../dist/packages-dist/bazel",
1010
"@angular/cli": "file:../../node_modules/@angular/cli",
11-
"@angular/common": "file:../../node_modules/@angular/common",
12-
"@angular/compiler": "file:../../node_modules/@angular/compiler",
13-
"@angular/compiler-cli": "file:../../node_modules/@angular/compiler-cli",
14-
"@angular/core": "file:../../node_modules/@angular/core",
15-
"@angular/forms": "file:../../node_modules/@angular/forms",
16-
"@angular/language-service": "file:../../node_modules/@angular/language-service",
17-
"@angular/platform-browser": "file:../../node_modules/@angular/platform-browser",
18-
"@angular/platform-browser-dynamic": "file:../../node_modules/@angular/platform-browser-dynamic",
19-
"@angular/router": "file:../../node_modules/@angular/router",
20-
"@bazel/bazel": "file:../../node_modules/@bazel/bazel",
11+
"@angular/common": "file:../../dist/packages-dist/common",
12+
"@angular/compiler": "file:../../dist/packages-dist/compiler",
13+
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
14+
"@angular/core": "file:../../dist/packages-dist/core",
15+
"@angular/forms": "file:../../dist/packages-dist/forms",
16+
"@angular/language-service": "file:../../dist/packages-dist/language-service",
17+
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
18+
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
19+
"@angular/router": "file:../../dist/packages-dist/router",
2120
"@types/node": "file:../../node_modules/@types/node",
2221
"patch-package": "^6.2.1",
2322
"protractor": "file:../../node_modules/protractor",

integration/bazel-schematics/test.sh

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ function patchProtractorConf() {
5252

5353
function testBazel() {
5454
# Set up
55-
bazel version
5655
ng version
5756
rm -rf demo
5857
# Create project

0 commit comments

Comments
 (0)