const fs = require('fs'); const path = require('path'); function absolutePath(value, workspace) { if (!value || !workspace) return null; const expanded = value.replace(/\$\{workspaceFolder\}/g, workspace); return path.resolve(workspace, expanded); } function projectForLaunch(configuration, workspace) { const explicit = absolutePath(configuration.project, workspace); if (explicit) { if (!fs.existsSync(path.join(explicit, 'Makefile'))) { throw new Error(`Нет Makefile в каталоге проекта: ${explicit}`); } return explicit; } const build = absolutePath(configuration.build, workspace); if (!build) return null; let directory = path.dirname(build); while (directory !== path.dirname(directory)) { if (fs.existsSync(path.join(directory, 'Makefile'))) { return directory; } if (directory === workspace) break; directory = path.dirname(directory); } return null; } function isSprinterMakefile(filename) { try { return /include\s+\$\(PROJ_ROOT\)\/app\.mk/.test( fs.readFileSync(filename, 'utf8')); } catch (_) { return false; } } function taskLabel(project, workspace) { const relative = path.relative(workspace, project); return `Sprinter: Build ${relative || '.'}`; } function makeCommand() { if (process.platform === 'win32') { throw new Error('Native Windows build/debug пока не поддерживается'); } return fs.existsSync('/usr/bin/make') ? '/usr/bin/make' : 'make'; } module.exports = {absolutePath, projectForLaunch, isSprinterMakefile, taskLabel, makeCommand};