Skip to content

Commit c63e47d

Browse files
fix(samples): align switch-v10 with SDK_V10
SDK_V10=1 exports the source-built SwiftPM product as Sentry instead of SentrySPM, so sample projects still linking SentrySPM fail to resolve. Split XcodeGen helpers into reusable scripts that set traits, swap product names, and set compiler flags. switch-v10 now rewrites SentrySPM to Sentry and opens the workspace with SDK_V10=1 xed.
1 parent 70fc7c8 commit c63e47d

7 files changed

Lines changed: 379 additions & 194 deletions

File tree

.github/file-filters.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ run_v10_for_prs: &run_v10_for_prs
396396
- "scripts/ci-utils.sh"
397397
- "scripts/sentry-xcodebuild.sh"
398398
- "scripts/verify-v10-sentrycrash-*.sh"
399+
- "scripts/generate-sample-v10.sh"
400+
- "scripts/set-xcodegen-package-traits.sh"
401+
- "scripts/set-xcodegen-compiler-flags.sh"
402+
- "scripts/swap-xcodegen-product-name.sh"
399403

400404
# Project files
401405
- "Sentry.xcodeproj/**"

Makefile

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ V10_SDK_FLAGS = GCC_PREPROCESSOR_DEFINITIONS='$$(inherited) SDK_V10=1' SWIFT_ACT
737737
## Build the iOS-Swift sample app with the V10 trait
738738
.PHONY: build-sample-v10-iOS-Swift
739739
build-sample-v10-iOS-Swift:
740-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/iOS-Swift/iOS-Swift.yml
740+
scripts/generate-sample-v10.sh --spec Samples/iOS-Swift/iOS-Swift.yml
741741
set -o pipefail && xcodebuild \
742742
-workspace Sentry.xcworkspace \
743743
-scheme iOS-Swift \
@@ -749,7 +749,7 @@ build-sample-v10-iOS-Swift:
749749
## Build the iOS-SwiftUI sample app with the V10 trait
750750
.PHONY: build-sample-v10-iOS-SwiftUI
751751
build-sample-v10-iOS-SwiftUI:
752-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/iOS-SwiftUI/iOS-SwiftUI.yml
752+
scripts/generate-sample-v10.sh --spec Samples/iOS-SwiftUI/iOS-SwiftUI.yml
753753
set -o pipefail && xcodebuild \
754754
-workspace Sentry.xcworkspace \
755755
-scheme iOS-SwiftUI \
@@ -761,7 +761,7 @@ build-sample-v10-iOS-SwiftUI:
761761
## Build the iOS-ObjectiveC sample app with the V10 trait
762762
.PHONY: build-sample-v10-iOS-ObjectiveC
763763
build-sample-v10-iOS-ObjectiveC:
764-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/iOS-ObjectiveC/iOS-ObjectiveC.yml
764+
scripts/generate-sample-v10.sh --spec Samples/iOS-ObjectiveC/iOS-ObjectiveC.yml
765765
set -o pipefail && xcodebuild \
766766
-workspace Sentry.xcworkspace \
767767
-scheme iOS-ObjectiveC \
@@ -773,7 +773,7 @@ build-sample-v10-iOS-ObjectiveC:
773773
## Build the iOS-ObjectiveCpp-NoModules sample app with the V10 trait
774774
.PHONY: build-sample-v10-iOS-ObjectiveCpp-NoModules
775775
build-sample-v10-iOS-ObjectiveCpp-NoModules:
776-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/iOS-ObjectiveCpp-NoModules/iOS-ObjectiveCpp-NoModules.yml
776+
scripts/generate-sample-v10.sh --spec Samples/iOS-ObjectiveCpp-NoModules/iOS-ObjectiveCpp-NoModules.yml
777777
set -o pipefail && xcodebuild \
778778
-workspace Sentry.xcworkspace \
779779
-scheme iOS-ObjectiveCpp-NoModules \
@@ -786,7 +786,7 @@ build-sample-v10-iOS-ObjectiveCpp-NoModules:
786786
## Build the SPM sample app with the V10 trait
787787
.PHONY: build-sample-v10-SPM
788788
build-sample-v10-SPM:
789-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/SPM/SPM.yml
789+
scripts/generate-sample-v10.sh --spec Samples/SPM/SPM.yml
790790
set -o pipefail && xcodebuild \
791791
-workspace Sentry.xcworkspace \
792792
-scheme SPM \
@@ -797,7 +797,7 @@ build-sample-v10-SPM:
797797
## Build the DistributionSample app with the V10 trait
798798
.PHONY: build-sample-v10-DistributionSample
799799
build-sample-v10-DistributionSample:
800-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/DistributionSample/DistributionSample.yml
800+
scripts/generate-sample-v10.sh --spec Samples/DistributionSample/DistributionSample.yml
801801
set -o pipefail && xcodebuild \
802802
-workspace Sentry.xcworkspace \
803803
-scheme DistributionSample \
@@ -808,7 +808,7 @@ build-sample-v10-DistributionSample:
808808
## Build the macOS-Swift sample app with the V10 trait
809809
.PHONY: build-sample-v10-macOS-Swift
810810
build-sample-v10-macOS-Swift:
811-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/macOS-Swift/macOS-Swift.yml
811+
scripts/generate-sample-v10.sh --spec Samples/macOS-Swift/macOS-Swift.yml
812812
set -o pipefail && xcodebuild \
813813
-workspace Sentry.xcworkspace \
814814
-scheme macOS-Swift \
@@ -819,7 +819,7 @@ build-sample-v10-macOS-Swift:
819819
## Build the macOS-SwiftUI sample app with the V10 trait
820820
.PHONY: build-sample-v10-macOS-SwiftUI
821821
build-sample-v10-macOS-SwiftUI:
822-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/macOS-SwiftUI/macOS-SwiftUI.yml
822+
scripts/generate-sample-v10.sh --spec Samples/macOS-SwiftUI/macOS-SwiftUI.yml
823823
set -o pipefail && xcodebuild \
824824
-workspace Sentry.xcworkspace \
825825
-scheme macOS-SwiftUI \
@@ -830,7 +830,7 @@ build-sample-v10-macOS-SwiftUI:
830830
## Build the tvOS-Swift sample app with the V10 trait
831831
.PHONY: build-sample-v10-tvOS-Swift
832832
build-sample-v10-tvOS-Swift:
833-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/tvOS-Swift/tvOS-Swift.yml
833+
scripts/generate-sample-v10.sh --spec Samples/tvOS-Swift/tvOS-Swift.yml
834834
set -o pipefail && xcodebuild \
835835
-workspace Sentry.xcworkspace \
836836
-scheme tvOS-Swift \
@@ -842,7 +842,7 @@ build-sample-v10-tvOS-Swift:
842842
## Build the visionOS-Swift sample app with the V10 trait
843843
.PHONY: build-sample-v10-visionOS-Swift
844844
build-sample-v10-visionOS-Swift:
845-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/visionOS-Swift/visionOS-Swift.yml
845+
scripts/generate-sample-v10.sh --spec Samples/visionOS-Swift/visionOS-Swift.yml
846846
set -o pipefail && xcodebuild \
847847
-workspace Sentry.xcworkspace \
848848
-scheme visionOS-Swift \
@@ -854,7 +854,7 @@ build-sample-v10-visionOS-Swift:
854854
## Build the watchOS-Swift sample app with the V10 trait
855855
.PHONY: build-sample-v10-watchOS-Swift
856856
build-sample-v10-watchOS-Swift:
857-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate --spec Samples/watchOS-Swift/watchOS-Swift.yml
857+
scripts/generate-sample-v10.sh --spec Samples/watchOS-Swift/watchOS-Swift.yml
858858
set -o pipefail && xcodebuild \
859859
-workspace Sentry.xcworkspace \
860860
-scheme 'watchOS-Swift WatchKit App' \
@@ -1831,12 +1831,15 @@ xcode: xcode-ci
18311831

