Skip to content

Commit

Permalink
Enhance/whitespaces2 (#1159)
Browse files Browse the repository at this point in the history
* 🐛 Replace ShellExcecution -> ProcessExecution

- Replaced Shell Executions task type with Process Executions
- Modified a bit the code for consistency in the project (replacing, workspace variable name to workspaceUri because there is a vscode.workspace an this two can be confused if we import "workspace" from "vscode" specifically.

* Update variable name

From workspace to workspaceUri

* Removing validations for whitespaces

TODO: UI changes to let user know it only work on version of esp-idf 5.0 and higher

* Change node.processChild.exec to .execFile

Revert "Change node.processChild.exec to .execFile"

This reverts commit b703c26.

Revert "Revert "Change node.processChild.exec to .execFile""

This reverts commit 84fcba5.

* 🐛 Fix activation, forgot empty variable

* Fix JTAG Flash for whitespaces

* Fix whitespaces for monitoring

Fix typo for espBom

🎨 Fix formatting

* Add UI Validation for whitespaces

* Update documentation

🎨 Fix formatting

* Reverting all UI changes

Use CMake Bin Path for building

* Fix conflict

* Reintroducing validation for tools path

* Fix getting user's shell

If user doesn't have default terminal set, we just use the default ones for each os

* Fix python paths for Mac

* Add UI Validation for Installation

* Add back documentation part

* Reintroduce margin

* Add validation for empty paths
  • Loading branch information
radurentea authored Jun 7, 2024
1 parent ee15bac commit 9096b39
Show file tree
Hide file tree
Showing 30 changed files with 596 additions and 397 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Install ESP-IDF and ESP-IDF Tools by following the [install tutorial](./docs/tut

> **NOTE:** Please take a look at [Working with multiple projects](./docs/MULTI_PROJECTS.md) for more information. Default is User settings.
- On the first time using the extension, press <kbd>F1</kbd> to show the Visual Studio Code Command Palette and type **ESP-IDF: Configure ESP-IDF Extension** to open the extension configuration wizard. This will install ESP-IDF, ESP-IDF tools, create a virtual python environment with ESP-IDF and this extension python packages and configure the extension settings with these values. **NOTE: Make sure that there is no spaces in any configured path since [ESP-IDF build system doesn't support spaces yet.](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html#start-a-project)**.
- On the first time using the extension, press <kbd>F1</kbd> to show the Visual Studio Code Command Palette and type **ESP-IDF: Configure ESP-IDF extension** to open the extension configuration wizard. This will install ESP-IDF, ESP-IDF tools, create a virtual python environment with ESP-IDF and this extension python packages and configure the extension settings with these values.
> **NOTE:** For versions of ESP-IDF < 5.0, spaces are not supported inside configured paths.
> **NOTE:** Please take a look at [Install tutorial](./docs/tutorial/install.md) documentation or the [Setup documentation](./docs/SETUP.md) for details about extension setup and configuration.
Expand Down
4 changes: 1 addition & 3 deletions docs/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ so make sure that if using an existing python virtual environment that installin

> **NOTE:** Currently the python package `pygdbmi` used by the debug adapter still depends on some Python 2.7 libraries (libpython2.7.so.1.0) so make sure that the Python executable in `idf.pythonBinPath` you use contains these libraries. This will be dropped in later versions of ESP-IDF.
> **NOTE:** Make sure that `IDF_PATH` and `IDF_TOOLS_PATH` doesn't have any spaces to avoid any build issues since [ESP-IDF Build System does NOT support spaces yet.](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html#start-a-project).
> **NOTE**: If you want to use an ESP-IDF version < 5.0, make sure that IDF_PATH and IDF_TOOLS_PATH don't have any spaces since they were no suported in previous versions.
After choosing any of the previous options, a status page is displayed showing ESP-IDF, tools and python environment setup progress status. When the setup is finished, a message is shown that "All settings have been configured. You can close this window."

Expand Down Expand Up @@ -114,8 +114,6 @@ where:

**DO NOT USE ~, $HOME OR %USERPROFILE% ENVIRONMENT VARIABLES ARE NOT RESOLVED IN THIS CONFIGURATION SETTINGS. You must use ${env:HOME} instead of \$HOME (Linux/MacOS) or %HOME% (Windows).**

> **NOTE:** Make sure that your configurations settings doesn't have any spaces to avoid any build issues.
Make sure to install the extension and extension debug adapter Python requirements by running the following commands in your terminal:

```
Expand Down
6 changes: 2 additions & 4 deletions docs/tutorial/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
- Pick an ESP-IDF version to download (or find ESP-IDF in your system) and the python executable to create the virtual environment.
- Choose the location for ESP-IDF Tools and python virtual environment (also known as `IDF_TOOLS_PATH`) which is `$HOME\.espressif` on MacOS/Linux and `%USERPROFILE%\.espressif` on Windows by default.
> **NOTE:** Windows users don't need to select a python executable since it is part of the setup.
> **NOTE:** Make sure that `IDF_PATH` and `IDF_TOOLS_PATH` doesn't have any spaces to avoid any build issues.
> **NOTE:** Make sure that `IDF_TOOLS_PATH` doesn't have any spaces to avoid any build issues.
<p>
<img src="../../media/tutorials/setup/select-esp-idf.png" alt="Select ESP-IDF" width="950">
</p>
Expand Down Expand Up @@ -60,7 +58,7 @@
<img src="../../media/tutorials/setup/install-complete.png" alt="Install complete">
</p>

> **NOTE**: The advance mode allows the user to choose to use existing ESP-IDF tools by manually entering each ESP-IDF tool absolute path. Make sure each ESP-IDF tool path doesn't have any spaces.
> **NOTE**: > The advance mode allows the user to choose to use existing ESP-IDF tools by manually entering each ESP-IDF tool absolute path. Again, if chose an ESP-IDF version < 5.0, make sure each ESP-IDF tool path doesn't have any spaces, since they were no suported in previous versions..
15. Now that the extension setup is finally done, check the [Basic use](./basic_use.md) to learn how to use the SDK Configuration editor, build, flash and monitor your Espressif device.

Expand Down
11 changes: 6 additions & 5 deletions src/PlatformInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ export class PlatformInformation {
}

public static GetUnixArchitecture(): Promise<string> {
const command = "uname";
const args = ["-m"];
return utils
.execChildProcess("uname -m", utils.extensionContext.extensionPath)
.execChildProcess(command, args, utils.extensionContext.extensionPath)
.then((architecture) => {
if (architecture) {
return architecture.trim();
Expand All @@ -90,11 +92,10 @@ export class PlatformInformation {
}

private static GetWindowsArchitecture(): Promise<string> {
const command = "wmic";
const args = ["os", "get", "osarchitecture"];
return utils
.execChildProcess(
"wmic os get osarchitecture",
utils.extensionContext.extensionPath
)
.execChildProcess(command, args, utils.extensionContext.extensionPath)
.then((architecture) => {
if (architecture) {
const archArray: string[] = architecture.split(os.EOL);
Expand Down
152 changes: 51 additions & 101 deletions src/build/buildTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,35 @@ import { selectedDFUAdapterId } from "../flash/dfu";
export class BuildTask {
public static isBuilding: boolean;
private buildDirPath: string;
private curWorkspace: vscode.Uri;
private currentWorkspace: vscode.Uri;
private idfPathDir: string;
private adapterTargetName: string;
private processOptions: vscode.ProcessExecutionOptions;
private modifiedEnv: { [key: string]: string };
private pythonBinPath: string;

constructor(workspace: vscode.Uri) {
this.curWorkspace = workspace;
constructor(workspaceUri: vscode.Uri) {
this.currentWorkspace = workspaceUri;
this.idfPathDir = idfConf.readParameter(
"idf.espIdfPath",
workspace
workspaceUri
) as string;
this.adapterTargetName = idfConf.readParameter(
"idf.adapterTargetName",
workspace
workspaceUri
) as string;
this.buildDirPath = idfConf.readParameter(
"idf.buildPath",
workspace
workspaceUri
) as string;
this.modifiedEnv = appendIdfAndToolsToPath(workspaceUri);
this.processOptions = {
cwd: this.buildDirPath,
env: this.modifiedEnv,
};
this.pythonBinPath = idfConf.readParameter(
"idf.pythonBinPath",
workspaceUri
) as string;
}

Expand All @@ -55,45 +67,13 @@ export class BuildTask {
private async saveBeforeBuild() {
const shallSaveBeforeBuild = idfConf.readParameter(
"idf.saveBeforeBuild",
this.curWorkspace
this.currentWorkspace
);
if (shallSaveBeforeBuild) {
await vscode.workspace.saveAll();
}
}

public getShellExecution(
args: string[],
options?: vscode.ShellExecutionOptions
) {
return new vscode.ShellExecution(`cmake ${args.join(" ")}`, options);
}

public getNinjaShellExecution(
args: string[],
options?: vscode.ShellExecutionOptions
) {
return new vscode.ShellExecution(`ninja ${args.join(" ")}`, options);
}

public dfuShellExecution(options?: vscode.ShellExecutionOptions) {
const pythonBinPath = idfConf.readParameter(
"idf.pythonBinPath",
this.curWorkspace
) as string;
return new vscode.ShellExecution(
`${pythonBinPath} ${join(
this.idfPathDir,
"tools",
"mkdfu.py"
)} write -o ${join(this.buildDirPath, "dfu.bin")} --json ${join(
this.buildDirPath,
"flasher_args.json"
)} --pid ${selectedDFUAdapterId(this.adapterTargetName)}`,
options
);
}

public async build() {
try {
await this.saveBeforeBuild();
Expand All @@ -107,17 +87,16 @@ export class BuildTask {
throw new Error("ALREADY_BUILDING");
}
this.building(true);
const modifiedEnv = appendIdfAndToolsToPath(this.curWorkspace);
await ensureDir(this.buildDirPath);
const canAccessCMake = await isBinInPath(
"cmake",
this.curWorkspace.fsPath,
modifiedEnv
this.currentWorkspace.fsPath,
this.modifiedEnv
);
const canAccessNinja = await isBinInPath(
"ninja",
this.curWorkspace.fsPath,
modifiedEnv
this.currentWorkspace.fsPath,
this.modifiedEnv
);

const cmakeCachePath = join(this.buildDirPath, "CMakeCache.txt");
Expand All @@ -127,33 +106,13 @@ export class BuildTask {
throw new Error("CMake or Ninja executables not found");
}

const options: vscode.ShellExecutionOptions = {
cwd: this.buildDirPath,
env: modifiedEnv,
};
const shellExecutablePath = idfConf.readParameter(
"idf.customTerminalExecutable",
this.curWorkspace
) as string;
const shellExecutableArgs = idfConf.readParameter(
"idf.customTerminalExecutableArgs",
this.curWorkspace
) as string[];
if (shellExecutablePath) {
options.executable = shellExecutablePath;
}

if (shellExecutableArgs && shellExecutableArgs.length) {
options.shellArgs = shellExecutableArgs;
}

const curWorkspaceFolder = vscode.workspace.workspaceFolders.find(
(w) => w.uri === this.curWorkspace
const currentWorkspaceFolder = vscode.workspace.workspaceFolders.find(
(w) => w.uri === this.currentWorkspace
);

const notificationMode = idfConf.readParameter(
"idf.notificationMode",
this.curWorkspace
this.currentWorkspace
) as string;
const showTaskOutput =
notificationMode === idfConf.NotificationMode.All ||
Expand All @@ -164,7 +123,7 @@ export class BuildTask {
if (!cmakeCacheExists) {
let compilerArgs = (idfConf.readParameter(
"idf.cmakeCompilerArgs",
this.curWorkspace
this.currentWorkspace
) as Array<string>) || [
"-G",
"Ninja",
Expand All @@ -178,7 +137,7 @@ export class BuildTask {
compilerArgs.push("-B", this.buildDirPath);

if (compilerArgs.indexOf("-S") === -1) {
compilerArgs.push("-S", this.curWorkspace.fsPath);
compilerArgs.push("-S", this.currentWorkspace.fsPath);
}

const sdkconfigDefaults =
Expand All @@ -196,15 +155,15 @@ export class BuildTask {

const enableCCache = idfConf.readParameter(
"idf.enableCCache",
this.curWorkspace
this.currentWorkspace
) as boolean;
if (enableCCache && compilerArgs && compilerArgs.length) {
const indexOfCCache = compilerArgs.indexOf("-DCCACHE_ENABLE=1");
if (indexOfCCache === -1) {
compilerArgs.push("-DCCACHE_ENABLE=1");
}
}
const compileExecution = this.getShellExecution(compilerArgs, options);
const compileExecution = new vscode.ProcessExecution(canAccessCMake, compilerArgs, this.processOptions);
const compilePresentationOptions = {
reveal: showTaskOutput,
showReuseMessage: false,
Expand All @@ -217,7 +176,7 @@ export class BuildTask {
command: "ESP-IDF Compile",
taskId: "idf-compile-task",
},
curWorkspaceFolder || vscode.TaskScope.Workspace,
currentWorkspaceFolder || vscode.TaskScope.Workspace,
"ESP-IDF Compile",
compileExecution,
["espIdf"],
Expand All @@ -227,10 +186,11 @@ export class BuildTask {
}

const buildArgs =
(idfConf.readParameter("idf.ninjaArgs", this.curWorkspace) as Array<
(idfConf.readParameter("idf.ninjaArgs", this.currentWorkspace) as Array<
string
>) || [];
const buildExecution = this.getNinjaShellExecution(buildArgs, options);
const ninjaCommand = "ninja";
const buildExecution = new vscode.ProcessExecution(ninjaCommand, buildArgs, this.processOptions);
const buildPresentationOptions = {
reveal: showTaskOutput,
showReuseMessage: false,
Expand All @@ -239,7 +199,7 @@ export class BuildTask {
} as vscode.TaskPresentationOptions;
TaskManager.addTask(
{ type: "esp-idf", command: "ESP-IDF Build", taskId: "idf-build-task" },
curWorkspaceFolder || vscode.TaskScope.Workspace,
currentWorkspaceFolder || vscode.TaskScope.Workspace,
"ESP-IDF Build",
buildExecution,
["espIdf"],
Expand All @@ -249,44 +209,34 @@ export class BuildTask {

public async buildDfu() {
this.building(true);
const modifiedEnv = appendIdfAndToolsToPath(this.curWorkspace);
const modifiedEnv = appendIdfAndToolsToPath(this.currentWorkspace);
await ensureDir(this.buildDirPath);

const options: vscode.ShellExecutionOptions = {
cwd: this.curWorkspace.fsPath,
env: modifiedEnv,
};

const shellExecutablePath = idfConf.readParameter(
"idf.customTerminalExecutable",
this.curWorkspace
) as string;
const shellExecutableArgs = idfConf.readParameter(
"idf.customTerminalExecutableArgs",
this.curWorkspace
) as string[];
if (shellExecutablePath) {
options.executable = shellExecutablePath;
}
if (shellExecutableArgs && shellExecutableArgs.length) {
options.shellArgs = shellExecutableArgs;
}

const curWorkspaceFolder = vscode.workspace.workspaceFolders.find(
(w) => w.uri === this.curWorkspace
const currentWorkspaceFolder = vscode.workspace.workspaceFolders.find(
(w) => w.uri === this.currentWorkspace
);

const notificationMode = idfConf.readParameter(
"idf.notificationMode",
this.curWorkspace
this.currentWorkspace
) as string;
const showTaskOutput =
notificationMode === idfConf.NotificationMode.All ||
notificationMode === idfConf.NotificationMode.Output
? vscode.TaskRevealKind.Always
: vscode.TaskRevealKind.Silent;

const writeExecution = this.dfuShellExecution(options);
const args = [
join(this.idfPathDir, "tools", "mkdfu.py"),
"write",
"-o",
join(this.buildDirPath, "dfu.bin"),
"--json",
join(this.buildDirPath, "flasher_args.json"),
"--pid",
selectedDFUAdapterId(this.adapterTargetName)
];
const writeExecution = new vscode.ProcessExecution(this.pythonBinPath, args, this.processOptions);
const buildPresentationOptions = {
reveal: showTaskOutput,
showReuseMessage: false,
Expand All @@ -299,7 +249,7 @@ export class BuildTask {
command: "ESP-IDF Write DFU.bin",
taskId: "idf-write-dfu-task",
},
curWorkspaceFolder || vscode.TaskScope.Workspace,
currentWorkspaceFolder || vscode.TaskScope.Workspace,
"ESP-IDF Write DFU.bin",
writeExecution,
["espIdf"],
Expand Down
9 changes: 6 additions & 3 deletions src/common/abstractCloning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,14 @@ export class AbstractCloning {
"esp-components",
];
await execChildProcess(
`${this.gitBinPath} submodule init`,
this.gitBinPath,
["submodule", "init"],
repoPath,
OutputChannel.init()
);
const gitModules = await execChildProcess(
`${this.gitBinPath} config -f .gitmodules --list`,
this.gitBinPath,
["config", "-f", ".gitmodules", "--list"],
repoPath,
OutputChannel.init()
);
Expand Down Expand Up @@ -297,7 +299,8 @@ export class AbstractCloning {
}

await execChildProcess(
`${this.gitBinPath} config submodule.${subPath}.url ${subUrl}`,
this.gitBinPath,
["config", `submodule.${subPath}.url`, subUrl],
repoPath,
OutputChannel.init()
);
Expand Down
Loading

0 comments on commit 9096b39

Please sign in to comment.