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: detect bzlmod in swift_update_packages.bzl #698

Merged
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
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("@@")