From c1ce148283b5ad48609dc4b96f4024295b1247e0 Mon Sep 17 00:00:00 2001 From: Anakin Childerhose Date: Wed, 30 Apr 2025 09:57:11 -0400 Subject: [PATCH 1/4] Refactor: Add BitbakeDriverVSCode To refactor BitbakeDriver to become editor agnostic, add BitbakeDriverVSCode which will be the base for factoring out VSCode specific functionality from BitbakeDriver. --- client/src/driver/BitbakeDriverVSCode.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 client/src/driver/BitbakeDriverVSCode.ts diff --git a/client/src/driver/BitbakeDriverVSCode.ts b/client/src/driver/BitbakeDriverVSCode.ts new file mode 100644 index 00000000..54fcd34b --- /dev/null +++ b/client/src/driver/BitbakeDriverVSCode.ts @@ -0,0 +1,9 @@ +/* -------------------------------------------------------------------------------------------- + * 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"; + +export class BitbakeDriverVSCode extends BitbakeDriver { +} From 0cdf74259b528d8299009c37f4f27ea07a1bb77a Mon Sep 17 00:00:00 2001 From: Anakin Childerhose Date: Wed, 30 Apr 2025 10:16:34 -0400 Subject: [PATCH 2/4] Refactor: Switch extension to use BitbakeDriverVSCode --- client/src/extension.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() From 964849d4f4bc9111aa65441b4bbe8e491520ba48 Mon Sep 17 00:00:00 2001 From: Anakin Childerhose Date: Wed, 30 Apr 2025 10:17:49 -0400 Subject: [PATCH 3/4] Refactor: factor out clientNotificationManager from BitbakeDriver To make BitbakeDriver editor agnostic, change the notifications from a VSCode dependent implementation to the standard logging and override it to clientNotificationManager in BitbakeDriverVSCode. --- client/src/driver/BitbakeDriver.ts | 8 ++++---- client/src/driver/BitbakeDriverVSCode.ts | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/driver/BitbakeDriver.ts b/client/src/driver/BitbakeDriver.ts index 416c21c2..95285461 100644 --- a/client/src/driver/BitbakeDriver.ts +++ b/client/src/driver/BitbakeDriver.ts @@ -8,7 +8,6 @@ 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' @@ -23,6 +22,7 @@ export class BitbakeDriver { bitbakeProcess: IPty | undefined bitbakeProcessCommand: string | undefined onBitbakeProcessChange: EventEmitter = new EventEmitter() + logBitbakeSettingsError: (message: string) => void = logger.error.bind(logger) loadSettings (settings: Record, workspaceFolder: string = '.'): void { this.bitbakeSettings = loadBitbakeSettings(settings, workspaceFolder) @@ -126,14 +126,14 @@ 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 } @@ -144,7 +144,7 @@ export class BitbakeDriver { 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 index 54fcd34b..7803bde2 100644 --- a/client/src/driver/BitbakeDriverVSCode.ts +++ b/client/src/driver/BitbakeDriverVSCode.ts @@ -4,6 +4,8 @@ * ------------------------------------------------------------------------------------------ */ import { BitbakeDriver } from "./BitbakeDriver"; +import { clientNotificationManager } from '../ui/ClientNotificationManager' export class BitbakeDriverVSCode extends BitbakeDriver { + logBitbakeSettingsError: (message: string) => void = clientNotificationManager.showBitbakeSettingsError.bind(clientNotificationManager) } From 197b8b6513e460c0465bac64bc6d1ab758fd6868 Mon Sep 17 00:00:00 2001 From: Anakin Childerhose Date: Wed, 30 Apr 2025 10:55:37 -0400 Subject: [PATCH 4/4] Refactor: Make terminal commands editor agnostic To make the BitbakeDriver editor agnostic, replace runBitbakeTerminalCustomCommand with a generic runTerminalCommand function that gets overriden by runBitbakeTerminalCustomCommand in BitbakeDriverVSCode. --- .../src/__tests__/unit-tests/driver/eSDKMode.test.ts | 3 +-- client/src/driver/BitbakeDriver.ts | 11 +++++++++-- client/src/driver/BitbakeDriverVSCode.ts | 8 ++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) 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 95285461..bc5b7c9c 100644 --- a/client/src/driver/BitbakeDriver.ts +++ b/client/src/driver/BitbakeDriver.ts @@ -9,7 +9,6 @@ import fs from 'fs' import { logger } from '../lib/src/utils/OutputLogger' import { type BitbakeSettings, loadBitbakeSettings, sanitizeForShell, type BitbakeBuildConfigSettings, getBuildSetting } from '../lib/src/BitbakeSettings' 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 +22,14 @@ export class BitbakeDriver { 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) @@ -139,7 +146,7 @@ export class BitbakeDriver { // 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) diff --git a/client/src/driver/BitbakeDriverVSCode.ts b/client/src/driver/BitbakeDriverVSCode.ts index 7803bde2..ede4373d 100644 --- a/client/src/driver/BitbakeDriverVSCode.ts +++ b/client/src/driver/BitbakeDriverVSCode.ts @@ -5,7 +5,15 @@ 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 }