From 054bd877616a01e4d8e7e45114f3bda9f2f92134 Mon Sep 17 00:00:00 2001 From: snehara99 <113148726+snehara99@users.noreply.github.com> Date: Tue, 24 Oct 2023 09:26:28 -0400 Subject: [PATCH] Dev/gcampbell/attempt fix3318 (#3400) * initial attempt, it doesn't work, but I think it's a start * fixed! Confirmation for code cleanliness and working in all cases should be done * made a copy of preset.environment to find compiler location --------- Co-authored-by: Garrett Campbell --- src/preset.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/preset.ts b/src/preset.ts index d1a07e74f..803a8f8e9 100644 --- a/src/preset.ts +++ b/src/preset.ts @@ -840,13 +840,13 @@ function parseToolset(toolset: string): Toolset { async function expandConfigurePresetImpl(folder: string, name: string, workspaceFolder: string, sourceDir: string, allowUserPreset: boolean = false): Promise { let preset = getPresetByName(configurePresets(folder), name); if (preset) { - return expandConfigurePresetHelper(folder, preset, workspaceFolder, sourceDir); + return expandConfigurePresetHelper(folder, name, preset, workspaceFolder, sourceDir); } if (allowUserPreset) { preset = getPresetByName(userConfigurePresets(folder), name); if (preset) { - return expandConfigurePresetHelper(folder, preset, workspaceFolder, sourceDir, true); + return expandConfigurePresetHelper(folder, name, preset, workspaceFolder, sourceDir, true); } } @@ -854,7 +854,7 @@ async function expandConfigurePresetImpl(folder: string, name: string, workspace return null; } -async function expandConfigurePresetHelper(folder: string, preset: ConfigurePreset, workspaceFolder: string, sourceDir: string, allowUserPreset: boolean = false) { +async function expandConfigurePresetHelper(folder: string, name: string, preset: ConfigurePreset, workspaceFolder: string, sourceDir: string, allowUserPreset: boolean = false) { if (preset.__expanded) { return preset; } @@ -921,6 +921,10 @@ async function expandConfigurePresetHelper(folder: string, preset: ConfigurePres inheritedEnv = EnvironmentUtils.mergePreserveNull([process.env, inheritedEnv]); let compilerEnv = EnvironmentUtils.createPreserveNull(); + const expansionOpts: ExpansionOptions = await getExpansionOptions(workspaceFolder, sourceDir, preset); + expansionOpts.envOverride = inheritedEnv; + + preset.environment = EnvironmentUtils.mergePreserveNull([inheritedEnv, preset.environment]); // [Windows Only] If CMAKE_CXX_COMPILER or CMAKE_C_COMPILER is set as cl, clang, clang-cl, clang-cpp and clang++, // but they are not on PATH, then set the env automatically. @@ -930,9 +934,17 @@ async function expandConfigurePresetHelper(folder: string, preset: ConfigurePres const cCompiler = getStringValueFromCacheVar(preset.cacheVariables['CMAKE_C_COMPILER'])?.toLowerCase(); // The env variables for the supported compilers are the same. const compilerName: string | undefined = util.isSupportedCompiler(cxxCompiler) || util.isSupportedCompiler(cCompiler); + const expandedPreset: ConfigurePreset = { name }; + const expansionOpts: ExpansionOptions = await getExpansionOptions(workspaceFolder, sourceDir, preset); if (compilerName) { + expandedPreset.environment = EnvironmentUtils.createPreserveNull(); + for (const key in preset.environment) { + if (preset.environment[key]) { + expandedPreset.environment[key] = await expandString(preset.environment[key]!, expansionOpts); + } + } const compilerLocation = await execute('where.exe', [compilerName], null, { - environment: EnvironmentUtils.create(preset.environment), + environment: EnvironmentUtils.create(expandedPreset.environment), silent: true, encoding: 'utf8', shell: true