3030TESTROOT_RELATIVE_PATH = '__TESTROOT__'
3131_SIGNAL_TEST_WITHOUT_BUILDING_SUCCEEDED = '** TEST EXECUTE SUCCEEDED **'
3232_SIGNAL_TEST_WITHOUT_BUILDING_FAILED = '** TEST EXECUTE FAILED **'
33+ _LIB_XCTEST_SWIFT_RELATIVE_PATH = 'Developer/usr/lib/libXCTestSwiftSupport.dylib'
3334
3435
3536class XctestRun (object ):
@@ -393,25 +394,9 @@ def _GenerateTestRootForXcuitest(self):
393394 Then copies app under test, test bundle, xctestrun.plist and uitest
394395 runner app to test root directory.
395396 """
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' )
398399 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-
415400 self ._PrepareUitestInRunerApp (uitest_runner_app )
416401
417402 if self ._on_device :
@@ -458,11 +443,22 @@ def _GenerateTestRootForXcuitest(self):
458443
459444 test_bundle_signing_identity = bundle_util .GetCodesignIdentity (
460445 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 )
466462 bundle_util .CodesignBundle (
467463 uitest_runner_app ,
468464 entitlements_plist_path = entitlements_plist_path ,
@@ -472,12 +468,12 @@ def _GenerateTestRootForXcuitest(self):
472468 bundle_util .CodesignBundle (self ._app_under_test_dir )
473469
474470 platform_name = 'iPhoneOS' if self ._on_device else 'iPhoneSimulator'
471+ developer_path = '__PLATFORMS__/%s.platform/Developer/' % platform_name
475472 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
481477 }
482478 self ._xctestrun_dict = {
483479 'IsUITestBundle' : True ,
@@ -561,82 +557,61 @@ def _GenerateTestRootForXctest(self):
561557 self ._test_bundle_dir = _MoveAndReplaceFile (
562558 self ._test_bundle_dir , app_under_test_plugins_dir )
563559
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-
607560 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 )
608566 app_under_test_signing_identity = bundle_util .GetCodesignIdentity (
609567 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 )
617594 bundle_util .CodesignBundle (self ._test_bundle_dir )
618595 bundle_util .CodesignBundle (self ._app_under_test_dir )
619596
620597 app_under_test_name = os .path .splitext (
621598 os .path .basename (self ._app_under_test_dir ))[0 ]
622599 platform_name = 'iPhoneOS' if self ._on_device else 'iPhoneSimulator'
600+ developer_path = '__PLATFORMS__/%s.platform/Developer/' % platform_name
623601 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 )
627605 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 )
630608 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 ),
636613 '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
640615 }
641616 self ._xctestrun_dict = {
642617 'TestHostPath' : self ._app_under_test_dir ,
@@ -673,3 +648,23 @@ def _MoveAndReplaceFile(src_file, target_parent_dir):
673648 shutil .rmtree (new_file_path )
674649 shutil .move (src_file , new_file_path )
675650 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