18321832
## Switch sample Xcode projects to SDK V10 mode
18331833
#
1834-
# Copies each sample XcodeGen YAML, adds the V10 package trait and app-target
1835-
# SDK_V10 compiler flags with yq, and regenerates the Xcode project from that
1836-
# copy. Committed YAML is left unchanged. Skips binary and NoUIFramework samples.
1834+
# Copies each sample XcodeGen YAML, sets the V10 package trait and app-target
1835+
# SDK_V10 compiler flags, rewrites SentrySPM product refs to Sentry, and
1836+
# regenerates the Xcode project from that copy. Committed YAML is left
1837+
# unchanged. Skips binary and NoUIFramework samples. Opens the workspace with
1838+
# SDK_V10=1 so SwiftPM exports the source-built product as Sentry.
18371839
.PHONY: switch-v10
18381840
switch-v10:
1839-
scripts/set-xcodegen-package-traits.sh --trait V10 --generate
1841+
scripts/generate-sample-v10.sh --product SentrySPM --with Sentry
1842+
SDK_V10=1 xed Sentry.xcworkspace
18401843

18411844
## Switch sample Xcode projects back to default (non-V10) mode
18421845
#

Samples/SentrySampleShared/Package.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
// swift-tools-version: 6.1
22

3+
import Foundation
34
import PackageDescription
45

