Skip to content

Commit 0611a25

Browse files
committed
fix task cmd error and format code
1 parent f571ce4 commit 0611a25

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

src/CodeBuilder.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ import { ArrayDelRepetition } from "../lib/node-utility/Utility";
5050
import { DependenceManager } from "./DependenceManager";
5151
import { WorkspaceManager } from "./WorkspaceManager";
5252
import { ToolchainName } from "./ToolchainManager";
53-
import { md5, sha256, copyObject, generateDotnetProgramCmd, generateRandomStr, isGccFamilyToolchain } from "./utility";
53+
import {
54+
md5, sha256, copyObject, generateDotnetProgramCmd, generateRandomStr,
55+
isGccFamilyToolchain, compareVersion
56+
} from "./utility";
5457
import { exeSuffix, osType } from "./Platform";
5558
import { FileWatcher } from "../lib/node-utility/FileWatcher";
5659
import { STVPFlasherOptions } from './HexUploader';
@@ -300,12 +303,20 @@ export abstract class CodeBuilder {
300303
if (SettingManager.GetInstance().isUseTaskToBuild() &&
301304
WorkspaceManager.getInstance().hasWorkspaces()) { // use vscode task
302305
// setup shell
303-
const shellOption: vscode.ShellExecutionOptions = {};
304-
if (os.platform() == 'win32') { shellOption.executable = 'cmd.exe'; shellOption.shellArgs = ['/C']; }
305-
else { shellOption.executable = '/bin/bash'; shellOption.shellArgs = ['-c']; }
306-
shellOption.env = <any>process.env;
306+
const shellOption: vscode.ShellExecutionOptions = {
307+
env: <any>process.env
308+
};
309+
if (os.platform() == 'win32') {
310+
shellOption.executable = 'cmd.exe';
311+
shellOption.shellArgs = ['/D', '/C'];
312+
// FIXME: https://github.com/microsoft/vscode/issues/260534
313+
if (compareVersion(vscode.version, '1.103.0') < 0)
314+
commandLine = `"${commandLine}"`;
315+
} else {
316+
shellOption.executable = '/bin/bash';
317+
shellOption.shellArgs = ['-c'];
318+
}
307319
// setup task
308-
if (os.platform() == 'win32') commandLine = `"${commandLine}"`;
309320
const task = new vscode.Task({ type: 'shell', command: commandLine }, vscode.TaskScope.Workspace,
310321
title, 'eide.builder', new vscode.ShellExecution(commandLine, shellOption), []);
311322
task.group = vscode.TaskGroup.Build;
@@ -317,10 +328,12 @@ export abstract class CodeBuilder {
317328
}
318329
vscode.tasks.executeTask(task);
319330
} else { // use terminal
320-
const index = vscode.window.terminals.findIndex((t) => { return t.name === title; });
321-
if (index !== -1) { vscode.window.terminals[index].dispose(); }
331+
const index = vscode.window.terminals.findIndex(t => t.name === title);
332+
if (index !== -1)
333+
vscode.window.terminals[index].dispose();
322334
const opts: vscode.TerminalOptions = { name: title, iconPath: new vscode.ThemeIcon('target') };
323-
if (os.platform() == 'win32') { opts.shellPath = 'cmd.exe'; };
335+
if (os.platform() == 'win32')
336+
opts.shellPath = 'cmd.exe';
324337
opts.env = <any>process.env;
325338
const terminal = vscode.window.createTerminal(opts);
326339
if (!SettingManager.GetInstance().isSilentBuildOrFlash())

src/utility.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,15 @@ export async function runShellCommand(title: string, commandLine: string, opts?:
570570
};
571571
if (platform.osType() == 'win32') {
572572
shellOption.executable = 'cmd.exe';
573-
shellOption.shellArgs = ['/C'];
573+
shellOption.shellArgs = ['/D', '/C'];
574+
// FIXME: https://github.com/microsoft/vscode/issues/260534
575+
if (compareVersion(vscode.version, '1.103.0') < 0)
576+
commandLine = `"${commandLine}"`;
574577
} else {
575578
shellOption.executable = '/bin/bash';
576579
shellOption.shellArgs = ['-c'];
577580
}
578581
// init task
579-
if (platform.osType() == 'win32')
580-
commandLine = `"${commandLine}"`;
581582
const task = new vscode.Task({ type: 'shell', command: commandLine }, vscode.TaskScope.Global,
582583
title, opts?.source || 'eide', new vscode.ShellExecution(commandLine, shellOption), []);
583584
task.isBackground = false;

0 commit comments

Comments
 (0)