Skip to content

Commit

Permalink
Dev/gcampbell/attempt fix3318 (#3400)
Browse files Browse the repository at this point in the history
* 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 <gcampbell@microsoft.com>
  • Loading branch information
snehara99 and gcampbell-msft authored Oct 24, 2023
1 parent dfdcd86 commit 054bd87
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,21 +840,21 @@ function parseToolset(toolset: string): Toolset {
async function expandConfigurePresetImpl(folder: string, name: string, workspaceFolder: string, sourceDir: string, allowUserPreset: boolean = false): Promise<ConfigurePreset | null> {
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);
}
}

log.error(localize('config.preset.not.found', 'Could not find configure preset with name {0}', name));
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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 054bd87

Please sign in to comment.