-
Notifications
You must be signed in to change notification settings - Fork 381
Turn off shell by default #2306
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
Draft
nagilson
wants to merge
13
commits into
dotnet:main
Choose a base branch
from
nagilson:nagilson-no-shell
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d52c6e3
Turn off shell by default
nagilson 4418f00
only disable shell on win
nagilson 90e68c6
Merge branch 'main' into nagilson-no-shell
nagilson 3a31ed1
Fix build error
nagilson 6108e6c
Merge branch 'nagilson-no-shell' of https://github.com/nagilson/vscod…
nagilson 88d78e4
use shell where it is required
nagilson 0857365
fix conflict
nagilson 5f0a2fa
WIP Use Spawn over exec
nagilson 60228e1
ignore stdin
nagilson 4b099a2
Fix some test bugs, ignore stdin
nagilson b4d8b66
Merge branch 'main' into nagilson-no-shell
nagilson d0e24d0
Merge remote-tracking branch 'upstream/main' into nagilson-no-shell
nagilson 0e36e18
Fix merge
nagilson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ | |
| import * as proc from 'child_process'; | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import { promisify } from 'util'; | ||
| import open = require('open'); | ||
| import path = require('path'); | ||
|
|
||
|
|
@@ -440,7 +439,11 @@ ${stderr}`)); | |
| options.cwd ??= path.resolve(__dirname); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
| options.shell ??= true; | ||
| options.shell ??= os.platform() === 'win32' ? false : true; | ||
| // ^ Windows systemcalls (node.js process library uses process_wrap which uses process.cc which makes system calls) | ||
| // Windows seems to resolve the PATH by default in a system call. Unix system calls do not. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just respect shell and let the shell do this? |
||
| // We could further improve Unix performance in the future by re-implementing our own PATH resolution. | ||
| // And turning SHELL off by default on Unix as well. | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
| options.encoding = 'utf8'; | ||
|
|
@@ -455,7 +458,7 @@ ${stderr}`)); | |
| else | ||
| { | ||
| options = { | ||
| cwd: path.resolve(__dirname), shell: true, encoding: 'utf8', env: | ||
| cwd: path.resolve(__dirname), shell: os.platform() === 'win32' ? false : true, encoding: 'utf8', env: | ||
| { ...process.env, DOTNET_CLI_UI_LANGUAGE: 'en-US', DOTNET_NOLOGO: 'true' } | ||
| }; | ||
| } | ||
|
|
@@ -515,39 +518,79 @@ ${stderr}`)); | |
| } | ||
|
|
||
| const commandStartTime = process.hrtime.bigint(); | ||
| const commandResult: CommandExecutorResult = await promisify(proc.exec)(fullCommandString, options).then( | ||
| fulfilled => | ||
| const commandResult: CommandExecutorResult = await this.asyncSpawn(command, options, terminalFailure); | ||
| this.logCommandResult(commandResult, fullCommandString, commandStartTime, command.commandRoot); | ||
|
|
||
| if (useCache) | ||
| { | ||
| LocalMemoryCacheSingleton.getInstance().putCommand({ command, options }, commandResult, this.context); | ||
| } | ||
| return commandResult; | ||
| } | ||
| } | ||
|
|
||
| private asyncSpawn(commandToExecute: CommandExecutorCommand, options: any, terminalFailure: boolean): Promise<CommandExecutorResult> | ||
| { | ||
| return new Promise((resolve, reject) => | ||
| { | ||
| const child = proc.spawn(commandToExecute.commandRoot, commandToExecute.commandParts, { | ||
| ...options, | ||
| stdio: ['ignore', 'pipe', 'pipe'], // Ignore stdin (we won't send any input), Capture stdout and stderr | ||
| }); | ||
|
|
||
| let stdout = ''; | ||
| let stderr = ''; | ||
|
|
||
| child.stdout.on('data', (data: any) => | ||
| { | ||
| stdout += data.toString(); | ||
| }); | ||
|
|
||
| child.stderr.on('data', (data: any) => | ||
| { | ||
| stderr += data.toString(); | ||
| }); | ||
|
|
||
| child.on('close', (code: any) => | ||
| { | ||
| if (code === 0) | ||
| { | ||
| return resolve({ stdout, stderr, status: '0' }); | ||
| } | ||
| else | ||
| { | ||
| // If any status besides 0 is returned, an error is thrown by nodejs | ||
| return { stdout: fulfilled.stdout?.toString() ?? '', stderr: fulfilled.stderr?.toString() ?? '', status: '0' }; | ||
| }, | ||
| rejected => // Rejected object: error type with stderr : Buffer, stdout : Buffer ... with .code (number) or .signal (string)} | ||
| { // see https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
| const result = { stdout: rejected?.stdout?.toString() ?? '', stderr: rejected?.stderr?.toString() ?? '', status: rejected?.code?.toString() ?? rejected?.signal?.toString() ?? '' }; | ||
| const result = { stdout, stderr, status: code?.toString() ?? '1' }; | ||
| if (terminalFailure) | ||
| { | ||
| this.logCommandResult(result, fullCommandString, commandStartTime, command.commandRoot); | ||
| throw rejected ?? new Error(`Spawning ${fullCommandString} failed with an unspecified error.`); // according to nodejs spec, this should never be possible | ||
| this.logCommandResult(result, CommandExecutor.prettifyCommandExecutorCommand(commandToExecute, false), process.hrtime.bigint(), commandToExecute.commandRoot); | ||
| return reject(new CommandExecutionNonZeroExitFailure(new EventBasedError('CommandExecutionNonZeroExitFailure', ''), null)); | ||
| } | ||
| else | ||
| { | ||
| // signal is a string or obj, code is a number | ||
| return result; | ||
| return resolve(result); | ||
| } | ||
| } | ||
| ); | ||
| }); // We don't need to handle exit, close is when all exits have been called. (stderr, stdout) | ||
|
|
||
| this.logCommandResult(commandResult, fullCommandString, commandStartTime, command.commandRoot); | ||
|
|
||
| if (useCache) | ||
| child.on('error', (error) => | ||
| { | ||
| LocalMemoryCacheSingleton.getInstance().putCommand({ command, options }, commandResult, this.context); | ||
| } | ||
| return commandResult; | ||
| } | ||
| const result = { stdout, stderr, status: error.name?.toString() ?? '' }; | ||
| if (terminalFailure) | ||
| { | ||
| this.logCommandResult(result, CommandExecutor.prettifyCommandExecutorCommand(commandToExecute, false), process.hrtime.bigint(), commandToExecute.commandRoot); | ||
| return reject(new CommandExecutionNonZeroExitFailure(new EventBasedError('CommandExecutionNonZeroExitFailure', ''), null)); | ||
| } | ||
| else | ||
| { | ||
| // signal is a string or obj, code is a number | ||
| return resolve(result); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| private logCommandResult(commandResult: CommandExecutorResult, fullCommandStringForTelemetryOnly: string, commandStartTime: bigint, commandRoot: string) | ||
| { | ||
| const durationMs = (Number(process.hrtime.bigint() - commandStartTime) / 1000000).toFixed(2); | ||
|
|
@@ -646,10 +689,10 @@ Please report this at https://github.com/dotnet/vscode-dotnet-runtime/issues.`), | |
| if (os.platform() === 'win32') | ||
| { | ||
| const setShellVariable = CommandExecutor.makeCommand(`set`, [`${variable}=${value}`]); | ||
| const setSystemVariable = CommandExecutor.makeCommand(`setx`, [`${variable}`, `"${value}"`]); | ||
| const setSystemVariable = CommandExecutor.makeCommand(`setx`, [`${variable}`, `${value}`]); | ||
| try | ||
| { | ||
| const shellEditResponse = (await this.execute(setShellVariable, null, false)).status; | ||
| const shellEditResponse = (await this.execute(setShellVariable, { shell: true }, false)).status; | ||
| environmentEditExitCode += Number(shellEditResponse[0]); | ||
| const systemEditResponse = (await this.execute(setSystemVariable, null, false)).status | ||
| environmentEditExitCode += Number(systemEditResponse[0]); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this break Linux/Mac scenarios in the shell? I think we need to look at this from a broader context.