Commit 4d166bd
authored
Generate XOJIT preview thunks for source files reached through a symlink (#1465)
CONTEXT
When SwiftUI Previews run in XOJIT mode, the previews client asks Swift Build — per source
file — for the compile command that builds that file's "preview thunk", via
generatePreviewInfo(.thunkInfo), identifying the file by path. In
SwiftCompilerSpec.generatePreviewInfo, Swift Build locates that path among the target's
compile inputs and hands it to LibSwiftDriver.frontendCommandLine as the primary input,
which produces the swift-frontend invocation for the thunk.
That lookup compares paths by exact string. If the source file was recorded in the build
description under a different — but equivalent — spelling than the one in the request,
nothing matches: frontendCommandLine returns no command line, generatePreviewInfo returns
an empty result, and the client reports noPreviewInfos, so the preview never renders.
This happens for standalone Swift packages whose sources live under a symlinked directory.
On macOS, temporary directories such as /tmp are symlinks to /private/tmp, and SwiftPM's
new package PIF builder symlink-resolves source paths (to match what the index store
records). The compile command then holds /private/tmp/.../View.swift while the preview
request still carries the unresolved /tmp/.../View.swift — the same file,
a different spelling, no match.
FIX
In the XOJIT branch of SwiftCompilerSpec.generatePreviewInfo, match the requested source
file against the command's inputs by resolved path (ie, FSProxy.realpath), and use the
spelling that actually appears in the command as the primary input. The output-file-map
and the VFS overlay are keyed on that same spelling so they line up with what the driver
resolves. When the requested and recorded paths already agree — e.g. the legacy package
PIF builder, which doesn't resolve symlinks — this is a no-op.
TESTING
Adds previewXOJITThunkInfoResolvesSymlinkedSourcePath to PreviewsBuildOperationTests.
Rather than standing up a real package, it reproduces the spelling mismatch with a single
symlink: it builds a one-file app under a real directory and then requests the preview
thunk through a symlink to that directory, so the requested path and the build's input
path resolve to the same file but differ as strings. It asserts that exactly one preview
info comes back and that the returned compile command references the real (build)
spelling, never the symlinked request path.
Without the fix the test returns zero preview infos (ie, the noPreviewInfos condition);
with it one, as expected.
Fixes rdar://176386125 (and related to rdar://179887248).1 parent b6e1c1c commit 4d166bd
3 files changed
Lines changed: 144 additions & 4 deletions
File tree
- Sources
- SWBCore/SpecImplementations/Tools
- SWBUtil
- Tests/SWBBuildSystemTests
Lines changed: 19 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3226 | 3226 | | |
3227 | 3227 | | |
3228 | 3228 | | |
3229 | | - | |
| 3229 | + | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
3230 | 3243 | | |
3231 | 3244 | | |
3232 | 3245 | | |
3233 | 3246 | | |
3234 | 3247 | | |
3235 | | - | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
3236 | 3252 | | |
3237 | 3253 | | |
3238 | 3254 | | |
3239 | 3255 | | |
3240 | 3256 | | |
3241 | 3257 | | |
3242 | 3258 | | |
3243 | | - | |
| 3259 | + | |
3244 | 3260 | | |
3245 | 3261 | | |
3246 | 3262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
25 | 42 | | |
26 | 43 | | |
27 | 44 | | |
| |||
Lines changed: 107 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1122 | 1122 | | |
1123 | 1123 | | |
1124 | 1124 | | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
1125 | 1232 | | |
1126 | 1233 | | |
1127 | 1234 | | |
| |||
0 commit comments