cleanup: remove vendored copy of skylib (#1003)
Following #1001 we require that users install bazel-skylib, so we are now free to load from it.
diff --git a/BUILD.bazel b/BUILD.bazel
index 654e014..5e9b592 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -35,9 +35,6 @@
"//gazelle:distribution",
"//python:distribution",
"//python/pip_install:distribution",
- "//third_party/github.com/bazelbuild/bazel-skylib/lib:distribution",
- "//third_party/github.com/bazelbuild/bazel-skylib/rules:distribution",
- "//third_party/github.com/bazelbuild/bazel-skylib/rules/private:distribution",
"//tools:distribution",
],
visibility = [
diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel
index f2f13be..105a68e 100644
--- a/docs/BUILD.bazel
+++ b/docs/BUILD.bazel
@@ -109,7 +109,7 @@
deps = [
":bazel_repo_tools",
":pip_install_bzl",
- "//third_party/github.com/bazelbuild/bazel-skylib/lib:versions",
+ "@bazel_skylib//lib:versions",
],
)
@@ -122,7 +122,7 @@
":bazel_repo_tools",
":pip_install_bzl",
":requirements_parser_bzl",
- "//third_party/github.com/bazelbuild/bazel-skylib/lib:versions",
+ "@bazel_skylib//lib:versions",
],
)
diff --git a/examples/multi_python_versions/WORKSPACE b/examples/multi_python_versions/WORKSPACE
index 698bce8..41c8880 100644
--- a/examples/multi_python_versions/WORKSPACE
+++ b/examples/multi_python_versions/WORKSPACE
@@ -5,14 +5,14 @@
path = "../..",
)
-load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies")
-
-pip_install_dependencies()
-
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains")
py_repositories()
+load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies")
+
+pip_install_dependencies()
+
default_python_version = "3.9"
python_register_multi_toolchains(
diff --git a/python/pip_install/repositories.bzl b/python/pip_install/repositories.bzl
index 5ce427d..12fe940 100644
--- a/python/pip_install/repositories.bzl
+++ b/python/pip_install/repositories.bzl
@@ -1,11 +1,9 @@
""
+load("@bazel_skylib//lib:versions.bzl", "versions")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
-# Avoid a load from @bazel_skylib repository as users don't necessarily have it installed
-load("//third_party/github.com/bazelbuild/bazel-skylib/lib:versions.bzl", "versions")
-
_RULE_DEPS = [
(
"pypi__build",
diff --git a/python/pip_install/tools/wheel_installer/wheel_installer.py b/python/pip_install/tools/wheel_installer/wheel_installer.py
index a324fbb..1f6eaf2 100644
--- a/python/pip_install/tools/wheel_installer/wheel_installer.py
+++ b/python/pip_install/tools/wheel_installer/wheel_installer.py
@@ -226,7 +226,7 @@
textwrap.dedent(
"""\
load("@rules_python//python:defs.bzl", "py_library", "py_binary")
- load("@rules_python//third_party/github.com/bazelbuild/bazel-skylib/rules:copy_file.bzl", "copy_file")
+ load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
package(default_visibility = ["//visibility:public"])
diff --git a/tests/compile_pip_requirements/WORKSPACE b/tests/compile_pip_requirements/WORKSPACE
index d3fd700..d3a419c 100644
--- a/tests/compile_pip_requirements/WORKSPACE
+++ b/tests/compile_pip_requirements/WORKSPACE
@@ -3,12 +3,14 @@
path = "../..",
)
+load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
+
+py_repositories()
+
load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies")
pip_install_dependencies()
-load("@rules_python//python:repositories.bzl", "python_register_toolchains")
-
python_register_toolchains(
name = "python39",
python_version = "3.9",
diff --git a/third_party/github.com/bazelbuild/bazel-skylib/README.md b/third_party/github.com/bazelbuild/bazel-skylib/README.md
deleted file mode 100644
index 5ed93ff..0000000
--- a/third_party/github.com/bazelbuild/bazel-skylib/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# vendored copy of skylib
-
-This exists so that users of rules_python don't have to install bazel-skylib
-copied from https://github.com/bazelbuild/bazel-skylib/blob/1.0.3
\ No newline at end of file
diff --git a/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD b/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD
deleted file mode 100644
index 9560aed..0000000
--- a/third_party/github.com/bazelbuild/bazel-skylib/lib/BUILD
+++ /dev/null
@@ -1,22 +0,0 @@
-load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-
-licenses(["notice"])
-
-package(default_visibility = ["//visibility:public"])
-
-# export bzl files for the documentation
-exports_files(
- glob(["*.bzl"]),
- visibility = ["//:__subpackages__"],
-)
-
-filegroup(
- name = "distribution",
- srcs = glob(["**"]),
- visibility = ["//:__pkg__"],
-)
-
-bzl_library(
- name = "versions",
- srcs = ["versions.bzl"],
-)
diff --git a/third_party/github.com/bazelbuild/bazel-skylib/lib/versions.bzl b/third_party/github.com/bazelbuild/bazel-skylib/lib/versions.bzl
deleted file mode 100644
index 3cd6019..0000000
--- a/third_party/github.com/bazelbuild/bazel-skylib/lib/versions.bzl
+++ /dev/null
@@ -1,128 +0,0 @@
-# Copyright 2018 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.
-
-"""Skylib module containing functions for checking Bazel versions."""
-
-def _get_bazel_version():
- """Returns the current Bazel version"""
-
- return native.bazel_version
-
-def _extract_version_number(bazel_version):
- """Extracts the semantic version number from a version string
-
- Args:
- bazel_version: the version string that begins with the semantic version
- e.g. "1.2.3rc1 abc1234" where "abc1234" is a commit hash.
-
- Returns:
- The semantic version string, like "1.2.3".
- """
- for i in range(len(bazel_version)):
- c = bazel_version[i]
- if not (c.isdigit() or c == "."):
- return bazel_version[:i]
- return bazel_version
-
-# Parse the bazel version string from `native.bazel_version`.
-# e.g.
-# "0.10.0rc1 abc123d" => (0, 10, 0)
-# "0.3.0" => (0, 3, 0)
-def _parse_bazel_version(bazel_version):
- """Parses a version string into a 3-tuple of ints
-
- int tuples can be compared directly using binary operators (<, >).
-
- Args:
- bazel_version: the Bazel version string
-
- Returns:
- An int 3-tuple of a (major, minor, patch) version.
- """
-
- version = _extract_version_number(bazel_version)
- return tuple([int(n) for n in version.split(".")])
-
-def _is_at_most(threshold, version):
- """Check that a version is lower or equals to a threshold.
-
- Args:
- threshold: the maximum version string
- version: the version string to be compared to the threshold
-
- Returns:
- True if version <= threshold.
- """
- return _parse_bazel_version(version) <= _parse_bazel_version(threshold)
-
-def _is_at_least(threshold, version):
- """Check that a version is higher or equals to a threshold.
-
- Args:
- threshold: the minimum version string
- version: the version string to be compared to the threshold
-
- Returns:
- True if version >= threshold.
- """
-
- return _parse_bazel_version(version) >= _parse_bazel_version(threshold)
-
-def _check_bazel_version(minimum_bazel_version, maximum_bazel_version = None, bazel_version = None):
- """Check that the version of Bazel is valid within the specified range.
-
- Args:
- minimum_bazel_version: minimum version of Bazel expected
- maximum_bazel_version: maximum version of Bazel expected
- bazel_version: the version of Bazel to check. Used for testing, defaults to native.bazel_version
- """
- if not bazel_version:
- if "bazel_version" not in dir(native):
- fail("Bazel version cannot be determined; expected at least {}".format(
- minimum_bazel_version,
- ))
- elif not native.bazel_version:
- # Using a non-release version, assume it is good.
- return
- else:
- bazel_version = native.bazel_version
-
- if not _is_at_least(
- threshold = minimum_bazel_version,
- version = bazel_version,
- ):
- fail("Current Bazel version is {}; expected at least {}".format(
- bazel_version,
- minimum_bazel_version,
- ))
-
- if maximum_bazel_version:
- if not _is_at_most(
- threshold = maximum_bazel_version,
- version = bazel_version,
- ):
- fail("Current Bazel version is {}; expected at most {}".format(
- bazel_version,
- maximum_bazel_version,
- ))
-
- pass
-
-versions = struct(
- get = _get_bazel_version,
- parse = _parse_bazel_version,
- check = _check_bazel_version,
- is_at_most = _is_at_most,
- is_at_least = _is_at_least,
-)
diff --git a/third_party/github.com/bazelbuild/bazel-skylib/rules/BUILD b/third_party/github.com/bazelbuild/bazel-skylib/rules/BUILD
deleted file mode 100644
index 6857449..0000000
--- a/third_party/github.com/bazelbuild/bazel-skylib/rules/BUILD
+++ /dev/null
@@ -1,36 +0,0 @@
-load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-
-licenses(["notice"])
-
-package(default_visibility = ["//visibility:public"])
-
-bzl_library(
- name = "copy_file",
- srcs = ["copy_file.bzl"],
- deps = ["//third_party/github.com/bazelbuild/bazel-skylib/rules/private:copy_file_private"],
-)
-
-filegroup(
- name = "test_deps",
- testonly = True,
- srcs = [
- "BUILD",
- ] + glob(["*.bzl"]),
-)
-
-# The files needed for distribution
-filegroup(
- name = "distribution",
- srcs = [
- "BUILD",
- ] + glob(["*.bzl"]),
- visibility = [
- "//:__pkg__",
- ],
-)
-
-# export bzl files for the documentation
-exports_files(
- glob(["*.bzl"]),
- visibility = ["//:__subpackages__"],
-)
diff --git a/third_party/github.com/bazelbuild/bazel-skylib/rules/copy_file.bzl b/third_party/github.com/bazelbuild/bazel-skylib/rules/copy_file.bzl
deleted file mode 100644
index 2908fa6..0000000
--- a/third_party/github.com/bazelbuild/bazel-skylib/rules/copy_file.bzl
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright 2019 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.
-
-"""A rule that copies a file to another place.
-
-native.genrule() is sometimes used to copy files (often wishing to rename them).
-The 'copy_file' rule does this with a simpler interface than genrule.
-
-The rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command
-on Windows (no Bash is required).
-"""
-
-load(
- "@rules_python//third_party/github.com/bazelbuild/bazel-skylib/rules/private:copy_file_private.bzl",
- _copy_file = "copy_file",
-)
-
-copy_file = _copy_file
diff --git a/third_party/github.com/bazelbuild/bazel-skylib/rules/private/BUILD b/third_party/github.com/bazelbuild/bazel-skylib/rules/private/BUILD
deleted file mode 100644
index a1aeb39..0000000
--- a/third_party/github.com/bazelbuild/bazel-skylib/rules/private/BUILD
+++ /dev/null
@@ -1,18 +0,0 @@
-load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-
-licenses(["notice"])
-
-bzl_library(
- name = "copy_file_private",
- srcs = ["copy_file_private.bzl"],
- visibility = ["//third_party/github.com/bazelbuild/bazel-skylib/rules:__pkg__"],
-)
-
-# The files needed for distribution
-filegroup(
- name = "distribution",
- srcs = glob(["*"]),
- visibility = [
- "//:__subpackages__",
- ],
-)
diff --git a/third_party/github.com/bazelbuild/bazel-skylib/rules/private/copy_file_private.bzl b/third_party/github.com/bazelbuild/bazel-skylib/rules/private/copy_file_private.bzl
deleted file mode 100644
index d044c97..0000000
--- a/third_party/github.com/bazelbuild/bazel-skylib/rules/private/copy_file_private.bzl
+++ /dev/null
@@ -1,141 +0,0 @@
-# Copyright 2019 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.
-
-"""Implementation of copy_file macro and underlying rules.
-
-These rules copy a file to another location using Bash (on Linux/macOS) or
-cmd.exe (on Windows). '_copy_xfile' marks the resulting file executable,
-'_copy_file' does not.
-"""
-
-def copy_cmd(ctx, src, dst):
- # Most Windows binaries built with MSVC use a certain argument quoting
- # scheme. Bazel uses that scheme too to quote arguments. However,
- # cmd.exe uses different semantics, so Bazel's quoting is wrong here.
- # To fix that we write the command to a .bat file so no command line
- # quoting or escaping is required.
- bat = ctx.actions.declare_file(ctx.label.name + "-cmd.bat")
- ctx.actions.write(
- output = bat,
- # Do not use lib/shell.bzl's shell.quote() method, because that uses
- # Bash quoting syntax, which is different from cmd.exe's syntax.
- content = "@copy /Y \"%s\" \"%s\" >NUL" % (
- src.path.replace("/", "\\"),
- dst.path.replace("/", "\\"),
- ),
- is_executable = True,
- )
- ctx.actions.run(
- inputs = [src],
- tools = [bat],
- outputs = [dst],
- executable = "cmd.exe",
- arguments = ["/C", bat.path.replace("/", "\\")],
- mnemonic = "CopyFile",
- progress_message = "Copying files",
- use_default_shell_env = True,
- )
-
-def copy_bash(ctx, src, dst):
- ctx.actions.run_shell(
- tools = [src],
- outputs = [dst],
- command = "cp -f \"$1\" \"$2\"",
- arguments = [src.path, dst.path],
- mnemonic = "CopyFile",
- progress_message = "Copying files",
- use_default_shell_env = True,
- )
-
-def _copy_file_impl(ctx):
- if ctx.attr.allow_symlink:
- ctx.actions.symlink(
- output = ctx.outputs.out,
- target_file = ctx.file.src,
- is_executable = ctx.attr.is_executable,
- )
- elif ctx.attr.is_windows:
- copy_cmd(ctx, ctx.file.src, ctx.outputs.out)
- else:
- copy_bash(ctx, ctx.file.src, ctx.outputs.out)
-
- files = depset(direct = [ctx.outputs.out])
- runfiles = ctx.runfiles(files = [ctx.outputs.out])
- if ctx.attr.is_executable:
- return [DefaultInfo(files = files, runfiles = runfiles, executable = ctx.outputs.out)]
- else:
- return [DefaultInfo(files = files, runfiles = runfiles)]
-
-_ATTRS = {
- "allow_symlink": attr.bool(mandatory = True),
- "is_executable": attr.bool(mandatory = True),
- "is_windows": attr.bool(mandatory = True),
- "out": attr.output(mandatory = True),
- "src": attr.label(mandatory = True, allow_single_file = True),
-}
-
-_copy_file = rule(
- implementation = _copy_file_impl,
- provides = [DefaultInfo],
- attrs = _ATTRS,
-)
-
-_copy_xfile = rule(
- implementation = _copy_file_impl,
- executable = True,
- provides = [DefaultInfo],
- attrs = _ATTRS,
-)
-
-def copy_file(name, src, out, is_executable = False, allow_symlink = False, **kwargs):
- """Copies a file to another location.
-
- `native.genrule()` is sometimes used to copy files (often wishing to rename them). The 'copy_file' rule does this with a simpler interface than genrule.
-
- This rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command on Windows (no Bash is required).
-
- Args:
- name: Name of the rule.
- src: A Label. The file to make a copy of. (Can also be the label of a rule
- that generates a file.)
- out: Path of the output file, relative to this package.
- is_executable: A boolean. Whether to make the output file executable. When
- True, the rule's output can be executed using `bazel run` and can be
- in the srcs of binary and test rules that require executable sources.
- WARNING: If `allow_symlink` is True, `src` must also be executable.
- allow_symlink: A boolean. Whether to allow symlinking instead of copying.
- When False, the output is always a hard copy. When True, the output
- *can* be a symlink, but there is no guarantee that a symlink is
- created (i.e., at the time of writing, we don't create symlinks on
- Windows). Set this to True if you need fast copying and your tools can
- handle symlinks (which most UNIX tools can).
- **kwargs: further keyword arguments, e.g. `visibility`
- """
-
- copy_file_impl = _copy_file
- if is_executable:
- copy_file_impl = _copy_xfile
-
- copy_file_impl(
- name = name,
- src = src,
- out = out,
- is_windows = select({
- "@bazel_tools//src/conditions:host_windows": True,
- "//conditions:default": False,
- }),
- is_executable = is_executable,
- allow_symlink = allow_symlink,
- **kwargs
- )