-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-MIEngine.mjs
More file actions
88 lines (75 loc) · 3.09 KB
/
Copy pathbuild-MIEngine.mjs
File metadata and controls
88 lines (75 loc) · 3.09 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import path from 'path';
import fs from 'fs';
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = __dirname;
const miEngineDir = path.join(rootDir, 'submodules', 'MIEngine');
const distDir = path.join(rootDir, 'dist');
const debugAdapterDir = path.join(distDir, 'debugAdapter');
const csprojPath = path.join(miEngineDir, 'src', 'MakePIAPortable', 'MakePIAPortable.csproj');
async function build() {
// 1. Delete debugAdapter directory
if (fs.existsSync(debugAdapterDir)) {
console.log(`Deleting ${debugAdapterDir}...`);
fs.rmSync(debugAdapterDir, { recursive: true, force: true });
}
fs.mkdirSync(distDir, { recursive: true });
let originalCsprojContent = null;
let modified = false;
// 1.5 Patch MakePIAPortable.csproj for Linux ARM64/LoongArch64
if (process.platform === 'linux' && (process.arch === 'arm64' || process.arch === 'loong64')) {
if (fs.existsSync(csprojPath)) {
const replaceArch = process.arch === 'arm64' ? 'linux-arm64' : 'linux-loongarch64';
try {
originalCsprojContent = fs.readFileSync(csprojPath, 'utf8');
if (originalCsprojContent.includes('linux-x64')) {
console.log('Detected Linux ARM64/LoongArch64, patching MakePIAPortable.csproj...');
const newContent = originalCsprojContent.replace(/linux-x64/g, replaceArch);
fs.writeFileSync(csprojPath, newContent, 'utf8');
modified = true;
}
} catch (err) {
console.error('Error patching MakePIAPortable.csproj:', err);
}
}
}
// 2. Determine script based on platform
const isWindows = process.platform === 'win32';
const scriptName = isWindows ? 'PublishOpenDebugAD7.bat' : './PublishOpenDebugAD7.sh';
// Arguments: -c Release -o <absolute_path_to_debugAdapter>
const args = ['-c', 'Release', '-o', debugAdapterDir];
console.log(`Executing ${scriptName} ${args.join(' ')} in ${miEngineDir}...`);
const child = spawn(scriptName, args, {
cwd: miEngineDir,
stdio: 'inherit',
shell: true
});
const restoreCsproj = () => {
if (modified && originalCsprojContent) {
try {
console.log('Restoring MakePIAPortable.csproj...');
fs.writeFileSync(csprojPath, originalCsprojContent, 'utf8');
modified = false;
} catch (err) {
console.error('Error restoring MakePIAPortable.csproj:', err);
}
}
};
child.on('close', (code) => {
restoreCsproj();
if (code !== 0) {
console.error(`Build failed with code ${code}`);
process.exit(1);
} else {
console.log('Build completed successfully.');
}
});
child.on('error', (err) => {
restoreCsproj();
console.error('Failed to start subprocess:', err);
process.exit(1);
});
}
build();