Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: depend on bazelisk rather than directly on Bazel #36078

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelversion
@@ -0,0 +1,3 @@
2.1.1
# [NB: this comment has to be after the first line, see https://github.com/bazelbuild/bazelisk/issues/117]
# When updating the Bazel version you also need to update the RBE toolchains version in package.bzl
7 changes: 4 additions & 3 deletions .circleci/config.yml
Expand Up @@ -195,10 +195,11 @@ commands:
- *cache_key_win_fallback
# Reinstall to get windows binaries.
- run: yarn install --frozen-lockfile --non-interactive
# Install @bazel/bazel globally and use that for the first run.
# Install @bazel/bazelisk globally and use that for the first run.
# Workaround for https://github.com/bazelbuild/rules_nodejs/issues/894
- run: yarn global add @bazel/bazel@$env:BAZEL_VERSION
- run: bazel info
# NB: the issue was for @bazel/bazel but the same problem applies to @bazel/bazelisk
- run: yarn global add @bazel/bazelisk@$env:BAZELISK_VERSION
- run: bazelisk info

notify_webhook_on_fail:
description: Notify a webhook about failure
Expand Down
10 changes: 5 additions & 5 deletions .circleci/windows-env.ps1
Expand Up @@ -14,12 +14,12 @@ Add-Content $profile '$Env:path = "${Env:ProgramFiles}\nodejs\;C:\Users\circleci
# Environment variables for Bazel
Add-Content $profile '$Env:BAZEL_SH = "C:\tools\msys64\usr\bin\bash.exe"'

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

# Remove the CircleCI checkout SSH override, because it breaks cloning repositories through Bazel.
# See https://circleci.com/gh/angular/angular/401454 for an example.
Expand Down
21 changes: 4 additions & 17 deletions WORKSPACE
Expand Up @@ -12,23 +12,10 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/1.4.1/rules_nodejs-1.4.1.tar.gz"],
)

# Check the bazel version and download npm dependencies
load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version", "check_rules_nodejs_version", "node_repositories", "yarn_install")

# Bazel version must be at least the following version because:
# - 0.26.0 managed_directories feature added which is required for nodejs rules 0.30.0
# - 0.27.0 has a fix for managed_directories after `rm -rf node_modules`
# - 2.1.0 feature added to honor .bazelignore in external repositories
check_bazel_version(
message = """
You no longer need to install Bazel on your machine.
Angular has a dependency on the @bazel/bazel package which supplies it.
Try running `yarn bazel` instead.
(If you did run that, check that you've got a fresh `yarn install`)

""",
minimum_bazel_version = "2.1.0",
)
# Check the rules_nodejs version and download npm dependencies
# Note: bazel (version 2 and after) will check the .bazelversion file so we don't need to
# assert on that.
load("@build_bazel_rules_nodejs//:index.bzl", "check_rules_nodejs_version", "node_repositories", "yarn_install")

check_rules_nodejs_version(minimum_version_string = "1.4.1")

Expand Down
12 changes: 6 additions & 6 deletions aio/content/guide/bazel.md
Expand Up @@ -82,16 +82,16 @@ Documentation for using Bazel for frontend projects is linked from https://docs.
## Running Bazel directly

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

The common commands in Bazel are:

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

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

The output locations are printed in the output.

Expand Down
2 changes: 1 addition & 1 deletion docs/BAZEL.md
Expand Up @@ -13,7 +13,7 @@ In order to ensure that everyone builds Angular in a _consistent_ way, Bazel
will be installed through NPM and therefore it's not necessary to install Bazel
manually.

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

You can access Bazel with the `yarn bazel` command
Expand Down
2 changes: 1 addition & 1 deletion integration/angular_integration_test.bzl
Expand Up @@ -26,7 +26,7 @@ NPM_PACKAGE_ARCHIVES = [
"webdriver-manager",
"@angular/cli",
"@angular-devkit/build-angular",
"@bazel/bazel",
"@bazel/bazelisk",
"@types/jasmine",
"@types/jasminewd2",
"@types/node",
Expand Down
19 changes: 9 additions & 10 deletions integration/bazel-schematics/package.json
Expand Up @@ -8,16 +8,15 @@
"@angular/animations": "file:../../dist/packages-dist/animations",
"@angular/bazel": "file:../../dist/packages-dist/bazel",
"@angular/cli": "file:../../node_modules/@angular/cli",
"@angular/common": "file:../../node_modules/@angular/common",
"@angular/compiler": "file:../../node_modules/@angular/compiler",
"@angular/compiler-cli": "file:../../node_modules/@angular/compiler-cli",
"@angular/core": "file:../../node_modules/@angular/core",
"@angular/forms": "file:../../node_modules/@angular/forms",
"@angular/language-service": "file:../../node_modules/@angular/language-service",
"@angular/platform-browser": "file:../../node_modules/@angular/platform-browser",
"@angular/platform-browser-dynamic": "file:../../node_modules/@angular/platform-browser-dynamic",
"@angular/router": "file:../../node_modules/@angular/router",
"@bazel/bazel": "file:../../node_modules/@bazel/bazel",
"@angular/common": "file:../../dist/packages-dist/common",
"@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/core": "file:../../dist/packages-dist/core",
"@angular/forms": "file:../../dist/packages-dist/forms",
"@angular/language-service": "file:../../dist/packages-dist/language-service",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
"@angular/router": "file:../../dist/packages-dist/router",
"@types/node": "file:../../node_modules/@types/node",
"patch-package": "^6.2.1",
"protractor": "file:../../node_modules/protractor",
Expand Down
1 change: 0 additions & 1 deletion integration/bazel-schematics/test.sh
Expand Up @@ -52,7 +52,6 @@ function patchProtractorConf() {

function testBazel() {
# Set up
bazel version
ng version
rm -rf demo
# Create project
Expand Down