@@ -229,23 +229,33 @@ async function patchGameAssemblyRunScriptOutput(projectDirectory: string): Promi
229229 return ;
230230 }
231231 let pbxprojContent = await fs . promises . readFile ( pbxprojPath , 'utf8' ) ;
232- // Regex to find the Run Script phase for GameAssembly and patch outputPaths
233- const runScriptRegex = / ( \/ \* R u n S c r i p t \/ \* \n [ \s \S ] * ?s h e l l S c r i p t = " ) ( .* G a m e A s s e m b l y [ \s \S ] * ?) ( " ; [ \s \S ] * ?o u t p u t P a t h s = ) ( \( [ \s \S ] * ?\) ; ) / g;
234232 const desiredOutput = '"${DERIVED_FILE_DIR}/il2cpp_outputs",' ;
235233 let modified = false ;
236- pbxprojContent = pbxprojContent . replace ( runScriptRegex , ( match , p1 , p2 , p3 , p4 ) => {
237- // Only patch if not already set
238- if ( p4 . includes ( '${DERIVED_FILE_DIR}/il2cpp_outputs' ) ) {
239- return match ;
234+ // Find all Run Script build phases
235+ pbxprojContent = pbxprojContent . replace ( / ( \/ \* R u n S c r i p t \/ \* [ \s \S ] * ?s h e l l S c r i p t = " ) ( .* G a m e A s s e m b l y [ \s \S ] * ?) ( " ; [ \s \S ] * ?) (? = \/ \* | \n \s * \w + = | $ ) / g, ( match , p1 , p2 , p3 ) => {
236+ // Check if outputPaths already present
237+ if ( / o u t p u t P a t h s \s * = \s * \( [ \s \S ] * ?\) ; / . test ( match ) ) {
238+ // Patch outputPaths if missing our output
239+ return match . replace ( / ( o u t p u t P a t h s \s * = \s * \( ) ( .* ?) ( \) ; ) / s, ( m , op1 , op2 , op3 ) => {
240+ if ( op2 . includes ( '${DERIVED_FILE_DIR}/il2cpp_outputs' ) ) {
241+ return m ; // already present
242+ }
243+ modified = true ;
244+ // Insert our output at the top
245+ return `${ op1 } \n\t\t\t\t${ desiredOutput } \n${ op2 . trim ( ) ? '\t\t\t\t' + op2 . trim ( ) + '\n' : '' } \t\t\t${ op3 } ` ;
246+ } ) ;
247+ } else {
248+ // Insert outputPaths after shellScript
249+ modified = true ;
250+ // Find the end of shellScript line
251+ return match . replace ( / ( " ; ) / , `$1\n\t\t\toutputPaths = (\n\t\t\t\t${ desiredOutput } \n\t\t\t);` ) ;
240252 }
241- modified = true ;
242- return `${ p1 } ${ p2 } ${ p3 } (\n\t\t\t\t${ desiredOutput } \n\t\t\t);` ;
243253 } ) ;
244254 if ( modified ) {
245255 await fs . promises . writeFile ( pbxprojPath , pbxprojContent , 'utf8' ) ;
246256 core . info ( `Patched GameAssembly Run Script output path in ${ pbxprojPath } to \\${ '${DERIVED_FILE_DIR}/il2cpp_outputs' } ` ) ;
247257 } else {
248- core . info ( 'No GameAssembly Run Script phase found to patch or already set .' ) ;
258+ core . info ( 'GameAssembly Run Script phase already patched .' ) ;
249259 }
250260}
251261
0 commit comments