From 938753f7f4d13257e59a4a0a380d2eb5613d0f39 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 11 Jan 2022 20:36:18 -0800 Subject: [PATCH] chore: remove check_bazel_version Also check_rules_nodejs_version, though a stub is left behind to avoid needing a patch in rules_sass which calls it. We can use the one in bazel_skylib instead. Fixes #2622 --- docs/Built-ins.md | 34 ------- index.bzl | 9 +- index.for_docs.bzl | 2 - internal/common/BUILD.bazel | 3 - internal/common/check_bazel_version.bzl | 92 ------------------- internal/node/BUILD.bazel | 1 + internal/node/node_repositories.bzl | 9 +- internal/npm_install/npm_install.bzl | 22 ----- .../concatjs/internal/ts_repositories.bzl | 7 +- 9 files changed, 8 insertions(+), 171 deletions(-) delete mode 100644 internal/common/check_bazel_version.bzl diff --git a/docs/Built-ins.md b/docs/Built-ins.md index bc63a1ea6b..3cd8f8e3f1 100755 --- a/docs/Built-ins.md +++ b/docs/Built-ins.md @@ -1631,40 +1631,6 @@ Defaults to `@yarn//:bin/yarn` -## check_bazel_version - -**USAGE** - -
-check_bazel_version(minimum_bazel_version, message)
-
- - Verify the users Bazel version is at least the given one. - -This can be used in rule implementations that depend on changes in Bazel, -to warn users about a mismatch between the rule and their installed Bazel -version. - -This should *not* be used in users WORKSPACE files. To locally pin your -Bazel version, just create the .bazelversion file in your workspace. - - -**PARAMETERS** - - -

minimum_bazel_version

- -a string indicating the minimum version - - - -

message

