Skip to content

Commit

Permalink
fix cycle when loading externals
Browse files Browse the repository at this point in the history
Change-Id: Ie2978cc5e832d08fee2f53608e26d31e09a76e79
  • Loading branch information
oliverlee committed Aug 20, 2024
1 parent b4ee359 commit 99c82f7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
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

0 comments on commit 99c82f7

Please sign in to comment.