From bdbd11bd95c5785072d966d02da34638823f0b8f Mon Sep 17 00:00:00 2001 From: thesayyn Date: Mon, 25 Mar 2024 14:31:34 -0700 Subject: [PATCH] use syklib versions --- .github/workflows/ci.yaml | 4 ++-- apko/private/BUILD.bazel | 6 ----- apko/private/apk.bzl | 4 ++-- apko/private/bazelversion.bzl | 45 ----------------------------------- 4 files changed, 4 insertions(+), 55 deletions(-) delete mode 100644 apko/private/bazelversion.bzl diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 763d0d9..3fbcb71 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: CI +name: test # Controls when the action will run. on: @@ -73,7 +73,7 @@ jobs: bzlmodEnabled: [true, false] exclude: # Root module is BZLMOD only, do not test it without bzlmod enabled. - - bzlmodEnable: false + - bzlmodEnabled: false folder: . # Steps represent a sequence of tasks that will be executed as part of the job diff --git a/apko/private/BUILD.bazel b/apko/private/BUILD.bazel index 4f113f9..df424ab 100644 --- a/apko/private/BUILD.bazel +++ b/apko/private/BUILD.bazel @@ -67,9 +67,3 @@ bzl_library( srcs = ["versions.bzl"], visibility = ["//apko:__subpackages__"], ) - -bzl_library( - name = "bazelversion", - srcs = ["bazelversion.bzl"], - visibility = ["//apko:__subpackages__"], -) diff --git a/apko/private/apk.bzl b/apko/private/apk.bzl index 59b040f..a3d927a 100644 --- a/apko/private/apk.bzl +++ b/apko/private/apk.bzl @@ -1,6 +1,6 @@ "Repository rules for importing remote apk packages" -load(":bazelversion.bzl", "bazel_version_gte") +load("@bazel_skylib//lib:versions.bzl", "versions") load(":util.bzl", "util") APK_IMPORT_TMPL = """\ @@ -43,7 +43,7 @@ To resolve this issue and enable partial package fetching, please follow the ste """.format(bytes[0])) def _download(rctx, url, rng, **kwargs): - if bazel_version_gte("7.1.0"): + if versions.is_at_least("7.1.0", native.bazel_version): return rctx.download( url = [url], headers = {"Range": [rng]}, diff --git a/apko/private/bazelversion.bzl b/apko/private/bazelversion.bzl deleted file mode 100644 index bb0fbed..0000000 --- a/apko/private/bazelversion.bzl +++ /dev/null @@ -1,45 +0,0 @@ -"""Internal functions to parse versions.""" - -# Taken from https://github.com/bazel-contrib/bazel_features/blob/main/private/parse.bzl -# We can't use bazel_features because it requires two loads and macro calls in the WORKSPACE -# file but rules_apko users make one load and two macro calls where marcros exported from -# the same file which makes it not possible to add bazel_features to `repositories.bzl` file -# and load from it in the repositories.bzl file. -# -# TODO(2.0): depend on bazel_features directly by splitting the repositories.bzl file into two. -# https://github.com/chainguard-dev/rules_apko/issues/55 - -def _safe_int(s, v): - if not s.isdigit(): - fail("invalid Bazel version '{}': non-numeric segment '{}'".format(v, s)) - return int(s) - -def _partition(s): - for i in range(len(s)): - c = s[i] - if c == "-": - return s[:i], s[i + 1:] - if not c.isdigit() and c != ".": - return s[:i], s[i:] - return s, "" - -def parse_version(v): - """Parses the given Bazel version string into a comparable value. - - Args: - v (str): version string - - Returns: - a triple ([major, minor, patch], is_released, prerelease) - """ - if not v: - # An empty string is treated as a "dev version", which is greater than anything. - v = "999999.999999.999999" - release, prerelease = _partition(v.partition(" ")[0]) - segments = release.split(".") - if len(segments) != 3: - fail("invalid Bazel version '{}': got {} dot-separated segments, want 3".format(v, len(segments))) - return [_safe_int(s, v) for s in segments], not prerelease, prerelease - -def bazel_version_gte(version): - return parse_version(native.bazel_version) >= parse_version(version)