Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first find/ensure where.exe exists before using it #3458

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# What's New?

## 1.16.32
Improvements:

- Improve our "smarts" when we attempt to provide PATH's for compilers or ninja. [PR #3458](/~https://github.com/microsoft/vscode-cmake-tools/pull/3458)

## 1.16.31
Bug Fixes:
- Refactor our attempt to add VS paths to PATH for cl, clang, etc. so that we fix issues with using the wrong compiler. [PR #3449](/~https://github.com/microsoft/vscode-cmake-tools/pull/3449)
Expand Down
29 changes: 25 additions & 4 deletions src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,13 +757,34 @@ export async function expandConfigurePreset(folder: string, name: string, worksp
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);
if (compilerName) {
const compilerLocation = await execute('where.exe', [compilerName], null, {

// find where.exe using process.env since we're on windows.
let whereExecutable;
// assume in this call that it exists
const whereOutput = await execute('where.exe', ['where.exe'], null, {
environment: process.env,
silent: true,
encoding: 'utf-8',
shell: true
}).result;

// now we have a valid where.exe

if (whereOutput.stdout) {
const locations = whereOutput.stdout.split('\r\n');
if (locations.length > 0) {
whereExecutable = locations[0];
}
}

if (compilerName && whereExecutable) {
const compilerLocation = await execute(whereExecutable, [compilerName], null, {
environment: EnvironmentUtils.create(expandedPreset.environment),
silent: true,
encoding: 'utf8',
shell: true
}).result;

if (!compilerLocation.stdout) {
// Not on PATH, need to set env
const arch = getArchitecture(preset);
Expand Down Expand Up @@ -838,8 +859,8 @@ export async function expandConfigurePreset(folder: string, name: string, worksp
compilerEnv = vsEnv ?? EnvironmentUtils.create();

// if ninja isn't on path, try to look for it in a VS install
const ninjaLoc = await execute('where.exe', ['ninja'], null, {
environment: EnvironmentUtils.create(preset.environment),
const ninjaLoc = await execute(whereExecutable, ['ninja'], null, {
environment: EnvironmentUtils.create(expandedPreset.environment),
silent: true,
encoding: 'utf8',
shell: true
Expand Down