From 0d551120ecb3cd5e2e2c802bf30214dae557691f Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Tue, 12 Nov 2024 10:45:46 +0100 Subject: [PATCH] Refactor: Use stric shell env for commands The previous code duplicated the logic to prepare the shell environment in temrinal profile and regular commands. Let's properly define the same one in both places. --- client/src/driver/BitbakeDriver.ts | 14 ++++++-------- client/src/ui/BitbakeTerminalProfile.ts | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/src/driver/BitbakeDriver.ts b/client/src/driver/BitbakeDriver.ts index ef0312ab..58ba6532 100644 --- a/client/src/driver/BitbakeDriver.ts +++ b/client/src/driver/BitbakeDriver.ts @@ -46,17 +46,15 @@ export class BitbakeDriver { /// Execute a command in the bitbake environment async spawnBitbakeProcess (command: string): Promise { - const { shell, script } = this.prepareCommand(command) - const cwd = this.getBuildConfig('workingDirectory') - const shellEnv = this.getBuildConfig('shellEnv') + const { shell, shellEnv, script, workingDirectory } = this.prepareCommand(command) await this.waitForBitbakeToFinish() - logger.debug(`Executing Bitbake command with ${shell} in ${cwd}: ${script}`) + logger.debug(`Executing Bitbake command with ${shell} in ${workingDirectory}: ${script}`) const child = pty.spawn( shell, ['-c', script], { - cwd: typeof(cwd) === 'string' ? cwd : undefined, - env: { ...process.env, ...(typeof shellEnv === 'object' ? shellEnv : {}) } + cwd: workingDirectory, + env: shellEnv } ) this.bitbakeProcess = child @@ -86,7 +84,7 @@ export class BitbakeDriver { } { const shell = process.env.SHELL ?? '/bin/sh' const tempShellEnv = this.getBuildConfig('shellEnv') - const shellEnv = typeof tempShellEnv === 'object' ? tempShellEnv : {} + const shellEnv = {...process.env, ...(typeof tempShellEnv === 'object' ? tempShellEnv : {}) } const script = this.composeBitbakeScript(command) const tempWorkingDirectory = this.getBuildConfig('workingDirectory') const workingDirectory = typeof tempWorkingDirectory === 'string' ? tempWorkingDirectory : '.' @@ -193,7 +191,7 @@ export class BitbakeDriver { } composeInteractiveCommand (): string { - return 'bash' + return 'printenv; bash' } composeDevshellCommand (recipe: string): string { diff --git a/client/src/ui/BitbakeTerminalProfile.ts b/client/src/ui/BitbakeTerminalProfile.ts index 9bbef52c..cf2dea89 100644 --- a/client/src/ui/BitbakeTerminalProfile.ts +++ b/client/src/ui/BitbakeTerminalProfile.ts @@ -29,6 +29,7 @@ export class BitbakeTerminalProfileProvider implements vscode.TerminalProfilePro shellPath: shell, shellArgs: ['-c', script], env: shellEnv, + strictEnv: true, cwd: workingDirectory, iconPath: vscode.Uri.file(path.resolve(__dirname, '../../images/yocto-view-icon.svg')) } satisfies vscode.TerminalOptions