Skip to content

Commit

Permalink
Feature: Add environment variables customization
Browse files Browse the repository at this point in the history
This patch adds a new setting `bitbake.shellEnv` which allows to set
environment variables before running the BitBake command. This allows
customizing oe-init-build-env but also kas, cqfd and other build tools.
  • Loading branch information
deribaucourt committed Dec 5, 2023
1 parent 5729a12 commit fe2d936
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
"type": "string",
"default": "${workspaceFolder}",
"description": "Set the working directory for running BitBake command."
},
"bitbake.shellEnv": {
"type": "object",
"default": {},
"description": "Environment variables to set before running the BitBake command."
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions client/src/driver/BitbakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class BitbakeDriver {
this.bitbakeActive = true
const child = childProcess.spawn(script, {
shell,
cwd: this.bitbakeSettings.workingDirectory
cwd: this.bitbakeSettings.workingDirectory,
env: { ...process.env, ...this.bitbakeSettings.shellEnv }
})
child.on('close', () => {
this.bitbakeActive = false
Expand All @@ -55,7 +56,8 @@ export class BitbakeDriver {
this.bitbakeActive = true
const ret = childProcess.spawnSync(script, {
shell,
cwd: this.bitbakeSettings.workingDirectory
cwd: this.bitbakeSettings.workingDirectory,
env: { ...process.env, ...this.bitbakeSettings.shellEnv }
})
this.bitbakeActive = false
return ret
Expand Down
8 changes: 7 additions & 1 deletion client/src/lib/src/BitbakeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface BitbakeSettings {
pathToEnvScript?: string
commandWrapper?: string
workingDirectory: string
shellEnv?: NodeJS.Dict<string>
}

export function loadBitbakeSettings (settings: any, workspaceFolder: string): BitbakeSettings {
Expand All @@ -29,7 +30,8 @@ export function loadBitbakeSettings (settings: any, workspaceFolder: string): Bi
pathToBuildFolder: settings.pathToBuildFolder !== '' ? resolveSettingsPath(settings.pathToBuildFolder, workspaceFolder) : undefined,
pathToEnvScript: settings.pathToEnvScript !== '' ? resolveSettingsPath(settings.pathToEnvScript, workspaceFolder) : undefined,
commandWrapper: settings.commandWrapper !== '' ? expandWorkspaceFolder(settings.commandWrapper, workspaceFolder) : undefined,
workingDirectory: settings.workingDirectory !== '' ? resolveSettingsPath(settings.workingDirectory, workspaceFolder) : workspaceFolder
workingDirectory: settings.workingDirectory !== '' ? resolveSettingsPath(settings.workingDirectory, workspaceFolder) : workspaceFolder,
shellEnv: toStringDict(settings.shellEnv)
}
}

Expand All @@ -48,3 +50,7 @@ function sanitizeForShell (command: string | undefined): string | undefined {
}
return command.replace(/[;`&|<>\\$(){}!#*?"']/g, '')
}

function toStringDict (dict: object | undefined): NodeJS.Dict<string> | undefined {
return dict as NodeJS.Dict<string> | undefined
}

0 comments on commit fe2d936

Please sign in to comment.