30
30
TESTROOT_RELATIVE_PATH = '__TESTROOT__'
31
31
_SIGNAL_TEST_WITHOUT_BUILDING_SUCCEEDED = '** TEST EXECUTE SUCCEEDED **'
32
32
_SIGNAL_TEST_WITHOUT_BUILDING_FAILED = '** TEST EXECUTE FAILED **'
33
+ _LIB_XCTEST_SWIFT_RELATIVE_PATH = 'Developer/usr/lib/libXCTestSwiftSupport.dylib'
33
34
34
35
35
36
class XctestRun (object ):
@@ -393,25 +394,9 @@ def _GenerateTestRootForXcuitest(self):
393
394
Then copies app under test, test bundle, xctestrun.plist and uitest
394
395
runner app to test root directory.
395
396
"""
396
- platform_library_path = os . path . join (
397
- xcode_info_util . GetSdkPlatformPath ( self . _sdk ) , 'Developer/Library' )
397
+ platform_path = xcode_info_util . GetSdkPlatformPath ( self . _sdk )
398
+ platform_library_path = os . path . join ( platform_path , 'Developer/Library' )
398
399
uitest_runner_app = self ._GetUitestRunnerAppFromXcode (platform_library_path )
399
-
400
- runner_app_frameworks_dir = os .path .join (uitest_runner_app , 'Frameworks' )
401
- os .mkdir (runner_app_frameworks_dir )
402
- xctest_framework = os .path .join (runner_app_frameworks_dir ,
403
- 'XCTest.framework' )
404
- shutil .copytree (
405
- os .path .join (platform_library_path , 'Frameworks/XCTest.framework' ),
406
- xctest_framework )
407
- if xcode_info_util .GetXcodeVersionNumber () >= 900 :
408
- xct_automation_framework = os .path .join (runner_app_frameworks_dir ,
409
- 'XCTAutomationSupport.framework' )
410
- shutil .copytree (
411
- os .path .join (platform_library_path ,
412
- 'PrivateFrameworks/XCTAutomationSupport.framework' ),
413
- xct_automation_framework )
414
-
415
400
self ._PrepareUitestInRunerApp (uitest_runner_app )
416
401
417
402
if self ._on_device :
@@ -458,11 +443,22 @@ def _GenerateTestRootForXcuitest(self):
458
443
459
444
test_bundle_signing_identity = bundle_util .GetCodesignIdentity (
460
445
self ._test_bundle_dir )
461
- bundle_util .CodesignBundle (
462
- xctest_framework , identity = test_bundle_signing_identity )
463
- if xcode_info_util .GetXcodeVersionNumber () >= 900 :
464
- bundle_util .CodesignBundle (
465
- xct_automation_framework , identity = test_bundle_signing_identity )
446
+
447
+ runner_app_frameworks_dir = os .path .join (uitest_runner_app , 'Frameworks' )
448
+ os .mkdir (runner_app_frameworks_dir )
449
+ _CopyAndSignFramework (
450
+ os .path .join (platform_library_path , 'Frameworks/XCTest.framework' ),
451
+ runner_app_frameworks_dir , test_bundle_signing_identity )
452
+ xcode_version_num = xcode_info_util .GetXcodeVersionNumber ()
453
+ if xcode_version_num >= 900 :
454
+ _CopyAndSignFramework (
455
+ os .path .join (platform_library_path ,
456
+ 'PrivateFrameworks/XCTAutomationSupport.framework' ),
457
+ runner_app_frameworks_dir , test_bundle_signing_identity )
458
+ if xcode_version_num >= 1100 :
459
+ _CopyAndSignLibFile (
460
+ os .path .join (platform_path , _LIB_XCTEST_SWIFT_RELATIVE_PATH ),
461
+ runner_app_frameworks_dir , test_bundle_signing_identity )
466
462
bundle_util .CodesignBundle (
467
463
uitest_runner_app ,
468
464
entitlements_plist_path = entitlements_plist_path ,
@@ -472,12 +468,12 @@ def _GenerateTestRootForXcuitest(self):
472
468
bundle_util .CodesignBundle (self ._app_under_test_dir )
473
469
474
470
platform_name = 'iPhoneOS' if self ._on_device else 'iPhoneSimulator'
471
+ developer_path = '__PLATFORMS__/%s.platform/Developer/' % platform_name
475
472
test_envs = {
476
- 'DYLD_FRAMEWORK_PATH' :
477
- '__TESTROOT__:__PLATFORMS__/%s.platform/Developer/'
478
- 'Library/Frameworks' % platform_name ,
479
- 'DYLD_LIBRARY_PATH' : '__TESTROOT__:__PLATFORMS__/%s.platform/Developer/'
480
- 'Library/Frameworks' % platform_name
473
+ 'DYLD_FRAMEWORK_PATH' : '__TESTROOT__:{developer}/Library/Frameworks:'
474
+ '{developer}/Library/PrivateFrameworks' .format (
475
+ developer = developer_path ),
476
+ 'DYLD_LIBRARY_PATH' : '__TESTROOT__:%s/usr/lib' % developer_path
481
477
}
482
478
self ._xctestrun_dict = {
483
479
'IsUITestBundle' : True ,
@@ -561,82 +557,61 @@ def _GenerateTestRootForXctest(self):
561
557
self ._test_bundle_dir = _MoveAndReplaceFile (
562
558
self ._test_bundle_dir , app_under_test_plugins_dir )
563
559
564
- platform_path = xcode_info_util .GetSdkPlatformPath (self ._sdk )
565
- app_under_test_frameworks_dir = os .path .join (self ._app_under_test_dir ,
566
- 'Frameworks' )
567
- if not os .path .exists (app_under_test_frameworks_dir ):
568
- os .mkdir (app_under_test_frameworks_dir )
569
- xctest_framework = os .path .join (app_under_test_frameworks_dir ,
570
- 'XCTest.framework' )
571
- if os .path .exists (xctest_framework ):
572
- shutil .rmtree (xctest_framework )
573
- shutil .copytree (
574
- os .path .join (platform_path ,
575
- 'Developer/Library/Frameworks/XCTest.framework' ),
576
- xctest_framework )
577
- if xcode_info_util .GetXcodeVersionNumber () < 1000 :
578
- bundle_injection_lib = os .path .join (app_under_test_frameworks_dir ,
579
- 'IDEBundleInjection.framework' )
580
- if os .path .exists (bundle_injection_lib ):
581
- shutil .rmtree (bundle_injection_lib )
582
- shutil .copytree (
583
- os .path .join (
584
- platform_path , 'Developer/Library/PrivateFrameworks/'
585
- 'IDEBundleInjection.framework' ),
586
- bundle_injection_lib )
587
- else :
588
- bundle_injection_lib = os .path .join (app_under_test_frameworks_dir ,
589
- 'libXCTestBundleInject.dylib' )
590
- if os .path .exists (bundle_injection_lib ):
591
- os .remove (bundle_injection_lib )
592
- shutil .copyfile (
593
- os .path .join (platform_path ,
594
- 'Developer/usr/lib/libXCTestBundleInject.dylib' ),
595
- bundle_injection_lib )
596
- xct_automation_framework = None
597
- if xcode_info_util .GetXcodeVersionNumber () >= 1100 :
598
- xct_automation_framework = os .path .join (app_under_test_frameworks_dir ,
599
- 'XCTAutomationSupport.framework' )
600
- if os .path .exists (xct_automation_framework ):
601
- os .remove (xct_automation_framework )
602
- shutil .copytree (
603
- os .path .join (
604
- platform_path , 'Developer/Library/PrivateFrameworks/'
605
- 'XCTAutomationSupport.framework' ), xct_automation_framework )
606
-
607
560
if self ._on_device :
561
+ platform_path = xcode_info_util .GetSdkPlatformPath (self ._sdk )
562
+ app_under_test_frameworks_dir = os .path .join (self ._app_under_test_dir ,
563
+ 'Frameworks' )
564
+ if not os .path .exists (app_under_test_frameworks_dir ):
565
+ os .mkdir (app_under_test_frameworks_dir )
608
566
app_under_test_signing_identity = bundle_util .GetCodesignIdentity (
609
567
self ._app_under_test_dir )
610
- bundle_util .CodesignBundle (
611
- xctest_framework , identity = app_under_test_signing_identity )
612
- bundle_util .CodesignBundle (
613
- bundle_injection_lib , identity = app_under_test_signing_identity )
614
- if xct_automation_framework :
615
- bundle_util .CodesignBundle (
616
- xct_automation_framework , identity = app_under_test_signing_identity )
568
+ _CopyAndSignFramework (
569
+ os .path .join (platform_path ,
570
+ 'Developer/Library/Frameworks/XCTest.framework' ),
571
+ app_under_test_frameworks_dir , app_under_test_signing_identity )
572
+ xcode_version_num = xcode_info_util .GetXcodeVersionNumber ()
573
+ if xcode_version_num < 1000 :
574
+ bundle_injection_lib = os .path .join (
575
+ platform_path , 'Developer/Library/PrivateFrameworks/'
576
+ 'IDEBundleInjection.framework' )
577
+ _CopyAndSignFramework (bundle_injection_lib ,
578
+ app_under_test_frameworks_dir ,
579
+ app_under_test_signing_identity )
580
+ else :
581
+ bundle_injection_lib = os .path .join (
582
+ platform_path , 'Developer/usr/lib/libXCTestBundleInject.dylib' )
583
+ _CopyAndSignLibFile (bundle_injection_lib , app_under_test_frameworks_dir ,
584
+ app_under_test_signing_identity )
585
+ if xcode_version_num >= 1100 :
586
+ _CopyAndSignFramework (
587
+ os .path .join (
588
+ platform_path , 'Developer/Library/PrivateFrameworks/'
589
+ 'XCTAutomationSupport.framework' ),
590
+ app_under_test_frameworks_dir , app_under_test_signing_identity )
591
+ _CopyAndSignLibFile (
592
+ os .path .join (platform_path , _LIB_XCTEST_SWIFT_RELATIVE_PATH ),
593
+ app_under_test_frameworks_dir , app_under_test_signing_identity )
617
594
bundle_util .CodesignBundle (self ._test_bundle_dir )
618
595
bundle_util .CodesignBundle (self ._app_under_test_dir )
619
596
620
597
app_under_test_name = os .path .splitext (
621
598
os .path .basename (self ._app_under_test_dir ))[0 ]
622
599
platform_name = 'iPhoneOS' if self ._on_device else 'iPhoneSimulator'
600
+ developer_path = '__PLATFORMS__/%s.platform/Developer/' % platform_name
623
601
if xcode_info_util .GetXcodeVersionNumber () < 1000 :
624
- dyld_insert_libs = ('__PLATFORMS__/%s.platform/Developer/ Library/'
625
- 'PrivateFrameworks/ IDEBundleInjection.framework/'
626
- 'IDEBundleInjection' % platform_name )
602
+ dyld_insert_libs = ('%s/ Library/PrivateFrameworks /'
603
+ 'IDEBundleInjection.framework/IDEBundleInjection' %
604
+ developer_path )
627
605
else :
628
- dyld_insert_libs = ('__PLATFORMS__/%s.platform/Developer/ usr/lib/'
629
- 'libXCTestBundleInject.dylib' % platform_name )
606
+ dyld_insert_libs = ('%s/ usr/lib/libXCTestBundleInject.dylib' %
607
+ developer_path )
630
608
test_envs = {
631
- 'XCInjectBundleInto' :
632
- os .path .join ('__TESTHOST__' , app_under_test_name ),
633
- 'DYLD_FRAMEWORK_PATH' :
634
- '__TESTROOT__:__PLATFORMS__/%s.platform/Developer/'
635
- 'Library/Frameworks' % platform_name ,
609
+ 'XCInjectBundleInto' : os .path .join ('__TESTHOST__' , app_under_test_name ),
610
+ 'DYLD_FRAMEWORK_PATH' : '__TESTROOT__:{developer}/Library/Frameworks:'
611
+ '{developer}/Library/PrivateFrameworks' .format (
612
+ developer = developer_path ),
636
613
'DYLD_INSERT_LIBRARIES' : dyld_insert_libs ,
637
- 'DYLD_LIBRARY_PATH' :
638
- '__TESTROOT__:__PLATFORMS__/%s.platform/Developer/Library/'
639
- 'Frameworks' % platform_name ,
614
+ 'DYLD_LIBRARY_PATH' : '__TESTROOT__:%s/usr/lib:' % developer_path
640
615
}
641
616
self ._xctestrun_dict = {
642
617
'TestHostPath' : self ._app_under_test_dir ,
@@ -673,3 +648,23 @@ def _MoveAndReplaceFile(src_file, target_parent_dir):
673
648
shutil .rmtree (new_file_path )
674
649
shutil .move (src_file , new_file_path )
675
650
return new_file_path
651
+
652
+
653
+ def _CopyAndSignFramework (src_framework , target_parent_dir , signing_identity ):
654
+ """Copies the framework to the directory and signs the file with identity."""
655
+ file_name = os .path .basename (src_framework )
656
+ target_path = os .path .join (target_parent_dir , file_name )
657
+ if os .path .exists (target_path ):
658
+ shutil .rmtree (target_path )
659
+ shutil .copytree (src_framework , target_path )
660
+ bundle_util .CodesignBundle (target_path , identity = signing_identity )
661
+
662
+
663
+ def _CopyAndSignLibFile (src_lib , target_parent_dir , signing_identity ):
664
+ """Copies the library to the directory and signs the file with identity."""
665
+ file_name = os .path .basename (src_lib )
666
+ target_path = os .path .join (target_parent_dir , file_name )
667
+ if os .path .exists (target_path ):
668
+ os .remove (target_path )
669
+ shutil .copy (src_lib , target_path )
670
+ bundle_util .CodesignBundle (target_path , identity = signing_identity )
0 commit comments