Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cycle when loading externals #6

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ local_repository(
name = "rules_clang_tidy",
path = "..",
)

load("@rules_clang_tidy//:dependencies.bzl", "rules_clang_tidy_dependencies")

rules_clang_tidy_dependencies()
47 changes: 45 additions & 2 deletions private/local_workspace_status.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,50 @@
Determines the workspace status used as an input to `apply_fixes` rules.
"""

load("@bazel_skylib//lib:versions.bzl", "versions")
# we can't load @bazel_skylib yet since this bzl file is loaded in
# dependencies.bzl (which is responsible for loading @bazel_skylib)

# https://github.com/bazelbuild/bazel-skylib/blob/652c8f0b2817daaa2570b7a3b2147643210f7dc7/lib/versions.bzl

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 (<, >).

For a development build of Bazel, this returns an unspecified version tuple
that compares higher than any released version.

Args:
bazel_version: the Bazel version string

Returns:
An int 3-tuple of a (major, minor, patch) version.
"""

version = _extract_version_number(bazel_version)
if not version:
return (999999, 999999, 999999)
return tuple([int(n) for n in version.split(".")])

def _setup_status_file(rctx):
"""
Expand Down Expand Up @@ -83,7 +126,7 @@ BUILD_WORKSPACE_DIRECTORY = "{workspace_root}"
executable = False,
)

if versions.is_at_least("7.1.0", native.bazel_version):
if _parse_bazel_version(native.bazel_version) >= _parse_bazel_version("7.1.0"):
_setup_status_file(rctx)
else:
rctx.file(
Expand Down