diff --git a/client/src/__tests__/unit-tests/driver/eSDKMode.test.ts b/client/src/__tests__/unit-tests/driver/eSDKMode.test.ts index e99d585e..c891b4f1 100644 --- a/client/src/__tests__/unit-tests/driver/eSDKMode.test.ts +++ b/client/src/__tests__/unit-tests/driver/eSDKMode.test.ts @@ -5,7 +5,6 @@ import { BitBakeProjectScanner } from '../../../driver/BitBakeProjectScanner' import { BitbakeDriver } from '../../../driver/BitbakeDriver' -import * as BitbakeTerminal from '../../../ui/BitbakeTerminal' import * as ProcessUtils from '../../../utils/ProcessUtils' import { bitbakeESDKMode, setBitbakeESDKMode } from '../../../driver/BitbakeESDK' import { clientNotificationManager } from '../../../ui/ClientNotificationManager' @@ -47,7 +46,7 @@ describe('Devtool eSDK Mode Test Suite', () => { pathToBuildFolder: 'nonexistent' } bitbakeDriver.loadSettings(bitbakeSettings, __dirname) - const bitbakeTerminalSpy = jest.spyOn(BitbakeTerminal, 'runBitbakeTerminalCustomCommand').mockImplementation(async () => (undefined as unknown as Promise)) + const bitbakeTerminalSpy = jest.spyOn(bitbakeDriver, 'runTerminalCommand').mockImplementation(async () => (undefined as unknown as Promise)) const bitbakeExecutionSpy = jest.spyOn(ProcessUtils, 'finishProcessExecution') clientNotificationManager.showBitbakeSettingsError = jest.fn() diff --git a/client/src/driver/BitbakeDriver.ts b/client/src/driver/BitbakeDriver.ts index 416c21c2..bc5b7c9c 100644 --- a/client/src/driver/BitbakeDriver.ts +++ b/client/src/driver/BitbakeDriver.ts @@ -8,9 +8,7 @@ import fs from 'fs' import { logger } from '../lib/src/utils/OutputLogger' import { type BitbakeSettings, loadBitbakeSettings, sanitizeForShell, type BitbakeBuildConfigSettings, getBuildSetting } from '../lib/src/BitbakeSettings' -import { clientNotificationManager } from '../ui/ClientNotificationManager' import { type BitbakeTaskDefinition } from '../ui/BitbakeTaskProvider' -import { runBitbakeTerminalCustomCommand } from '../ui/BitbakeTerminal' import { bitbakeESDKMode, setBitbakeESDKMode } from './BitbakeESDK' import { BITBAKE_EXIT_TIMEOUT, finishProcessExecution, pty } from '../utils/ProcessUtils' @@ -23,6 +21,15 @@ export class BitbakeDriver { bitbakeProcess: IPty | undefined bitbakeProcessCommand: string | undefined onBitbakeProcessChange: EventEmitter = new EventEmitter() + logBitbakeSettingsError: (message: string) => void = logger.error.bind(logger) + runTerminalCommand: ( + bitbakeDriver: BitbakeDriver, + command: string, + terminalName: string, + isBackground?: boolean + ) => Promise = async () => { + return {} as IPty; + }; loadSettings (settings: Record, workspaceFolder: string = '.'): void { this.bitbakeSettings = loadBitbakeSettings(settings, workspaceFolder) @@ -126,25 +133,25 @@ export class BitbakeDriver { async checkBitbakeSettingsSanity (): Promise { if (!fs.existsSync(this.bitbakeSettings.pathToBitbakeFolder)) { - clientNotificationManager.showBitbakeSettingsError('Bitbake folder not found on disk.') + this.logBitbakeSettingsError('Bitbake folder not found on disk.') return false } const workingDirectory = this.getBuildConfig('workingDirectory') if (typeof workingDirectory === 'string' && !fs.existsSync(workingDirectory)) { // If it is not defined, then we will use the workspace folder which is always valid - clientNotificationManager.showBitbakeSettingsError('Working directory does not exist.') + this.logBitbakeSettingsError('Working directory does not exist.') return false } // We could test for devtool and bitbake to know if we are in an eSDK or not const command = 'which devtool bitbake || true' - const process = runBitbakeTerminalCustomCommand(this, command, 'Bitbake: Sanity test', true) + const process = this.runTerminalCommand(this, command, 'Bitbake: Sanity test', true) const ret = await finishProcessExecution(process, async () => { await this.killBitbake() }) const outLines = ret.stdout.toString().split(/\r?\n/g) if (outLines.filter((line) => /devtool$/.test(line)).length === 0) { - clientNotificationManager.showBitbakeSettingsError('devtool not found in $PATH\nSee Bitbake Terminal for command output.') + this.logBitbakeSettingsError('devtool not found in $PATH\nSee Bitbake Terminal for command output.') return false } diff --git a/client/src/driver/BitbakeDriverVSCode.ts b/client/src/driver/BitbakeDriverVSCode.ts new file mode 100644 index 00000000..ede4373d --- /dev/null +++ b/client/src/driver/BitbakeDriverVSCode.ts @@ -0,0 +1,19 @@ +/* -------------------------------------------------------------------------------------------- + * Copyright (c) 2025 Savoir-faire Linux. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * ------------------------------------------------------------------------------------------ */ + +import { BitbakeDriver } from "./BitbakeDriver"; +import { clientNotificationManager } from '../ui/ClientNotificationManager' +import { runBitbakeTerminalCustomCommand } from '../ui/BitbakeTerminal' +import { type IPty } from 'node-pty' + +export class BitbakeDriverVSCode extends BitbakeDriver { + logBitbakeSettingsError: (message: string) => void = clientNotificationManager.showBitbakeSettingsError.bind(clientNotificationManager) + runTerminalCommand: ( + bitbakeDriver: BitbakeDriver, + command: string, + terminalName: string, + isBackground?: boolean + ) => Promise = runBitbakeTerminalCustomCommand +} diff --git a/client/src/extension.ts b/client/src/extension.ts index 32be5f3d..ef7e3ae6 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -9,7 +9,7 @@ import { type LanguageClient } from 'vscode-languageclient/node' import { clientNotificationManager } from './ui/ClientNotificationManager' import { logger } from './lib/src/utils/OutputLogger' import { activateLanguageServer, deactivateLanguageServer } from './language/languageClient' -import { BitbakeDriver } from './driver/BitbakeDriver' +import { BitbakeDriverVSCode } from './driver/BitbakeDriverVSCode' import { BitbakeTaskProvider } from './ui/BitbakeTaskProvider' import { registerBitbakeCommands, registerDevtoolCommands } from './ui/BitbakeCommands' import { BitbakeWorkspace } from './ui/BitbakeWorkspace' @@ -30,7 +30,7 @@ import { embeddedLanguageDocsManager } from './language/EmbeddedLanguageDocsMana import { NotificationMethod } from './lib/src/types/notifications' let client: LanguageClient -const bitbakeDriver: BitbakeDriver = new BitbakeDriver() +const bitbakeDriver: BitbakeDriverVSCode = new BitbakeDriverVSCode() let bitbakeTaskProvider: BitbakeTaskProvider let taskProvider: vscode.Disposable const bitbakeWorkspace: BitbakeWorkspace = new BitbakeWorkspace()