-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrewrite_dylibs.js
47 lines (33 loc) · 1.38 KB
/
rewrite_dylibs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const childProcess = require('child_process');
const { basename } = require('path');
console.log('Removing pre-written local dylibs...');
// clean
childProcess.execSync('rm -rf macos/build/PCem.app/Contents/MacOS/*.dylib', {
stdio: 'inherit'
});
console.log(`Analyzing pcem executable...`);
const stdout = childProcess.execSync(`otool -L macos/build/PCem.app/Contents/MacOS/pcem`, {
stdio: 'pipe',
}).toString();
const stdoutLines = stdout.split('\n');
const dylibs = [];
for (let i=0; i<stdoutLines.length; i++) {
// statically analyze dylibs of the executable pcem binary
if (stdoutLines[i].indexOf('.dylib') > -1) {
dylibs.push(stdoutLines[i].trim().split(' ')[0]);
}
}
console.log(`Re-writing dylibs of local pcem executable...`);
for (let i=0; i<dylibs.length; i++) {
// copy over system dylib into local App bundle
childProcess.execSync(`cp ${dylibs[i]} macos/build/PCem.app/Contents/MacOS`, {
stdio: 'inherit'
});
// re-link dylib to locally available App bundle dylib
childProcess.execSync(`install_name_tool -change ${dylibs[i]} @executable_path/${basename(dylibs[i])} macos/build/PCem.app/Contents/MacOS/pcem`)
}
console.log('Dylibs bundled into local App bundle: ', dylibs);
console.log('Re-written dylibs in local executable: ');
childProcess.execSync(`otool -L macos/build/PCem.app/Contents/MacOS/pcem`, {
stdio: 'inherit',
})