build: depend on bazelisk rather than directly on Bazel (#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 #36078
This commit is contained in:
committed by
Andrew Kushnir
parent
31bec8ce61
commit
46fe8fb8b4
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -52,7 +52,6 @@ function patchProtractorConf() {
|
||||
|
||||
function testBazel() {
|
||||
# Set up
|
||||
bazel version
|
||||
ng version
|
||||
rm -rf demo
|
||||
# Create project
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
2.2.0
|
||||
@@ -22,7 +22,7 @@
|
||||
"@angular/bazel": "file:../../dist/packages-dist/bazel",
|
||||
"@angular/compiler": "file:../../dist/packages-dist/compiler",
|
||||
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
|
||||
"@bazel/bazel": "file:../../node_modules/@bazel/bazel",
|
||||
"@bazel/bazelisk": "file:../../node_modules/@bazel/bazelisk",
|
||||
"@bazel/karma": "1.4.1",
|
||||
"@bazel/protractor": "1.4.1",
|
||||
"@bazel/rollup": "1.4.1",
|
||||
@@ -46,7 +46,7 @@
|
||||
"typescript": "3.7.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "bazel build ... --noshow_progress && bazel test ...",
|
||||
"test": "bazelisk build ... --noshow_progress && bazelisk test ...",
|
||||
"postinstall": "ngcc"
|
||||
}
|
||||
}
|
||||
|
||||
+160
-341
File diff suppressed because it is too large
Load Diff
+8
-9
@@ -23,14 +23,14 @@
|
||||
"postinstall": "node scripts/webdriver-manager-update.js && node --preserve-symlinks --preserve-symlinks-main ./tools/postinstall-patches.js",
|
||||
"check-env": "gulp check-env",
|
||||
"commitmsg": "node ./scripts/git/commit-msg.js",
|
||||
"test-ivy-aot": "bazel test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot",
|
||||
"test-non-ivy": "bazel test --build_tag_filters=-ivy-only --test_tag_filters=-ivy-only",
|
||||
"test-fixme-ivy-aot": "bazel test --config=ivy --build_tag_filters=-no-ivy-aot --test_tag_filters=-no-ivy-aot",
|
||||
"list-fixme-ivy-targets": "bazel query --output=label 'attr(\"tags\", \"\\[.*fixme-ivy.*\\]\", //...) except kind(\"sh_binary\", //...) except kind(\"devmode_js_sources\", //...)' | sort",
|
||||
"bazel": "bazel",
|
||||
"test-ivy-aot": "bazelisk test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot",
|
||||
"test-non-ivy": "bazelisk test --build_tag_filters=-ivy-only --test_tag_filters=-ivy-only",
|
||||
"test-fixme-ivy-aot": "bazelisk test --config=ivy --build_tag_filters=-no-ivy-aot --test_tag_filters=-no-ivy-aot",
|
||||
"list-fixme-ivy-targets": "bazelisk query --output=label 'attr(\"tags\", \"\\[.*fixme-ivy.*\\]\", //...) except kind(\"sh_binary\", //...) except kind(\"devmode_js_sources\", //...)' | sort",
|
||||
"bazel": "bazelisk",
|
||||
"//circleci-win-comment": "See the test-win circleci job for why these are needed. If they are not needed anymore, remove them.",
|
||||
"circleci-win-ve": "bazel test --build_tag_filters=-ivy-only --test_tag_filters=-ivy-only,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/...",
|
||||
"circleci-win-ivy": "bazel test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/...",
|
||||
"circleci-win-ve": "bazelisk test --build_tag_filters=-ivy-only --test_tag_filters=-ivy-only,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/...",
|
||||
"circleci-win-ivy": "bazelisk test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot,-browser:chromium-local //packages/compiler-cli/... //tools/ts-api-guardian/...",
|
||||
"lint": "yarn -s tslint && yarn gulp lint",
|
||||
"tslint": "tsc -p tools/tsconfig.json && tslint -c tslint.json \"+(packages|modules|scripts|tools)/**/*.+(js|ts)\"",
|
||||
"public-api:check": "node goldens/public-api/manage.js test",
|
||||
@@ -142,10 +142,9 @@
|
||||
"yargs": "15.3.0"
|
||||
},
|
||||
"// 2": "devDependencies are not used under Bazel. Many can be removed after test.sh is deleted.",
|
||||
"// 3": "when updating @bazel/bazel version you also need to update the RBE settings in .bazelrc (see https://github.com/angular/angular/pull/27935)",
|
||||
"devDependencies": {
|
||||
"@angular/cli": "9.0.3",
|
||||
"@bazel/bazel": "2.1.0",
|
||||
"@bazel/bazelisk": "^1.3.0",
|
||||
"@bazel/buildifier": "^0.29.0",
|
||||
"@bazel/ibazel": "^0.12.2",
|
||||
"@octokit/graphql": "^4.3.1",
|
||||
|
||||
@@ -29,11 +29,11 @@ def rules_angular_dev_dependencies():
|
||||
_maybe(
|
||||
http_archive,
|
||||
name = "bazel_toolchains",
|
||||
sha256 = "4d348abfaddbcee0c077fc51bb1177065c3663191588ab3d958f027cbfe1818b",
|
||||
strip_prefix = "bazel-toolchains-2.1.0",
|
||||
sha256 = "b5a8039df7119d618402472f3adff8a1bd0ae9d5e253f53fcc4c47122e91a3d2",
|
||||
strip_prefix = "bazel-toolchains-2.1.1",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/releases/download/2.1.0/bazel-toolchains-2.1.0.tar.gz",
|
||||
"https://github.com/bazelbuild/bazel-toolchains/releases/download/2.1.0/bazel-toolchains-2.1.0.tar.gz",
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/releases/download/2.1.1/bazel-toolchains-2.1.1.tar.gz",
|
||||
"https://github.com/bazelbuild/bazel-toolchains/releases/download/2.1.1/bazel-toolchains-2.1.1.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
This docker container provides everything needed to build and test Angular applications:
|
||||
|
||||
**Note**: This docker image will be no longer actively updated. Consider using other Docker
|
||||
images that come with Node installed. Bazel can be installed through the `@bazel/bazel` NPM package.
|
||||
images that come with Node installed.
|
||||
|
||||
- node 10.9.0
|
||||
- npm 6.2.0
|
||||
|
||||
@@ -17,6 +17,9 @@ const VERBOSE_LOGS = !!process.env['VERBOSE_LOGS'];
|
||||
// Set to true if you want the /tmp folder created to persist after running `bazel test`
|
||||
const KEEP_TMP = false;
|
||||
|
||||
// bazelisk requires a $HOME environment variable for its cache
|
||||
process.env['HOME'] = tmp.dirSync({keep: KEEP_TMP, unsafeCleanup: !KEEP_TMP}).name;
|
||||
|
||||
function fail(...m) {
|
||||
console.error();
|
||||
console.error(`[${path.basename(__filename)}]`);
|
||||
|
||||
@@ -1041,31 +1041,10 @@
|
||||
lodash "^4.17.13"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@bazel/bazel[email protected].0":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-2.1.0.tgz#c36c37080841618f142996884f07ac0e3d6a9598"
|
||||
integrity sha512-9waB/6UT6JmQh8qxlRK9IfSY4Ef+4iGwy5eYK2hoc1zXYDnnZoZoC4eXiq68cWTpyCcT7SNGEb9B3wL5Y5rA9A==
|
||||
|
||||
"@bazel/[email protected]":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-2.1.0.tgz#3185cc3d2533641d6a539bf613247d628425ebf0"
|
||||
integrity sha512-ag6ZwYMJblf1YuPhNRAMyCYf164mY8jhdIwPSVFI1CMiBRnSDJBkSg7rVIczPh+8Gp7TDqAno9MMTnfUXzxogA==
|
||||
|
||||
"@bazel/[email protected]":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-2.1.0.tgz#013960fe506ddb8dc08f5d54b52420c818eb4264"
|
||||
integrity sha512-Y6cs3frmCqoAsrDmEp0msyS8VYE13JvjVoyvdIXTOh5Cc4fOeWzSPb02VS08asaV1jCnOQbv15Ud286hcxAvxg==
|
||||
|
||||
"@bazel/[email protected]":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-2.1.0.tgz#25a4d3b4171bfb637374133d29878bbcb36b4c92"
|
||||
integrity sha512-3Dhs0uJ69ImqC+VIRcifnptPXytxCNWHqyTMFYf0F5AJCVHHW7uRE0tt3Vhm5BseFpdOsjqcghgxGzR/yo10qw==
|
||||
dependencies:
|
||||
"@bazel/hide-bazel-files" latest
|
||||
optionalDependencies:
|
||||
"@bazel/bazel-darwin_x64" "2.1.0"
|
||||
"@bazel/bazel-linux_x64" "2.1.0"
|
||||
"@bazel/bazel-win32_x64" "2.1.0"
|
||||
"@bazel/bazelisk@^1.3.0":
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.3.0.tgz#dc312dd30ad01e9af86e53b40795ab6e545fa55b"
|
||||
integrity sha512-73H1nq3572tTf+dhDT86aWQN+LCyfxrh05jabqPXp6cpR8soxte3gS5oUqkN36fUe+J2HzNiV4CXZTz4Xytd3Q==
|
||||
|
||||
"@bazel/[email protected]":
|
||||
version "0.29.0"
|
||||
@@ -1091,11 +1070,6 @@
|
||||
"@bazel/buildifier-linux_x64" "0.29.0"
|
||||
"@bazel/buildifier-win32_x64" "0.29.0"
|
||||
|
||||
"@bazel/hide-bazel-files@latest":
|
||||
version "0.34.0"
|
||||
resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-0.34.0.tgz#368ea84db2756ff80ead23bb9eb179e9ed24b462"
|
||||
integrity sha512-suyO6cZf8iV6W2LkM1X1spWBt7CsRRXH7gU1wYNuAuHYkkfI0A6qj84yPiIXiOt/2G44kbioGyC1bUsI3fKv7A==
|
||||
|
||||
"@bazel/ibazel@^0.12.2":
|
||||
version "0.12.2"
|
||||
resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.12.2.tgz#98a290dbf8025076dd3040eab4f13a3d7e99357c"
|
||||
|
||||
Reference in New Issue
Block a user