Skip to content

Commit 9ee82b8

Browse files
authored
Switch hasattr with our version check (#1152)
If you mix hasattr with version checks you get the wrong behavior on old dev builds, because in the case of fragments when it was supported `ctx.fragments.swift` always existed, you just couldn't access it without declaring the dependency, so on old commit releases they are treated as not having this feature, even when the fragment API is still there.
1 parent 313ab73 commit 9ee82b8

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

swift/internal/swift_toolchain.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _swift_toolchain_impl(ctx):
295295
)
296296

297297
# TODO: Remove once we drop bazel 7.x support
298-
if hasattr(ctx.fragments, "swift"):
298+
if not bazel_features.cc.swift_fragment_removed:
299299
swiftcopts = list(ctx.fragments.swift.copts())
300300
else:
301301
swiftcopts = []

swift/internal/xcode_swift_toolchain.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def _xcode_swift_toolchain_impl(ctx):
562562
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
563563

564564
# TODO: Remove once we drop bazel 7.x support
565-
if hasattr(ctx.fragments, "swift"):
565+
if not bazel_features.cc.swift_fragment_removed:
566566
swiftcopts = list(ctx.fragments.swift.copts())
567567
else:
568568
swiftcopts = []

0 commit comments

Comments
 (0)