Skip to content

fix: Only build files on OSs that are relevant#75

Merged
cbaker6 merged 3 commits intomainfrom
prepareForServerSide
Jan 18, 2026
Merged

fix: Only build files on OSs that are relevant#75
cbaker6 merged 3 commits intomainfrom
prepareForServerSide

Conversation

@cbaker6
Copy link
Member

@cbaker6 cbaker6 commented Jan 18, 2026

This pull request adds conditional compilation guards to ensure files are only built on platforms where their dependencies are available. The changes wrap platform-specific code with #if canImport() directives and remove unused code from tests.

Changes:

  • Added conditional compilation guards (#if canImport(SwiftUI), #if canImport(Charts), #if canImport(os.log)) to platform-specific files
  • Removed unused expectedGoal variables from LinearCareTaskProgressTests
  • Removed unnecessary Swift version guards in favor of @available attributes

Copilot AI review requested due to automatic review settings January 18, 2026 21:41
@coderabbitai
Copy link

coderabbitai bot commented Jan 18, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added detailText and instructionsText (plus image helper) for richer event display.
  • Refactor

    • SwiftUI- and Charts-dependent UI components and extensions are now conditionally compiled to improve build compatibility across platforms.
  • Tests

    • Simplified progress calculation tests by removing unused expected-goal computations.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Plus Ultra! This PR adds conditional compilation guards (#if canImport(SwiftUI), #if canImport(Charts), #if canImport(os.log)) across many files, gating SwiftUI/Charts/os.log-dependent code. No public signatures or runtime logic were changed; availability is restricted at compile time.

Changes

Cohort / File(s) Summary
SwiftUI Conditional Compilation Wraps
Sources/CareKitEssentials/Cards/Shared/CardViewModel.swift, Sources/CareKitEssentials/Cards/Shared/Chart/CKEConfigurationView.swift, Sources/CareKitEssentials/Cards/Shared/Chart/CareKitEssentialChartBodyView.swift, Sources/CareKitEssentials/Cards/Shared/Chart/CareKitEssentialChartDetailView.swift, Sources/CareKitEssentials/Cards/Shared/Chart/CareKitEssentialChartHeaderView.swift, Sources/CareKitEssentials/Cards/Shared/Chart/CareKitEssentialChartView.swift, Sources/CareKitEssentials/Cards/Shared/CustomLabelView.swift, Sources/CareKitEssentials/Cards/Shared/DetailsView.swift, Sources/CareKitEssentials/Cards/Shared/DismissableView.swift, Sources/CareKitEssentials/Cards/Shared/InformationHeaderView.swift, Sources/CareKitEssentials/Cards/Shared/SimpleLabelView.swift, Sources/CareKitEssentials/Cards/Shared/ResearchSurveyView/ResearchSurveyView.swift, Sources/CareKitEssentials/Cards/Shared/Protocols/CareKitEssentialView.swift, Sources/CareKitEssentials/Cards/Shared/Extensions/InstructionsTaskView.swift, Sources/CareKitEssentials/Cards/Shared/Extensions/SimpleTaskView.swift, Sources/CareKitEssentials/Cards/Shared/SliderLog/SliderLogTaskViewModel.swift, Sources/CareKitEssentials/Environment/CardEnabledEnvironmentKey.swift, Sources/CareKitEssentials/Extensions/CGFloat.swift, Sources/CareKitEssentials/Extensions/Image.swift, Sources/CareKitEssentials/Extensions/View+Default.swift, Sources/CareKitEssentials/Models/ScheduleUtility.swift
Entire file contents wrapped with #if canImport(SwiftUI) ... #endif``; imports moved inside guards where applicable. No API signature changes.
watchOS + SwiftUI Guards
Sources/CareKitEssentials/Cards/Shared/EventViews/EventQueryContentView.swift, Sources/CareKitEssentials/Cards/Shared/EventViews/EventQueryView.swift, Sources/CareKitEssentials/Cards/Shared/SliderLog/CareKitEssentialSliderLogView.swift, Sources/CareKitEssentials/Cards/Shared/SliderLog/Slider.swift, Sources/CareKitEssentials/Cards/Shared/SliderLog/SliderLogButton.swift, Sources/CareKitEssentials/Cards/Shared/SliderLog/SliderLogTaskView.swift, Sources/CareKitEssentials/Cards/Shared/SliderLog/SliderStyle.swift, Sources/CareKitEssentials/Cards/Shared/Extensions/*TaskView+EventViewable.swift, Sources/CareKitEssentials/Cards/Shared/Extensions/LabeledValueTaskView.swift, Sources/CareKitEssentials/Cards/Shared/Extensions/NumericProgressTaskView.swift, Sources/CareKitEssentials/Cards/Shared/Extensions/SimpleTaskView+EventViewable.swift
Replaced #if !os(watchOS) with #if canImport(SwiftUI) && !os(watchOS) or added SwiftUI guard, restricting compilation to SwiftUI-enabled non-watchOS targets.
Chart-related Guards
Sources/CareKitEssentials/Cards/Shared/Chart/Data/CKEDataSeries.swift, Sources/CareKitEssentials/Cards/Shared/Chart/Data/CKEDataSeriesConfiguration.swift, Sources/CareKitEssentials/Cards/Shared/Chart/Protocols/CareKitEssentialChartable.swift, Sources/CareKitEssentials/Cards/Shared/Extensions/CKEDataSeries+AXChartDescriptorRepresentable.swift, Sources/CareKitEssentials/Cards/Shared/Extensions/CareKitEssentialChartBodyView+ChartContent.swift, Sources/CareKitEssentials/Extensions/ChartContent+Default.swift, Sources/CareKitEssentials/Extensions/OCKOutcomeValue+Plottable.swift
Wrapped chart-related code with #if canImport(SwiftUI) and/or #if canImport(Charts) as appropriate; public types unchanged.
watchOS Digital Crown Files
Sources/CareKitEssentials/Cards/watchOS/DigitalCrown/CareKitEssentialDigitalCrownLogView.swift, Sources/CareKitEssentials/Cards/watchOS/DigitalCrown/DigitalCrownView.swift, Sources/CareKitEssentials/Cards/watchOS/DigitalCrown/DigitalCrownViewFooter.swift, Sources/CareKitEssentials/Cards/watchOS/DigitalCrown/DigitalCrownViewHeader.swift, Sources/CareKitEssentials/Cards/watchOS/DigitalCrown/DigitalCrownViewModel.swift
Changed guards from #if os(watchOS) to #if canImport(SwiftUI) && os(watchOS) or wrapped with SwiftUI guard. No API changes.
os.log Guards & Logging Additions
Sources/CareKitEssentials/Extensions/Logger.swift, Sources/CareKitEssentials/Extensions/OCKAnyEventStore.swift, Sources/CareKitEssentials/Extensions/OCKStore.swift
Added #if canImport(os.log) guards. OCKStore received a new populateDefaultCarePlansTasks(startDate: Date) async throws function inside an os.log-guarded extension.
OCKAnyEvent SwiftUI additions
Sources/CareKitEssentials/Extensions/OCKAnyEvent.swift
Removed unconditional detail: String?; added SwiftUI-guarded detail: String?, plus detailText: Text?, instructionsText: Text?, and image() -> Image? — all available only when SwiftUI can be imported.
Model Adjustments
Sources/CareKitEssentials/Models/PeriodComponent.swift
Removed SwiftUI import and simplified mapping so .dayOfYear now maps to .day unconditionally. No public API changes.
Tests
Tests/CareKitEssentialsTests/LinearCareTaskProgressTests.swift
Removed expectedGoal calculations and related assertions; tests simplified.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

PLUS ULTRA! Guards rise like banners bright,
SwiftUI checked to compile just right.
Charts and logs now nod and play,
Builds stay tidy, day by day. ✨💪

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: Only build files on OSs that are relevant' clearly and specifically summarizes the main change: adding conditional compilation to ensure platform-specific code only builds on relevant operating systems.
Description check ✅ Passed The description is well-related to the changeset, explaining the conditional compilation guards added and the removal of unused test code, which matches the file summaries provided.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch prepareForServerSide

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 18, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 5.85%. Comparing base (6d26e5d) to head (731a49b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ces/CareKitEssentials/Extensions/OCKAnyEvent.swift 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main     #75   +/-   ##
=====================================
  Coverage   5.85%   5.85%           
=====================================
  Files         71      71           
  Lines       3640    3640           
=====================================
  Hits         213     213           
  Misses      3427    3427           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
Sources/CareKitEssentials/Cards/watchOS/DigitalCrown/DigitalCrownView.swift (1)

73-76: Fear not! I spotted a small villain hiding in your code, young hero!

This appears to be a pre-existing copy-paste error—isHeaderPadded is used for the footer's padding condition instead of isFooterPadded. When these values differ (e.g., in the initializer at lines 130-131), the footer padding won't behave as intended!

🐛 Proposed fix
                 footer
-                    .if(isHeaderPadded) {
+                    .if(isFooterPadded) {
                         $0.padding([.horizontal, .bottom])
                     }
Sources/CareKitEssentials/Extensions/OCKAnyEventStore.swift (1)

9-83: PLUS ULTRA: The guard must extend to ALL wrappers!

Your concern is spot-on! The core implementation in OCKAnyEventStore.swift is properly guarded by #if canImport(os.log), but the wrappers that call it are not:

  • OCKAnyEvent.swift (lines 23–24): Wrapper is guarded only by #if canImport(SwiftUI), not os.log. On platforms with SwiftUI but without os.log, this wrapper will be compiled and will call a method that doesn't exist—compilation failure.

  • CareStoreFetchedResult.swift (lines 15–23): No guard whatsoever. This extension is unconditionally declared and will unconditionally try to call toggleBooleanOutcome methods that don't exist on platforms without os.logcritical compilation failure.

The wrapper methods in both files must also be guarded by #if canImport(os.log) to prevent symbol availability mismatches.

Sources/CareKitEssentials/Cards/Shared/Chart/Protocols/CareKitEssentialChartable.swift (1)

9-16: Consider adding canImport(Charts) to align with established patterns in the codebase.

While the current #if canImport(SwiftUI) guard works correctly—since your minimum deployment targets (iOS 18.0, macOS 15.0, watchOS 11.0) all exceed Charts' requirements—other files like OCKOutcomeValue+Plottable.swift use #if canImport(Charts) for Charts-specific code. Adding it here would be more explicit and defensive:

Suggested change
-#if canImport(SwiftUI)
+#if canImport(SwiftUI) && canImport(Charts)
Sources/CareKitEssentials/Cards/Shared/Chart/Data/CKEDataSeriesConfiguration.swift (1)

118-140: WAIT, YOUNG HERO! I've spotted a VILLAINOUS BUG lurking in your initializer!

Look closely at line 139 - you're assigning xAxisLabel to self.yAxisLabel instead of self.xAxisLabel! The xAxisLabel property at line 54 is NEVER being assigned in the initializer, which means it will always be nil regardless of what value the caller provides!

🐛 Proposed fix to correctly assign xAxisLabel
         self.legendTitle = legendTitle
+        self.xAxisLabel = xAxisLabel
         self.yAxisLabel = yAxisLabel
         self.showMarkWhenHighlighted = showMarkWhenHighlighted
Sources/CareKitEssentials/Extensions/OCKAnyEvent.swift (1)

160-162: YOUNG HERO, YOUR SENSES DO NOT DECEIVE YOU! The danger is REAL!

The image() method at lines 131-133 returns Image? (a SwiftUI type) but stands UNGUARDED without #if canImport(SwiftUI)! This is a CRITICAL ISSUE that will cause compilation failure on non-SwiftUI platforms like Linux! The file itself shows the proper pattern—other SwiftUI types like Text are correctly guarded. The image() method must follow suit!

🦸 The Plus Ultra fix to guard the image() method
+    `#if` canImport(SwiftUI)
     func image() -> Image? {
         Image.asset(self.task.asset)
     }
+    `#endif`
🤖 Fix all issues with AI agents
In `@Sources/CareKitEssentials/Models/ScheduleUtility.swift`:
- Around line 9-13: The build breaks because OCKAnyEvent.detail calls
ScheduleUtility.scheduleLabel(for:) but ScheduleUtility is only compiled inside
`#if` canImport(SwiftUI); fix by guarding the OCKAnyEvent.detail implementation
with the same `#if` canImport(SwiftUI) conditional (or alternatively remove the
SwiftUI-only gate from Models/ScheduleUtility.swift if ScheduleUtility should be
available on all targets); locate the detail property in
Extensions/OCKAnyEvent.swift and wrap its declaration/usage of
ScheduleUtility.scheduleLabel(for: self) in `#if` canImport(SwiftUI) ... `#endif` so
non-SwiftUI targets no longer reference ScheduleUtility.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds conditional compilation guards to ensure files are only built on platforms where their dependencies are available. The changes wrap platform-specific code with #if canImport() directives and remove unused code from tests.

Changes:

  • Added conditional compilation guards (#if canImport(SwiftUI), #if canImport(Charts), #if canImport(os.log)) to platform-specific files
  • Removed unused expectedGoal variables from LinearCareTaskProgressTests
  • Removed unnecessary Swift version guards in favor of @available attributes

Reviewed changes

Copilot reviewed 55 out of 55 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Tests/CareKitEssentialsTests/LinearCareTaskProgressTests.swift Removed unused expectedGoal variables from three test methods
Sources/CareKitEssentials/Models/ScheduleUtility.swift Added #if canImport(SwiftUI) guard around entire file
Sources/CareKitEssentials/Models/PeriodComponent.swift Removed unused SwiftUI import and Swift version guards
Sources/CareKitEssentials/Extensions/View+Default.swift Added #if canImport(SwiftUI) guard
Sources/CareKitEssentials/Extensions/OCKStore.swift Added conditional #if canImport(os.log) around utility methods
Sources/CareKitEssentials/Extensions/OCKOutcomeValue+Plottable.swift Added #if canImport(Charts) guard
Sources/CareKitEssentials/Extensions/OCKAnyEventStore.swift Added #if canImport(os.log) guard
Sources/CareKitEssentials/Extensions/OCKAnyEvent.swift Added conditional imports and guards for SwiftUI-specific properties
Sources/CareKitEssentials/Extensions/Logger.swift Added #if canImport(os.log) guard
Sources/CareKitEssentials/Extensions/Image.swift Added #if canImport(SwiftUI) guard
Sources/CareKitEssentials/Extensions/ChartContent+Default.swift Added #if canImport(Charts) guard
Sources/CareKitEssentials/Extensions/CGFloat.swift Added #if canImport(SwiftUI) guard
Sources/CareKitEssentials/Environment/CardEnabledEnvironmentKey.swift Added #if canImport(SwiftUI) guard
Sources/CareKitEssentials/Cards/watchOS/DigitalCrown/* Updated guards from #if os(watchOS) to #if canImport(SwiftUI) && os(watchOS)
Sources/CareKitEssentials/Cards/Shared/SliderLog/* Updated guards from #if !os(watchOS) to #if canImport(SwiftUI) && !os(watchOS)
Sources/CareKitEssentials/Cards/Shared/* Added #if canImport(SwiftUI) guards to various view files
Sources/CareKitEssentials/Cards/Shared/Chart/* Added #if canImport(SwiftUI) guards and removed Swift version guards

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Sources/CareKitEssentials/Extensions/OCKAnyEvent.swift (1)

27-42: Keep detail accessible outside the SwiftUI guard—it's a core property with no UI dependency.

The detail property returns a plain String? and has zero SwiftUI dependencies. Moving it behind #if canImport(SwiftUI) gates it away from non-UI targets (CLI/server code), which breaks the API's accessibility. All current usages in the codebase access it from UI components, but the property itself should remain available everywhere.

Relocate detail outside the guard and gate only the detailText and instructionsText properties that actually depend on SwiftUI's Text type. This preserves backward compatibility at full PLUS ULTRA power!

💡 Suggested adjustment
+/// Denotes the time and date of the event.
+var detail: String? {
+    ScheduleUtility.scheduleLabel(for: self)
+}
+
 `#if` canImport(SwiftUI)
-/// Denotes the time and date of the event.
-var detail: String? {
-    ScheduleUtility.scheduleLabel(for: self)
-}
 
 var detailText: Text? {
     guard let detail else { return nil }
     return Text(detail)
 }
🤖 Fix all issues with AI agents
In `@Sources/CareKitEssentials/Extensions/OCKAnyEvent.swift`:
- Around line 11-13: The image() -> Image? function returns a SwiftUI type but
is not conditionally compiled; wrap the entire image() implementation in the
same `#if` canImport(SwiftUI) / `#endif` guard used for detailText and
instructionsText so non-SwiftUI builds don't reference Image, and provide a
non-SwiftUI fallback signature (e.g., return nil or an alternate API) for the
else branch to keep the API surface consistent; update the function named
image() in OCKAnyEvent to be inside that conditional compilation block.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Sources/CareKitEssentials/Extensions/OCKAnyEvent.swift (1)

27-42: Consider moving detail outside the SwiftUI guard, Hero!

The detail property returns String? and relies only on ScheduleUtility.scheduleLabel(for:), which has no SwiftUI dependencies. By placing it inside the #if canImport(SwiftUI) block, you're unnecessarily restricting its availability on non-SwiftUI platforms (like server-side Swift), which appears to be the very use case this PR aims to support! Plus Ultra!

The detailText and instructionsText properties correctly need the guard since they return SwiftUI Text types.

💪 Proposed fix to restore availability on all platforms
+	/// Denotes the time and date of the event.
+	var detail: String? {
+		ScheduleUtility.scheduleLabel(for: self)
+	}
+
 	`#if` canImport(SwiftUI)
-	/// Denotes the time and date of the event.
-	var detail: String? {
-		ScheduleUtility.scheduleLabel(for: self)
-	}
-
     var detailText: Text? {
         guard let detail else { return nil }
         return Text(detail)
     }

     var instructionsText: Text? {
         guard let instructions else { return nil }
         return Text(instructions)
     }
 	`#endif`
♻️ Duplicate comments (1)
Sources/CareKitEssentials/Extensions/OCKAnyEvent.swift (1)

160-164: EXCELLENT WORK, Young Hero! You've addressed the previous review concern! Plus Ultra!

The image() function returns a SwiftUI Image? type and is now properly wrapped with #if canImport(SwiftUI), ensuring non-SwiftUI builds won't break. This is exactly the fix that was needed!

@cbaker6 cbaker6 merged commit 9d8058a into main Jan 18, 2026
8 checks passed
@cbaker6 cbaker6 deleted the prepareForServerSide branch January 18, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant