Skip to content

Commit 3298819

Browse files
try different patch regex
1 parent 3c1ed81 commit 3298819

3 files changed

Lines changed: 34 additions & 17 deletions

File tree

dist/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58671,22 +58671,29 @@ async function patchGameAssemblyRunScriptOutput(projectDirectory) {
5867158671
return;
5867258672
}
5867358673
let pbxprojContent = await fs.promises.readFile(pbxprojPath, 'utf8');
58674-
const runScriptRegex = /(\/\* Run Script \/\*\n[\s\S]*?shellScript = ")(.*GameAssembly[\s\S]*?)(";[\s\S]*?outputPaths = )(\([\s\S]*?\);)/g;
5867558674
const desiredOutput = '"${DERIVED_FILE_DIR}/il2cpp_outputs",';
5867658675
let modified = false;
58677-
pbxprojContent = pbxprojContent.replace(runScriptRegex, (match, p1, p2, p3, p4) => {
58678-
if (p4.includes('${DERIVED_FILE_DIR}/il2cpp_outputs')) {
58679-
return match;
58676+
pbxprojContent = pbxprojContent.replace(/(\/\* Run Script \/\*[\s\S]*?shellScript = ")(.*GameAssembly[\s\S]*?)(";[\s\S]*?)(?=\/\*|\n\s*\w+ =|$)/g, (match, p1, p2, p3) => {
58677+
if (/outputPaths\s*=\s*\([\s\S]*?\);/.test(match)) {
58678+
return match.replace(/(outputPaths\s*=\s*\()(.*?)(\);)/s, (m, op1, op2, op3) => {
58679+
if (op2.includes('${DERIVED_FILE_DIR}/il2cpp_outputs')) {
58680+
return m;
58681+
}
58682+
modified = true;
58683+
return `${op1}\n\t\t\t\t${desiredOutput}\n${op2.trim() ? '\t\t\t\t' + op2.trim() + '\n' : ''}\t\t\t${op3}`;
58684+
});
58685+
}
58686+
else {
58687+
modified = true;
58688+
return match.replace(/(";)/, `$1\n\t\t\toutputPaths = (\n\t\t\t\t${desiredOutput}\n\t\t\t);`);
5868058689
}
58681-
modified = true;
58682-
return `${p1}${p2}${p3}(\n\t\t\t\t${desiredOutput}\n\t\t\t);`;
5868358690
});
5868458691
if (modified) {
5868558692
await fs.promises.writeFile(pbxprojPath, pbxprojContent, 'utf8');
5868658693
core.info(`Patched GameAssembly Run Script output path in ${pbxprojPath} to \\${'${DERIVED_FILE_DIR}/il2cpp_outputs'}`);
5868758694
}
5868858695
else {
58689-
core.info('No GameAssembly Run Script phase found to patch or already set.');
58696+
core.info('GameAssembly Run Script phase already patched.');
5869058697
}
5869158698
}
5869258699
async function checkSimulatorsAvailable(platform) {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/xcode.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = /(\/\* Run Script \/\*\n[\s\S]*?shellScript = ")(.*GameAssembly[\s\S]*?)(";[\s\S]*?outputPaths = )(\([\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(/(\/\* Run Script \/\*[\s\S]*?shellScript = ")(.*GameAssembly[\s\S]*?)(";[\s\S]*?)(?=\/\*|\n\s*\w+ =|$)/g, (match, p1, p2, p3) => {
236+
// Check if outputPaths already present
237+
if (/outputPaths\s*=\s*\([\s\S]*?\);/.test(match)) {
238+
// Patch outputPaths if missing our output
239+
return match.replace(/(outputPaths\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

Comments
 (0)