forked from microsoft/vscode-node-debug2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwslSupport.ts
More file actions
77 lines (68 loc) · 3.04 KB
/
Copy pathwslSupport.ts
File metadata and controls
77 lines (68 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as path from 'path';
import * as fs from 'fs';
import * as child_process from 'child_process';
const isWindows = process.platform === 'win32';
const is64bit = process.arch === 'x64';
export function subsystemForLinuxPresent(): boolean {
if (!isWindows) {
return false;
}
const bashPath32bitApp = path.join(process.env['SystemRoot'], 'Sysnative', 'bash.exe');
const bashPath64bitApp = path.join(process.env['SystemRoot'], 'System32', 'bash.exe');
const bashPathHost = is64bit ? bashPath64bitApp : bashPath32bitApp;
return fs.existsSync(bashPathHost);
}
function windowsPathToWSLPath(windowsPath: string): string {
if (!isWindows || !windowsPath) {
return undefined;
} else if (path.isAbsolute(windowsPath)) {
return `/mnt/${windowsPath.substr(0, 1).toLowerCase()}/${windowsPath.substr(3).replace(/\\/g, '/')}`;
} else {
return windowsPath.replace(/\\/g, '/');
}
}
export interface ILaunchArgs {
cwd: string;
executable: string;
args: string[];
combined: string[];
localRoot?: string;
remoteRoot?: string;
}
export function createLaunchArg(useSubsytemLinux: boolean | undefined, useExternalConsole: boolean, cwd: string | undefined, executable: string, args?: string[], program?: string): ILaunchArgs {
if (useSubsytemLinux && subsystemForLinuxPresent()) {
const bashPath32bitApp = path.join(process.env['SystemRoot'], 'Sysnative', 'bash.exe');
const bashPath64bitApp = path.join(process.env['SystemRoot'], 'System32', 'bash.exe');
const bashPathHost = is64bit ? bashPath64bitApp : bashPath32bitApp;
const subsystemLinuxPath = useExternalConsole ? bashPath64bitApp : bashPathHost;
const bashCommand = [executable].concat(args || []).map(element => {
if (element === program) { // workaround for issue #35249
element = element.replace(/\\/g, '/');
}
return element.indexOf(' ') > 0 ? `'${element}'` : element;
}).join(' ');
return <ILaunchArgs>{
cwd,
executable: subsystemLinuxPath,
args: ['-ic', bashCommand],
combined: [subsystemLinuxPath].concat(['-ic', bashCommand]),
localRoot: cwd,
remoteRoot: windowsPathToWSLPath(cwd)
};
} else {
return <ILaunchArgs>{
cwd: cwd,
executable: executable,
args: args || [],
combined: [executable].concat(args || [])
};
}
}
export function spawn(useWSL: boolean, executable: string, args?: string[], options?: child_process.SpawnOptions) {
const launchArgs = createLaunchArg(useWSL, false, undefined, executable, args);
return child_process.spawn(launchArgs.executable, launchArgs.args, options);
}
export function spawnSync(useWSL: boolean, executable: string, args?: string[], options?: child_process.SpawnSyncOptions) {
const launchArgs = createLaunchArg(useWSL, false, undefined, executable, args);
return child_process.spawnSync(launchArgs.executable, launchArgs.args, options);
}