Skip to content

Commit

Permalink
fix: detect bzlmod in swift_update_packages.bzl
Browse files Browse the repository at this point in the history
Signed-off-by: Luis Padron <[email protected]>
  • Loading branch information
luispadron committed Oct 30, 2023
1 parent a38b63e commit 6632a8b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions swiftpkg/internal/swift_update_packages.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def swift_update_packages(
_swift_update_repos_args.append("-update_bzlmod_stanzas")
if patches_yaml:
_swift_update_repos_args.extend(["-swift_patches", patches_yaml])
if _is_bzlmod_enabled():
# Need to tell Gazelle to run as if it is in bzlmod mode. It does not figure it out
# properly when we run it from inside this binary.
# Related to https://github.com/bazelbuild/bazel-gazelle/pull/1589.
_swift_update_repos_args.append("-bzlmod")

_gazelle(
name = name,
Expand All @@ -92,3 +97,9 @@ def swift_update_packages(
gazelle = gazelle,
**kwargs
)

def _is_bzlmod_enabled():
"""Determines if currently running under bzlmod."""

# Taken from: https://github.com/aspect-build/bazel-lib/blob/main/lib/private/utils.bzl
return str(Label("@//:BUILD.bazel")).startswith("@@")

0 comments on commit 6632a8b

Please sign in to comment.