This library provides Bazel Starlark functionality meant to help in maintaining other libraries.
The following libraries are implemented:
Implements versioning functions that mostly follow Semver.
Comparators correctly respect major, minor and patch components, as well as Semver compliant 'pre-release' and 'build' components. The pre-release and build components are split at ".". Comparing pre-release parts works for alphabetical prefixes and numeric suffixes, so 'alpha', 'beta' and 'rc' as well as numbered versions of those (e.g. 'alpha1' or 'rc-1') are supported. For pre-release pieces a single '-' in front of the numeric parts is dropped (e.g. 'rc-1' becomes 'rc' + '1' while 'alpha--2' becomes 'alpha-' + '2'). Build components are split only at dots; their prefixes and numeric suffixes are not separated.
The full functionality is exposed as a single struct containing all functions.
The version parameters support:
- a string that can be parsed according to:
major['.'minor[ '.'patch[ '.'digits]*]] ['-' [^+]+] ['+' .*] - a
listortuplewhere each component is a version part. If present, then:- a pre-release component must be separated by a single "-" and split by ".".
- a build component must be separated by a single "+" and split by "."
- a single
intwhich will be the major version. - anything else is an error and the functions will
fail. - unlike Semver, the function allows any number of numeric version components.
Note: Most functions support a skip_build parameter. If True, then any
present build component will be dropped. The parameter defaults to False
for parsing and True for comparisons since Semver dictates that
the build component must be ignored for precedence (see
Semver-10).
The functionality has exhaustive tests. If something still works wrong please, file a bug report or propose a fix.
Example:
load("@mboworks_bzl//bzl/versions:versions.bzl", _versions = "versions")
my_version = "25.33.42"
min_version = (10, 11, 12)
if _versions.lt(my_version, min_version):
fail("My version {my_version} is earlier than {min_version}.".format(
my_version = my_version,
min_version = min_version,
))Provides:
load("@mboworks_bzl//bzl/versions:versions.bzl", _versions = "versions")versionsis a single import structure:parse: Parses a version.ge: ImplementsL >= R.gt: ImplementsL > R.le: ImplementsL <= R.lt: ImplementsL < R.eq: ImplementsL == R.ne: ImplementsL != R.cmp: Returns -1 ifL < R, 0 ifL == R, and 1 ifL > R.compare: ImplementsL OP R.check_one_requirement: Checks a version adheres to a single requirement.check_all_requirements: Checks a version adheres to a requirements list.parse_requirements: Parses a requirements specification.
Implements file path manipulation functions.
NOTE: These functions do not support Windows drive letter relative paths.
Provides:
load("@mboworks_bzl//bzl/paths:paths.bzl", _paths = "paths")pathsis a single import structure:collapse: Collapse '.' and '..' path segments for normalized Unix paths.collapse_windows: Collapse '.' and '..' path segments for normalized Windows paths.ensure_trailing_slash: Ensure a Unix path ends with a single trailing slash.ensure_trailing_slash_windows: Ensure a Windows path ends with a single trailing backslash.is_absolute: ReturnsTrueif a Unix path is absolute.is_absolute_windows: ReturnsTrueif a Windows path is absolute.join: Join path elements and return as normalized Unix paths.join_windows: Join path elements and return as normalized Windows paths.join_respect_absolute: Join path elements (respecting absolute paths) and return as normalized Unix paths.join_respect_absolute_windows: Join path elements (respecting absolute paths) and return as normalized Windows paths.normalize: Normalize a Unix file path.normalize_windows: Normalize a Windows file path.
The library is available as a Bazel module (bzlmod) and supports macOS, Ubuntu and Windows with Bazel versions 7.x, 8.x and 9.x (other systems are not tested). However, future versions may drop Windows support.
See mboworks/bzl releases to replace the version number.
bazel_dep(name = "mboworks_bzl", version = "0.5.1")bazel_skylib.