diff --git a/CHANGELOG.md b/CHANGELOG.md index b89a4714..a8d76039 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.11 +Improvements: + +- More wisely pass the modified environment variables, if present, from the pre/post-configure scripts to tasks and debugging options. [#540](https://github.com/microsoft/vscode-makefile-tools/issues/540), [#493](https://github.com/microsoft/vscode-makefile-tools/issues/493), [#554](https://github.com/microsoft/vscode-makefile-tools/issues/554) + Bug Fixes: - Ensure that we append line endings, which fixes a recent regression. [#641](https://github.com/microsoft/vscode-makefile-tools/issues/641) diff --git a/src/launch.ts b/src/launch.ts index 43e60634..7538e7c8 100644 --- a/src/launch.ts +++ b/src/launch.ts @@ -230,7 +230,13 @@ export class Launcher implements vscode.Disposable { request: "launch", cwd: this.getLaunchTargetDirectory(), args, - env: util.mergeEnvironment(process.env as util.EnvironmentVariables), + // Only pass a defined environment if there are modified environment variables. + env: + Object.keys(util.modifiedEnvironmentVariables).length > 0 + ? util.mergeEnvironment( + util.modifiedEnvironmentVariables as util.EnvironmentVariables + ) + : undefined, program: this.getLaunchTargetPath(), MIMode: miMode, miDebuggerPath: miDebuggerPath, diff --git a/src/make.ts b/src/make.ts index d4e89d23..3efffb27 100644 --- a/src/make.ts +++ b/src/make.ts @@ -478,7 +478,13 @@ export async function doBuildTarget( } let myTaskOptions: vscode.ShellExecutionOptions = { - env: util.mergeEnvironment(process.env as util.EnvironmentVariables), + // Only pass a defined environment if there are modified environment variables. + env: + Object.keys(util.modifiedEnvironmentVariables).length > 0 + ? util.mergeEnvironment( + util.modifiedEnvironmentVariables as util.EnvironmentVariables + ) + : undefined, cwd, }; @@ -1090,6 +1096,12 @@ async function applyEnvironment(content: string | undefined): Promise { if (eqPos !== -1) { let envVarName: string = line.substring(0, eqPos); let envVarValue: string = line.substring(eqPos + 1, line.length); + + // Only save to the modified environment values if it's different than the process.env. + if (!process.env[envVarName] || envVarValue !== process.env[envVarName]) { + util.modifiedEnvironmentVariables[envVarName] = envVarValue; + } + process.env[envVarName] = envVarValue; } }); diff --git a/src/util.ts b/src/util.ts index b8ba367e..752aacf3 100644 --- a/src/util.ts +++ b/src/util.ts @@ -338,6 +338,8 @@ export function mergeEnvironment( }, {}); } +export let modifiedEnvironmentVariables: EnvironmentVariables = {}; + export interface SpawnProcessResult { returnCode: number; signal: string; @@ -388,6 +390,10 @@ export function spawnChildProcess( `integrated.automationShell.${shellPlatform}` ); // and replaced with automationProfile + if (typeof shellType === "object") { + shellType = shellType["path"]; + } + // Final quoting decisions for process name and args before being executed. let qProcessName: string = ensureQuoted ? quoteStringIfNeeded(processName)