@@ -104,6 +104,11 @@ type SimulatorXCTestAgentCacheContext = Omit<
104104 'artifactName' | 'destinationKind' | 'schemaVersion' | 'xctestrunRelativePath'
105105> ;
106106
107+ type ExternalXCTestConfiguration = {
108+ derivedDataPath : string ;
109+ xctestrunFilePath : string ;
110+ } ;
111+
107112export type XCTestAgentController = {
108113 prepare : ( ) => Promise < void > ;
109114 ensureStarted : ( ) => Promise < void > ;
@@ -177,6 +182,23 @@ const assertExternalXCTestRunFileExists = (filePath: string) => {
177182 ) ;
178183} ;
179184
185+ const getExternalXCTestConfiguration = (
186+ fallbackDerivedDataPath : string
187+ ) : ExternalXCTestConfiguration | null => {
188+ const xctestrunFilePath = getExternalXCTestRunFilePath ( ) ;
189+
190+ if ( ! xctestrunFilePath ) {
191+ return null ;
192+ }
193+
194+ assertExternalXCTestRunFileExists ( xctestrunFilePath ) ;
195+
196+ return {
197+ derivedDataPath : getExternalDerivedDataPath ( ) ?? fallbackDerivedDataPath ,
198+ xctestrunFilePath,
199+ } ;
200+ } ;
201+
180202const getXCTestAgentBuildManifestPath = ( derivedDataPath : string ) : string =>
181203 path . join ( derivedDataPath , 'build-manifest.json' ) ;
182204
@@ -908,6 +930,7 @@ export const createXCTestAgentController = (options: {
908930 'xcodebuild.log'
909931 ) ;
910932 let preparedDerivedDataPath = getXCTestAgentDerivedDataPath ( target . kind ) ;
933+ let preparedXCTestRunFilePath : string | null = null ;
911934 let prepared = false ;
912935 let agentProcess : Subprocess | null = null ;
913936 let agentClient : ReturnType < typeof createXCTestAgentClient > | null = null ;
@@ -943,20 +966,20 @@ export const createXCTestAgentController = (options: {
943966 return ;
944967 }
945968
946- const externalXCTestRunFilePath = getExternalXCTestRunFilePath ( ) ;
947- if ( externalXCTestRunFilePath ) {
948- assertExternalXCTestRunFileExists ( externalXCTestRunFilePath ) ;
969+ const externalXCTestConfiguration = getExternalXCTestConfiguration (
970+ preparedDerivedDataPath
971+ ) ;
949972
950- const externalDerivedDataPath = getExternalDerivedDataPath ( ) ;
951- if ( externalDerivedDataPath ) {
952- preparedDerivedDataPath = externalDerivedDataPath ;
953- }
973+ if ( externalXCTestConfiguration ) {
974+ preparedDerivedDataPath = externalXCTestConfiguration . derivedDataPath ;
975+ preparedXCTestRunFilePath =
976+ externalXCTestConfiguration . xctestrunFilePath ;
954977
955978 prepared = true ;
956979 xctestAgentLogger . info (
957980 'Using external XCTest run file for %s target: %s' ,
958981 target . kind ,
959- externalXCTestRunFilePath
982+ preparedXCTestRunFilePath
960983 ) ;
961984 return ;
962985 }
@@ -973,6 +996,7 @@ export const createXCTestAgentController = (options: {
973996 } ) ;
974997
975998 preparedDerivedDataPath = buildResult . derivedDataPath ;
999+ preparedXCTestRunFilePath = null ;
9761000 prepared = true ;
9771001 } ;
9781002
@@ -992,19 +1016,14 @@ export const createXCTestAgentController = (options: {
9921016 target . kind
9931017 ) ;
9941018 xctestAgentLogger . debug ( 'Using XCTest agent port %d' , port ) ;
995- const externalXCTestRunFilePath = getExternalXCTestRunFilePath ( ) ;
996- let xcodebuildRunInputArgs : string [ ] ;
997-
998- if ( externalXCTestRunFilePath ) {
999- xcodebuildRunInputArgs = [ '-xctestrun' , externalXCTestRunFilePath ] ;
1000- } else {
1001- xcodebuildRunInputArgs = [
1002- '-project' ,
1003- getXCTestAgentProjectFilePath ( ) ,
1004- '-scheme' ,
1005- XCTEST_AGENT_SCHEME_NAME ,
1006- ] ;
1007- }
1019+ const xcodebuildRunInputArgs = preparedXCTestRunFilePath
1020+ ? [ '-xctestrun' , preparedXCTestRunFilePath ]
1021+ : [
1022+ '-project' ,
1023+ getXCTestAgentProjectFilePath ( ) ,
1024+ '-scheme' ,
1025+ XCTEST_AGENT_SCHEME_NAME ,
1026+ ] ;
10081027
10091028 const xcodebuildArgs = [
10101029 'test-without-building' ,
0 commit comments