Skip to content

Commit

Permalink
Remove some uses of process in tasks
Browse files Browse the repository at this point in the history
The terminal task system still has references to process that affect only Windows. This change removes some of those references

Part of #69113
  • Loading branch information
alexr00 committed Jun 18, 2019
1 parent 5678473 commit 416f8ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { RunAutomaticTasks } from 'vs/workbench/contrib/tasks/browser/runAutomat

import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';

export namespace ConfigureTaskAction {
export const ID = 'workbench.action.tasks.configureTaskRunner';
Expand Down Expand Up @@ -220,6 +221,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@ITerminalInstanceService private readonly terminalInstanceService: ITerminalInstanceService,
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService
) {
super();

Expand Down Expand Up @@ -1094,6 +1096,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this.modelService, this.configurationResolverService, this.telemetryService,
this.contextService, this.environmentService,
AbstractTaskService.OutputChannelId, this.fileService, this.terminalInstanceService,
this.remoteAgentService,
(workspaceFolder: IWorkspaceFolder) => {
if (!workspaceFolder) {
return undefined;
Expand Down
46 changes: 34 additions & 12 deletions src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
import { Schemas } from 'vs/base/common/network';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';

interface TerminalData {
terminal: ITerminalInstance;
Expand Down Expand Up @@ -172,6 +173,7 @@ export class TerminalTaskSystem implements ITaskSystem {
private outputChannelId: string,
private fileService: IFileService,
private terminalInstanceService: ITerminalInstanceService,
private remoteAgentService: IRemoteAgentService,
taskSystemInfoResolver: TaskSystemInfoResolver,
) {

Expand Down Expand Up @@ -506,13 +508,18 @@ export class TerminalTaskSystem implements ITaskSystem {
}
}

private executeInTerminal(task: CustomTask | ContributedTask, trigger: string, resolver: VariableResolver): Promise<ITaskSummary> {
private async executeInTerminal(task: CustomTask | ContributedTask, trigger: string, resolver: VariableResolver): Promise<ITaskSummary> {
let terminal: ITerminalInstance | undefined = undefined;
let executedCommand: string | undefined = undefined;
let error: TaskError | undefined = undefined;
let promise: Promise<ITaskSummary> | undefined = undefined;
let terminalPromise: Promise<void> | undefined = undefined;
if (task.configurationProperties.isBackground) {
promise = new Promise<ITaskSummary>((resolve, reject) => {
terminalPromise = new Promise<void>(async (resolveTerminal) => {
[terminal, executedCommand, error] = await this.createTerminal(task, resolver);
resolveTerminal();
});
promise = new Promise<ITaskSummary>(async (resolve, reject) => {
const problemMatchers = this.resolveMatchers(resolver, task.configurationProperties.problemMatchers);
let watchingProblemMatcher = new WatchingProblemCollector(problemMatchers, this.markerService, this.modelService, this.fileService);
let toDispose: IDisposable[] | undefined = [];
Expand Down Expand Up @@ -541,7 +548,7 @@ export class TerminalTaskSystem implements ITaskSystem {
}));
watchingProblemMatcher.aboutToStart();
let delayer: Async.Delayer<any> | undefined = undefined;
[terminal, executedCommand, error] = this.createTerminal(task, resolver);
await terminalPromise;
if (error || !terminal) {
return;
}
Expand Down Expand Up @@ -615,8 +622,12 @@ export class TerminalTaskSystem implements ITaskSystem {
});
});
} else {
promise = new Promise<ITaskSummary>((resolve, reject) => {
[terminal, executedCommand, error] = this.createTerminal(task, resolver);
terminalPromise = new Promise<void>(async (resolveTerminal) => {
[terminal, executedCommand, error] = await this.createTerminal(task, resolver);
resolveTerminal();
});
promise = new Promise<ITaskSummary>(async (resolve, reject) => {
await terminalPromise;
if (!terminal || error) {
return;
}
Expand Down Expand Up @@ -687,6 +698,7 @@ export class TerminalTaskSystem implements ITaskSystem {
});
});
}
await terminalPromise;
if (error) {
return Promise.reject(new Error((<TaskError>error).message));
}
Expand Down Expand Up @@ -770,7 +782,15 @@ export class TerminalTaskSystem implements ITaskSystem {
return defaultShell;
}

private createShellLaunchConfig(task: CustomTask | ContributedTask, variableResolver: VariableResolver, platform: Platform.Platform, options: CommandOptions, command: CommandString, args: CommandString[], waitOnExit: boolean | string): IShellLaunchConfig | undefined {
private async getUserHome(): Promise<URI> {
const env = await this.remoteAgentService.getEnvironment();
if (env) {
return env.userHome;
}
return URI.from({ scheme: Schemas.file, path: this.environmentService.userHome });
}

private async createShellLaunchConfig(task: CustomTask | ContributedTask, variableResolver: VariableResolver, platform: Platform.Platform, options: CommandOptions, command: CommandString, args: CommandString[], waitOnExit: boolean | string): Promise<IShellLaunchConfig | undefined> {
let shellLaunchConfig: IShellLaunchConfig;
let isShellCommand = task.command.runtime === RuntimeType.Shell;
let needsFolderQualification = this.currentTask.workspaceFolder && this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE;
Expand Down Expand Up @@ -799,7 +819,9 @@ export class TerminalTaskSystem implements ITaskSystem {
if (platform === Platform.Platform.Windows) {
windowsShellArgs = true;
let basename = path.basename(shellLaunchConfig.executable!).toLowerCase();
if (basename === 'cmd.exe' && ((options.cwd && isUNC(options.cwd)) || (!options.cwd && isUNC(process.cwd())))) {
// If we don't have a cwd, then the terminal uses the home dir.
const userHome = await this.getUserHome();
if (basename === 'cmd.exe' && ((options.cwd && isUNC(options.cwd)) || (!options.cwd && isUNC(userHome.fsPath)))) {
return undefined;
}
if ((basename === 'powershell.exe') || (basename === 'pwsh.exe')) {
Expand Down Expand Up @@ -894,7 +916,7 @@ export class TerminalTaskSystem implements ITaskSystem {
return shellLaunchConfig;
}

private createTerminal(task: CustomTask | ContributedTask, resolver: VariableResolver): [ITerminalInstance | undefined, string | undefined, TaskError | undefined] {
private async createTerminal(task: CustomTask | ContributedTask, resolver: VariableResolver): Promise<[ITerminalInstance | undefined, string | undefined, TaskError | undefined]> {
let platform = resolver.taskSystemInfo ? resolver.taskSystemInfo.platform : Platform.platform;
let options = this.resolveOptions(resolver, task.command.options);

Expand Down Expand Up @@ -931,7 +953,7 @@ export class TerminalTaskSystem implements ITaskSystem {
args = resolvedResult.args;
commandExecutable = CommandString.value(command);

this.currentTask.shellLaunchConfig = this.isRerun ? this.lastTask.getVerifiedTask().shellLaunchConfig : this.createShellLaunchConfig(task, resolver, platform, options, command, args, waitOnExit);
this.currentTask.shellLaunchConfig = this.isRerun ? this.lastTask.getVerifiedTask().shellLaunchConfig : await this.createShellLaunchConfig(task, resolver, platform, options, command, args, waitOnExit);
if (this.currentTask.shellLaunchConfig === undefined) {
return [undefined, undefined, new TaskError(Severity.Error, nls.localize('TerminalTaskSystem', 'Can\'t execute a shell command on an UNC drive using cmd.exe.'), TaskErrors.UnknownError)];
}
Expand Down Expand Up @@ -1022,7 +1044,7 @@ export class TerminalTaskSystem implements ITaskSystem {

private buildShellCommandLine(platform: Platform.Platform, shellExecutable: string, shellOptions: ShellConfiguration | undefined, command: CommandString, originalCommand: CommandString | undefined, args: CommandString[]): string {
let basename = path.parse(shellExecutable).name.toLowerCase();
let shellQuoteOptions = this.getQuotingOptions(basename, shellOptions);
let shellQuoteOptions = this.getQuotingOptions(basename, shellOptions, platform);

function needsQuotes(value: string): boolean {
if (value.length >= 2) {
Expand Down Expand Up @@ -1122,11 +1144,11 @@ export class TerminalTaskSystem implements ITaskSystem {
return commandLine;
}

private getQuotingOptions(shellBasename: string, shellOptions: ShellConfiguration | undefined): ShellQuotingOptions {
private getQuotingOptions(shellBasename: string, shellOptions: ShellConfiguration | undefined, platform: Platform.Platform): ShellQuotingOptions {
if (shellOptions && shellOptions.quoting) {
return shellOptions.quoting;
}
return TerminalTaskSystem.shellQuotes[shellBasename] || TerminalTaskSystem.osShellQuotes[process.platform];
return TerminalTaskSystem.shellQuotes[shellBasename] || TerminalTaskSystem.osShellQuotes[platform];
}

private collectTaskVariables(variables: Set<string>, task: CustomTask | ContributedTask): void {
Expand Down

0 comments on commit 416f8ac

Please sign in to comment.