Skip to content

Commit

Permalink
update wsl env detection (#578)
Browse files Browse the repository at this point in the history
* update wsl env detection

* add use of WSL_DISTRO_NAME in docs

* refacto is running in wsl to method

* fix lint utils

* rm use of port COM
  • Loading branch information
brianignacio5 authored Nov 26, 2021
1 parent f27dd56 commit 4320f31
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/WSL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Please review [Debugging using WSL](https://code.visualstudio.com/api/advanced-t
This extension was tested in Windows 10 Build 19041 with the Microsoft's Ubuntu 20.04 distribution for WSL 2.

Currently in WSL 2, there is no access to serial ports. Calling `powershell.exe` from distribution's shell we obtain serial ports and perform flash and monitor tasks.
Currently in WSL 2, there is no access to serial ports. Calling `powershell.exe` from distribution's shell we obtain serial ports and perform flash and monitor tasks when `WSL_DISTRO_NAME` environment variable is defined.

## WSL 2 extension setup

Expand Down
10 changes: 2 additions & 8 deletions src/espIdf/monitor/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,15 @@ export async function createMonitorTerminal(
});
}
monitorTerminal.show();
const osRelease = release();
const kernelMatch = osRelease.toLowerCase().match(/(.*)-(.*)-(.*)/);
let isWsl2Kernel: number = -1; // WSL 2 is implemented on Microsoft Linux Kernel >=4.19
if (kernelMatch && kernelMatch.length) {
isWsl2Kernel = utils.compareVersion(kernelMatch[1], "4.19");
}
let isWsl2Kernel = utils.isRunningInWsl();
const isPowerShellInPath = await utils.isBinInPath(
"powershell.exe",
workspace.fsPath,
modifiedEnv
);
if (
process.platform === "linux" &&
osRelease.toLowerCase().indexOf("microsoft") !== -1 &&
isWsl2Kernel !== -1 &&
isWsl2Kernel &&
isPowerShellInPath !== ""
) {
const wslRoot = utils.extensionContext.extensionPath.replace(/\//g, "\\");
Expand Down
11 changes: 3 additions & 8 deletions src/espIdf/serial/serialPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
compareVersion,
execChildProcess,
extensionContext,
isRunningInWsl,
spawn,
} from "../../utils";
import { SerialPortDetails } from "./serialPortDetails";
Expand Down Expand Up @@ -55,17 +56,11 @@ export class SerialPort {
);

try {
const osRelease = release();
const kernelMatch = osRelease.toLowerCase().match(/(.*)-(.*)-(.*)/);
let isWsl2Kernel: number = -1; // WSL 2 is implemented on Microsoft Linux Kernel >=4.19
if (kernelMatch && kernelMatch.length) {
isWsl2Kernel = compareVersion(kernelMatch[1], "4.19");
}
let isWsl2Kernel = isRunningInWsl();
let portList: SerialPortDetails[];
if (
process.platform === "linux" &&
osRelease.toLowerCase().indexOf("microsoft") !== -1 &&
isWsl2Kernel !== -1
isWsl2Kernel
) {
portList = await this.wslList();
} else {
Expand Down
15 changes: 3 additions & 12 deletions src/flash/flashTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
execChildProcess,
extensionContext,
isBinInPath,
isRunningInWsl,
} from "../utils";
import { TaskManager } from "../taskManager";

Expand Down Expand Up @@ -79,24 +80,14 @@ export class FlashTask {
const showTaskOutput = isSilentMode
? vscode.TaskRevealKind.Silent
: vscode.TaskRevealKind.Always;
const osRelease = release();
const kernelMatch = osRelease.toLowerCase().match(/(.*)-(.*)-(.*)/);
let isWsl2Kernel: number = -1; // WSL 2 is implemented on Microsoft Linux Kernel >=4.19
if (kernelMatch && kernelMatch.length) {
isWsl2Kernel = compareVersion(kernelMatch[1], "4.19");
}
let isWsl2Kernel = isRunningInWsl();
const powershellPath = await isBinInPath(
"powershell.exe",
this.buildDir,
process.env
);
let flashExecution: vscode.ShellExecution | vscode.ProcessExecution;
if (
process.platform === "linux" &&
osRelease.toLowerCase().indexOf("microsoft") !== -1 &&
isWsl2Kernel !== -1 &&
powershellPath !== ""
) {
if (process.platform === "linux" && isWsl2Kernel && powershellPath !== "") {
flashExecution = await this._wslFlashExecution();
} else {
flashExecution = this._flashExecution();
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,13 @@ export function getWebViewFavicon(extensionPath: string): vscode.Uri {
);
}

export function isRunningInWsl() {
return (
typeof process.env.WSL_DISTRO_NAME === "string" &&
process.env.WSL_DISTRO_NAME !== ""
);
}

export async function createNewComponent(
name: string,
currentDirectory: string
Expand Down

0 comments on commit 4320f31

Please sign in to comment.