6+
func envFlag(_ name: String) -> Bool {
7+
getenv(name).map { String(cString: $0) == "1" } ?? false
8+
}
9+
10+
let enableV10 = envFlag("SDK_V10")
11+
12+
// When SDK_V10 is set in the environment, Sentry exports the compile-from-source product
13+
// as "Sentry" rather than "SentrySPM". Mirror that selection here.
14+
let sentryProductName = enableV10 ? "Sentry" : "SentrySPM"
15+
516
let package = Package(
617
name: "SentrySampleShared",
718
platforms: [.iOS(.v15), .macOS(.v12), .tvOS(.v15), .watchOS(.v9), .visionOS(.v1)],
@@ -33,7 +44,7 @@ let package = Package(
3344
.target(
3445
name: "SentrySampleShared",
3546
dependencies: [
36-
.product(name: "SentrySPM", package: "Sentry"),
47+
.product(name: sentryProductName, package: "Sentry"),
3748
.product(name: "SentryObjC", package: "Sentry")
3849
],
3950
path: "Sources/SentrySampleShared",

scripts/generate-sample-v10.sh

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Disable SC1091 because it won't work with pre-commit
5+
# shellcheck source=./scripts/ci-utils.sh disable=SC1091
6+
source "$(cd "$(dirname "$0")" && pwd)/ci-utils.sh"
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
10+
SAMPLES_DIR="$REPO_ROOT/Samples"
11+
12+
SPECS=()
13+
PRODUCT=""
14+
WITH=""
15+
16+
# Binary XCFramework samples cannot enable V10. macOS-CLI-Xcode uses the
17+
# NoUIFramework trait and must not pick up V10 from a bulk generate.
18+
SKIP_SPECS=(
19+
"macOS-CLI-Xcode.yml"
20+
"iOS-ObjectiveC-Dynamic.yml"
21+
"iOS-ObjectiveC-Static.yml"
22+
)
23+
24+
usage() {
25+
log_notice "Usage: $(basename "$0")"
26+
log_notice " -s, --spec <path> XcodeGen YAML spec (repeatable; all eligible"
27+
log_notice " Samples/ specs when omitted)"
28+
log_notice " -p, --product <name> Product name to replace in the generate copy"
29+
log_notice " -w, --with <name> Replacement product name (required with --product)"
30+
exit 1
31+
}
32+
33+
while [[ $# -gt 0 ]]; do
34+
case $1 in
35+
-s|--spec) SPECS+=("$2"); shift 2 ;;
36+
-p|--product) PRODUCT="$2"; shift 2 ;;
37+
-w|--with) WITH="$2"; shift 2 ;;
38+
*) usage ;;
39+
esac
40+
done
41+
42+
if [[ -n "$PRODUCT" && -z "$WITH" ]]; then
43+
log_error "--with is required when --product is set"
44+
usage
45+
fi
46+
47+
if [[ -z "$PRODUCT" && -n "$WITH" ]]; then
48+
log_error "--product is required when --with is set"
49+
usage
50+
fi
51+
52+
if ! command -v yq >/dev/null 2>&1; then
53+
log_error "yq is required (brew install yq)"
54+
exit 1
55+
fi
56+
57+
if ! command -v xcodegen >/dev/null 2>&1; then
58+
log_error "xcodegen is required"
59+
exit 1
60+
fi
61+
62+
should_skip() {
63+
local basename
64+
basename="$(basename "$1")"
65+
local skip
66+
for skip in "${SKIP_SPECS[@]}"; do
67+
if [[ "$basename" == "$skip" ]]; then
68+
return 0
69+
fi
70+
done
71+
return 1
72+
}
73+
74+
has_local_packages() {
75+
yq -e '.packages | to_entries | map(select(.value | has("path"))) | length > 0' "$1" >/dev/null 2>&1
76+
}
77+
78+
resolve_spec() {
79+
local spec="$1"
80+
if [[ -f "$spec" ]]; then
81+
echo "$spec"
82+
return 0
83+
fi
84+
if [[ -f "$REPO_ROOT/$spec" ]]; then
85+
echo "$REPO_ROOT/$spec"
86+
return 0
87+
fi
88+
log_error "Spec not found: $spec"
89+
return 1
90+
}
91+
92+
collect_specs() {
93+
local spec
94+
while IFS= read -r -d '' spec; do
95+
if should_skip "$spec"; then
96+
continue
97+
fi
98+
if ! has_local_packages "$spec"; then
99+
continue
100+
fi
101+
printf '%s\0' "$spec"
102+
done < <(find "$SAMPLES_DIR" -name '*.yml' ! -path '*/Shared/*' -print0)
103+
}
104+
105+
gather_specs() {
106+
local resolved=()
107+
local spec
108+
if [[ ${#SPECS[@]} -gt 0 ]]; then
109+
for spec in "${SPECS[@]}"; do
110+
resolved+=("$(resolve_spec "$spec")")
111+
done
112+
SPECS=("${resolved[@]}")
113+
return 0
114+
fi
115+
SPECS=()
116+
while IFS= read -r -d '' spec; do
117+
SPECS+=("$spec")
118+
done < <(collect_specs)
119+
}
120+
121+
patch_and_generate() {
122+
local spec="$1"
123+
local dir base tmp
124+
dir="$(dirname "$spec")"
125+
base="$(basename "$spec" .yml)"
126+
tmp="$dir/${base}.v10.yml"
127+
128+
(
129+
trap 'rm -f "$tmp"' EXIT
130+
cp "$spec" "$tmp"
131+
"$SCRIPT_DIR/set-xcodegen-package-traits.sh" --spec "$tmp" --trait V10
132+
"$SCRIPT_DIR/set-xcodegen-compiler-flags.sh" \
133+
--spec "$tmp" \
134+
--swift-condition SDK_V10 \
135+
--c-define SDK_V10=1
136+
if [[ -n "$PRODUCT" ]]; then
137+
"$SCRIPT_DIR/swap-xcodegen-product-name.sh" \
138+
--spec "$tmp" \
139+
--product "$PRODUCT" \
140+
--with "$WITH"
141+
fi
142+
begin_group "generate V10: $spec"
143+
xcodegen --spec "$tmp"
144+
log_info " Generated"
145+
end_group
146+
)
147+
}
148+
149+
gather_specs
150+
151+
if [[ ${#SPECS[@]} -eq 0 ]]; then
152+
log_warning "No XcodeGen specs with local packages found under Samples/"
153+
exit 0
154+
fi
155+
156+
for spec in "${SPECS[@]}"; do
157+
patch_and_generate "$spec"
158+
done
159+
160+
log_info "Done: generated ${#SPECS[@]} V10 project(s)"
161+
if [[ -n "$PRODUCT" ]]; then
162+
log_notice "Product refs rewritten from '$PRODUCT' to '$WITH'. Open Xcode with SDK_V10=1."
163+
fi

0 commit comments

Comments
 (0)