- -optional string to print to your users, could be used to help them update - -Defaults to `""` - - ## copy_to_bin **USAGE** diff --git a/index.bzl b/index.bzl index 5260f8e824..ffbd36ea2b 100644 --- a/index.bzl +++ b/index.bzl @@ -18,7 +18,6 @@ Users should not load files under "/internal" """ load("//:version.bzl", "VERSION") -load("//internal/common:check_bazel_version.bzl", _check_bazel_version = "check_bazel_version") load("//internal/common:check_version.bzl", "check_version") load("//internal/common:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin") load("//internal/common:params_file.bzl", _params_file = "params_file") @@ -35,7 +34,6 @@ load("//internal/npm_install:npm_install.bzl", _npm_install = "npm_install", _ya load("//internal/pkg_npm:pkg_npm.bzl", _pkg_npm = "pkg_npm_macro") load("//internal/pkg_web:pkg_web.bzl", _pkg_web = "pkg_web") -check_bazel_version = _check_bazel_version nodejs_binary = _nodejs_binary nodejs_test = _nodejs_test node_repositories = _node_repositories @@ -102,7 +100,6 @@ def check_build_bazel_rules_nodejs_version(minimum_version_string): minimum_version_string, )) -# Export check_rules_nodejs_version symbol for pre-5.0 backward compat. This -# will eventually get removed as we move to the core @rules_nodejs package in -# future release. -check_rules_nodejs_version = check_build_bazel_rules_nodejs_version +def check_rules_nodejs_version(): + # buildifier: disable=print + print("check_rules_nodejs_version has been removed. This is a no-op, please remove the call.") diff --git a/index.for_docs.bzl b/index.for_docs.bzl index 42eab46716..50b0181703 100644 --- a/index.for_docs.bzl +++ b/index.for_docs.bzl @@ -23,7 +23,6 @@ via the `WORKSPACE` install of the `build_bazel_rules_nodejs` workspace. This is necessary to bootstrap Bazel to run the package manager to download other rules from NPM. """ -load("//internal/common:check_bazel_version.bzl", _check_bazel_version = "check_bazel_version") load("//internal/common:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin") load("//internal/common:params_file.bzl", _params_file = "params_file") load("//internal/generated_file_test:generated_file_test.bzl", _generated_file_test = "generated_file_test") @@ -34,7 +33,6 @@ load("//internal/npm_install:npm_install.bzl", _npm_install = "npm_install", _ya load("//internal/pkg_npm:pkg_npm.bzl", _pkg_npm = "pkg_npm") load("//internal/pkg_web:pkg_web.bzl", _pkg_web = "pkg_web") -check_bazel_version = _check_bazel_version copy_to_bin = _copy_to_bin params_file = _params_file nodejs_binary = _nodejs_binary diff --git a/internal/common/BUILD.bazel b/internal/common/BUILD.bazel index da347500d1..d0baa65c45 100644 --- a/internal/common/BUILD.bazel +++ b/internal/common/BUILD.bazel @@ -27,9 +27,6 @@ bzl_library( visibility = ["//visibility:public"], ) -# Exported to be consumed for generating stardoc. -exports_files(["check_bazel_version.bzl"]) - check_version_test_suite() filegroup( diff --git a/internal/common/check_bazel_version.bzl b/internal/common/check_bazel_version.bzl deleted file mode 100644 index ace77fcae8..0000000000 --- a/internal/common/check_bazel_version.bzl +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Check Bazel version - -We recommend forcing all users to update to at least the same version of Bazel -as the continuous integration, so they don't trip over incompatibilities with -rules used in the project. -""" - -load(":check_version.bzl", "check_version", "check_version_range") - -# From https://github.com/tensorflow/tensorflow/blob/5541ef4fbba56cf8930198373162dd3119e6ee70/tensorflow/workspace.bzl#L44 - -# Check that a specific bazel version is being used. -# Args: minimum_bazel_version in the form ".." -def check_bazel_version(minimum_bazel_version, message = ""): - """ - Verify the users Bazel version is at least the given one. - - This can be used in rule implementations that depend on changes in Bazel, - to warn users about a mismatch between the rule and their installed Bazel - version. - - This should *not* be used in users WORKSPACE files. To locally pin your - Bazel version, just create the .bazelversion file in your workspace. - - Args: - minimum_bazel_version: a string indicating the minimum version - message: optional string to print to your users, could be used to help them update - """ - if "bazel_version" not in dir(native): - fail("\nCurrent Bazel version is lower than 0.2.1, expected at least %s\n" % - minimum_bazel_version) - elif native.bazel_version and not check_version(native.bazel_version, minimum_bazel_version): - fail("\nCurrent Bazel version is {}, expected at least {}\n{}".format( - native.bazel_version, - minimum_bazel_version, - message, - )) - -# Check that a bazel version being used is in the version range. -# Args: -# minimum_bazel_version in the form ".." -# maximum_bazel_version in the form ".." -def check_bazel_version_range(minimum_bazel_version, maximum_bazel_version, message = ""): - """ - Verify the users Bazel version is in the version range. - - This should be called from the `WORKSPACE` file so that the build fails as - early as possible. For example: - - ``` - # in WORKSPACE: - load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version_range") - check_bazel_version_range("0.11.0", "0.22.0") - ``` - - Args: - minimum_bazel_version: a string indicating the minimum version - maximum_bazel_version: a string indicating the maximum version - message: optional string to print to your users, could be used to help them update - """ - if "bazel_version" not in dir(native): - fail("\nCurrent Bazel version is lower than 0.2.1, expected at least %s\n" % - minimum_bazel_version) - elif not native.bazel_version: - print("\nCurrent Bazel is not a release version, cannot check for " + - "compatibility.") - print("Make sure that you are running at least Bazel %s.\n" % minimum_bazel_version) - elif not check_version_range( - native.bazel_version, - minimum_bazel_version, - maximum_bazel_version, - ): - fail("\nCurrent Bazel version is {}, expected >= {} and <= {}\n{}".format( - native.bazel_version, - minimum_bazel_version, - maximum_bazel_version, - message, - )) diff --git a/internal/node/BUILD.bazel b/internal/node/BUILD.bazel index 308fa2148a..f8b877fd2d 100644 --- a/internal/node/BUILD.bazel +++ b/internal/node/BUILD.bazel @@ -31,6 +31,7 @@ bzl_library( "//internal/npm_install:bzl", "//third_party/github.com/bazelbuild/bazel-skylib:bzl", "@bazel_skylib//lib:types", + "@bazel_skylib//lib:versions", "@rules_nodejs//nodejs:bzl", ], ) diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index 114cf3ab57..00f894ba3c 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -18,11 +18,11 @@ This is a set of repository rules for setting up hermetic copies of NodeJS and Y See https://docs.bazel.build/versions/main/skylark/repository_rules.html """ +load("@bazel_skylib//lib:versions.bzl", "versions") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("@rules_nodejs//nodejs/private:os_name.bzl", "OS_ARCH_NAMES", "node_exists_for_os", "os_name") load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains", node_repositories_rule = "node_repositories") load("@rules_nodejs//nodejs:yarn_repositories.bzl", "yarn_repositories") -load("//internal/common:check_bazel_version.bzl", "check_bazel_version") def node_repositories(**kwargs): """ @@ -35,12 +35,7 @@ def node_repositories(**kwargs): """ # Require that users update Bazel, so that we don't need to support older ones. - check_bazel_version( - message = """ - Bazel current LTS version (4.0.0) is the minimum required to use rules_nodejs. - """, - minimum_bazel_version = "4.0.0", - ) + versions.check("4.0.0") # Back-compat: allow yarn_repositories args to be provided to node_repositories yarn_args = {} diff --git a/internal/npm_install/npm_install.bzl b/internal/npm_install/npm_install.bzl index 3f61bc04be..79d04f968d 100644 --- a/internal/npm_install/npm_install.bzl +++ b/internal/npm_install/npm_install.bzl @@ -24,7 +24,6 @@ See discussion in the README. load("@rules_nodejs//nodejs/private:os_name.bzl", "is_windows_os", "os_name") load("@rules_nodejs//nodejs/private:node_labels.bzl", "get_node_label", "get_npm_label") load("//:version.bzl", "VERSION") -load("//internal/common:check_bazel_version.bzl", "check_bazel_version") COMMON_ATTRIBUTES = dict(dict(), **{ "data": attr.label_list( @@ -637,27 +636,8 @@ def _symlink_node_modules(repository_ctx): repository_ctx.path("node_modules"), ) -def _check_min_bazel_version(rule, repository_ctx): - if repository_ctx.attr.symlink_node_modules: - # When using symlink_node_modules enforce the minimum Bazel version required - check_bazel_version( - message = """ - A minimum Bazel version of 0.26.0 is required for the %s @%s repository rule. - - By default, yarn_install and npm_install in build_bazel_rules_nodejs >= 0.30.0 - depends on the managed directory feature added in Bazel 0.26.0. See - https://github.com/bazelbuild/rules_nodejs/wiki#migrating-to-rules_nodejs-030. - - You can opt out of this feature by setting `symlink_node_modules = False` - on all of your yarn_install & npm_install rules. - """ % (rule, repository_ctx.attr.name), - minimum_bazel_version = "0.26.0", - ) - def _npm_install_impl(repository_ctx): """Core implementation of npm_install.""" - _check_min_bazel_version("npm_install", repository_ctx) - is_windows_host = is_windows_os(repository_ctx) node = repository_ctx.path(get_node_label(repository_ctx)) npm = get_npm_label(repository_ctx) @@ -804,8 +784,6 @@ def _detect_yarn_version(rctx, yarn): def _yarn_install_impl(repository_ctx): """Core implementation of yarn_install.""" - _check_min_bazel_version("yarn_install", repository_ctx) - is_windows_host = is_windows_os(repository_ctx) node = repository_ctx.path(get_node_label(repository_ctx)) yarn_label = repository_ctx.attr.yarn diff --git a/packages/concatjs/internal/ts_repositories.bzl b/packages/concatjs/internal/ts_repositories.bzl index 30cb4053f6..1d655a99d4 100644 --- a/packages/concatjs/internal/ts_repositories.bzl +++ b/packages/concatjs/internal/ts_repositories.bzl @@ -20,7 +20,7 @@ load("@bazel_gazelle//:deps.bzl", "go_repository") # END-DEV-ONLY -load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version", "check_rules_nodejs_version") +load("@bazel_skylib//lib:versions.bzl", "versions") def ts_setup_workspace(): """This repository rule should be called from your WORKSPACE file. @@ -30,10 +30,7 @@ def ts_setup_workspace(): """ # 0.18.0: support for .bazelignore - check_bazel_version("0.18.0") - - # 0.16.8: ng_package fix for packaging binary files - check_rules_nodejs_version("0.16.8") + versions.check("0.18.0") # BEGIN-DEV-ONLY def ts_setup_dev_workspace():