@@ -242,33 +242,69 @@ def clone_testbed(
242
242
shutil .copytree (source , target , symlinks = True )
243
243
print (" done" )
244
244
245
+ xc_framework_path = target / "Python.xcframework"
246
+ sim_framework_path = xc_framework_path / "ios-arm64_x86_64-simulator"
245
247
if framework is not None :
246
248
if framework .suffix == ".xcframework" :
247
249
print (" Installing XCFramework..." , end = "" , flush = True )
248
- xc_framework_path = (target / "Python.xcframework" ).resolve ()
249
250
if xc_framework_path .is_dir ():
250
251
shutil .rmtree (xc_framework_path )
251
252
else :
252
- xc_framework_path .unlink ()
253
+ xc_framework_path .unlink (missing_ok = True )
253
254
xc_framework_path .symlink_to (
254
255
relative_to (framework , xc_framework_path .parent )
255
256
)
256
257
print (" done" )
257
258
else :
258
259
print (" Installing simulator framework..." , end = "" , flush = True )
259
- sim_framework_path = (
260
- target / "Python.xcframework" / "ios-arm64_x86_64-simulator"
261
- ).resolve ()
262
260
if sim_framework_path .is_dir ():
263
261
shutil .rmtree (sim_framework_path )
264
262
else :
265
- sim_framework_path .unlink ()
263
+ sim_framework_path .unlink (missing_ok = True )
266
264
sim_framework_path .symlink_to (
267
265
relative_to (framework , sim_framework_path .parent )
268
266
)
269
267
print (" done" )
270
268
else :
271
- print (" Using pre-existing iOS framework." )
269
+ if (
270
+ xc_framework_path .is_symlink ()
271
+ and not xc_framework_path .readlink ().is_absolute ()
272
+ ):
273
+ # XCFramework is a relative symlink. Rewrite the symlink relative
274
+ # to the new location.
275
+ print (" Rewriting symlink to XCframework..." , end = "" , flush = True )
276
+ orig_xc_framework_path = (
277
+ source
278
+ / xc_framework_path .readlink ()
279
+ ).resolve ()
280
+ xc_framework_path .unlink ()
281
+ xc_framework_path .symlink_to (
282
+ orig_xc_framework_path .relative_to (
283
+ xc_framework_path .parent , walk_up = True
284
+ )
285
+ )
286
+ print (" done" )
287
+ elif (
288
+ sim_framework_path .is_symlink ()
289
+ and not sim_framework_path .readlink ().is_absolute ()
290
+ ):
291
+ print (" Rewriting symlink to simulator framework..." , end = "" , flush = True )
292
+ # Simulator framework is a relative symlink. Rewrite the symlink
293
+ # relative to the new location.
294
+ orig_sim_framework_path = (
295
+ source
296
+ / "Python.XCframework"
297
+ / sim_framework_path .readlink ()
298
+ ).resolve ()
299
+ sim_framework_path .unlink ()
300
+ sim_framework_path .symlink_to (
301
+ orig_sim_framework_path .relative_to (
302
+ sim_framework_path .parent , walk_up = True
303
+ )
304
+ )
305
+ print (" done" )
306
+ else :
307
+ print (" Using pre-existing iOS framework." )
272
308
273
309
for app_src in apps :
274
310
print (f" Installing app { app_src .name !r} ..." , end = "" , flush = True )
@@ -384,8 +420,8 @@ def main():
384
420
385
421
if context .subcommand == "clone" :
386
422
clone_testbed (
387
- source = Path (__file__ ).parent ,
388
- target = Path (context .location ),
423
+ source = Path (__file__ ).parent . resolve () ,
424
+ target = Path (context .location ). resolve () ,
389
425
framework = Path (context .framework ).resolve () if context .framework else None ,
390
426
apps = [Path (app ) for app in context .apps ],
391
427
)
0 commit comments