Skip to content

Commit

Permalink
first find/ensure where.exe exists before using it (#3458)
Browse files Browse the repository at this point in the history
* first find/ensure where.exe exists before using it

* update changelog
  • Loading branch information
gcampbell-msft authored Nov 20, 2023
1 parent 0d99580 commit 8018ef5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
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

0 comments on commit 8018ef5

Please sign in to comment.