"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveDebugAdapterExecutable = resolveDebugAdapterExecutable;
const ide_core_common_1 = require("@opensumi/ide-core-common");
const path_1 = require("@opensumi/ide-utils/lib/path");
const ext_types_1 = require("../../../../common/vscode/ext-types");
async function resolveDebugAdapterExecutable(pluginPath, debuggerContribution) {
    const info = toPlatformInfo(debuggerContribution);
    let program = (info && info.program) || debuggerContribution.program;
    if (!program) {
        return undefined;
    }
    program = (0, path_1.join)(pluginPath, program);
    const programArgs = (info && info.args) || debuggerContribution.args || [];
    let runtime = (info && info.runtime) || debuggerContribution.runtime;
    if (runtime && runtime.indexOf('./') === 0) {
        runtime = (0, path_1.join)(pluginPath, runtime);
    }
    const runtimeArgs = (info && info.runtimeArgs) || debuggerContribution.runtimeArgs || [];
    const command = runtime ? runtime : program;
    const args = runtime ? [...runtimeArgs, program, ...programArgs] : programArgs;
    return new ext_types_1.DebugAdapterExecutable(command, args);
}
function toPlatformInfo(executable) {
    if (ide_core_common_1.isWindows && !process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')) {
        return executable.winx86 || executable.win || executable.windows;
    }
    if (ide_core_common_1.isWindows) {
        return executable.win || executable.windows;
    }
    if (ide_core_common_1.isOSX) {
        return executable.osx;
    }
    return executable.linux;
}
//# sourceMappingURL=extension-debug-adapter-excutable-resolver.js.map