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

determine shell for .cmd, .bat, .ps1 #4044

Merged
merged 8 commits into from
Oct 10, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Features:

- Add support for Presets v9, which enables more macro expansion for the `include` field. [#3946](https://github.com/microsoft/vscode-cmake-tools/issues/3946)

Improvements:

- Ensure that any uses of `proc.spawn` work, especially for .bat and .cmd files, due to VS Code updating to Node 20. [#4037](https://github.com/microsoft/vscode-cmake-tools/issues/4037)

Bug Fixes:

- Fix our setting of `isUserPreset` for presets, only set it to `true` if it's defined in a user presets file. [#4059](https://github.com/microsoft/vscode-cmake-tools/issues/4059)
Expand Down
19 changes: 18 additions & 1 deletion src/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface ExecutionResult {

export interface ExecutionOptions {
environment?: Environment;
shell?: boolean;
shell?: boolean | string;
silent?: boolean;
cwd?: string;
encoding?: BufferEncoding;
Expand All @@ -113,6 +113,18 @@ export function buildCmdStr(command: string, args?: string[]): string {
return cmdarr.map(a => /[ \n\r\f;\t]/.test(a) ? `"${a}"` : a).join(' ');
}

export function determineShell(command: string): string | boolean {
if (command.endsWith('.cmd') || command.endsWith('.bat')) {
return 'cmd';
}

if (command.endsWith('.ps1')) {
return 'powershell';
}

return false;
}

/**
* Execute a command and return the result
* @param command The binary to execute
Expand Down Expand Up @@ -146,6 +158,11 @@ export function execute(command: string, args?: string[], outputConsumer?: Outpu
log.debug(localize('execution.environment', ' with environment: {0}', JSON.stringify(final_env)));
}
}

if (process.platform === "win32" && options.shell === undefined) {
options.shell = determineShell(command);
}

const spawn_opts: proc.SpawnOptions = {
env: final_env,
shell: !!options.shell
Expand Down
Loading