Skip to content

Commit

Permalink
Refactor: Use stric shell env for commands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deribaucourt committed Nov 12, 2024
1 parent d64a18a commit 0d55112
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 6 additions & 8 deletions client/src/driver/BitbakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ export class BitbakeDriver {

/// Execute a command in the bitbake environment
async spawnBitbakeProcess (command: string): Promise<IPty> {
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
Expand Down Expand Up @@ -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 : '.'
Expand Down Expand Up @@ -193,7 +191,7 @@ export class BitbakeDriver {
}

composeInteractiveCommand (): string {
return 'bash'
return 'printenv; bash'
}

composeDevshellCommand (recipe: string): string {
Expand Down
1 change: 1 addition & 0 deletions client/src/ui/BitbakeTerminalProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d55112

Please sign in to comment.