Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use workspace folder as readParameter scope #641

Merged
merged 7 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions docs/SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This extension contributes the following settings that can be later updated in s

> **NOTE:** Please consider that `~`, `%VARNAME%` and `$VARNAME` are not recognized when set on ANY of this extension configuration settings. You can instead set any environment variable in the path using a `${env:VARNAME}` such as `${env:HOME}` or you can refer to other configuration parameter path with `${config:SETTINGID}` such as `${config:idf.espIdfPath}`.

The `idf.saveScope` allows the user to specify where to save settings when using commands such as `Configure Paths`, `Device configuration`, `Set Espressif device target` and other commands. Possible values are Global (User Settings), Workspace and WorkspaceFolder. For more information please take a look at [Working with multiple projects](./MULTI_PROJECTS.md). Use the `Select where to save configuration settings` command to choose where to save settings when using this extension commands.

> **NOTE:** All settings can be applied to Global (User Settings), Workspace and WorkspaceFolder unless Scope is specified.

## ESP-IDF Specific Settings

These are the configuration settings that ESP-IDF extension contributes to your Visual Studio Code editor settings.
Expand Down Expand Up @@ -39,16 +43,18 @@ This is how the extension uses them:

These settings are specific to the ESP32 Chip/ Board

| Setting | Description |
| ------------------------------------------------ | ------------------------------------------------------------------- |
| `idf.adapterTargetName` | ESP-IDF target Chip (Example: esp32) |
| `idf.customAdapterTargetName` | Custom target name for ESP-IDF Debug Adapter |
| `idf.flashBaudRate` | Flash Baud rate |
| `idf.openOcdConfigs` | Configuration files for OpenOCD. Relative to OPENOCD_SCRIPTS folder |
| `idf.openOcdDebugLevel` | Set openOCD debug level (0-4) Default: 2 |
| `idf.port` | Path of selected device port |
| `idf.portWin` | Path of selected device port in Windows |
| `openocd.jtag.command.force_unix_path_separator` | Forced to use `/` as path sep. for Win32 based OS instead of `\\` |
| Setting | Description | Scope |
| ------------------------------------------------ | ------------------------------------------------------------------- | ------------------------- |
| `idf.adapterTargetName` | ESP-IDF target Chip (Example: esp32) | |
| `idf.customAdapterTargetName` | Custom target name for ESP-IDF Debug Adapter | |
| `idf.flashBaudRate` | Flash Baud rate | |
| `idf.openOcdConfigs` | Configuration files for OpenOCD. Relative to OPENOCD_SCRIPTS folder | |
| `idf.openOcdDebugLevel` | Set openOCD debug level (0-4) Default: 2 | |
| `idf.port` | Path of selected device port | |
| `idf.portWin` | Path of selected device port in Windows | |
| `openocd.jtag.command.force_unix_path_separator` | Forced to use `/` as path sep. for Win32 based OS instead of `\\` | User, Remote or Workspace |
| `idf.listDfuDevices` | List of DFU devices connected to USB | User, Remote or Workspace |
| `idf.selectedDfuDevicePath` | Selected DFU device connected to USB | User, Remote or Workspace |

This is how the extension uses them:

Expand Down Expand Up @@ -77,19 +83,18 @@ These settings are used to configure the [Code coverage](./COVERAGE.md) colors.

## Extension Behaviour Settings

| Setting ID | Description |
| -------------------------------------- | ---------------------------------------------------------------------- |
| `idf.enableUpdateSrcsToCMakeListsFile` | Enable update source files in CMakeLists.txt (default `true`) |
| `idf.flashType` | Preferred flash method. UART or JTAG |
| `idf.launchMonitorOnDebugSession` | Launch ESP-IDF Monitor along with ESP-IDF Debug session |
| `idf.notificationSilentMode` | Silent all notifications messages and show tasks output |
| `idf.showOnboardingOnInit` | Show ESP-IDF Configuration window on extension activation |
| `idf.saveScope` | Where to save extension settings |
| `idf.saveBeforeBuild` | Save all the edited files before building (default `true`) |
| `idf.useIDFKconfigStyle` | Enable style validation for Kconfig files |
| `idf.wslEnable` | Enable use of powershell executable for flash and monitor tasks in WSL |

The `idf.saveScope` allows the user to specify where to save settings when using commands such as `Configure Paths`, `Device configuration`, `Set Espressif device target` and other commands. Possible values are Global (User Settings), Workspace and WorkspaceFolder. For more information please take a look at [Working with multiple projects](./MULTI_PROJECTS.md). Use the `Select where to save configuration settings` command to choose where to save settings when using this extension commands.
| Setting ID | Description | Scope |
| -------------------------------------- | ---------------------------------------------------------------------- | ------------------------- |
| `idf.enableUpdateSrcsToCMakeListsFile` | Enable update source files in CMakeLists.txt (default `true`) | User, Remote or Workspace |
| `idf.flashType` | Preferred flash method. UART or JTAG | |
| `idf.launchMonitorOnDebugSession` | Launch ESP-IDF Monitor along with ESP-IDF Debug session | |
| `idf.notificationSilentMode` | Silent all notifications messages and show tasks output | User, Remote or Workspace |
| `idf.showOnboardingOnInit` | Show ESP-IDF Configuration window on extension activation | User, Remote or Workspace |
| `idf.saveScope` | Where to save extension settings | User, Remote or Workspace |
| `idf.saveBeforeBuild` | Save all the edited files before building (default `true`) | |
| `idf.useIDFKconfigStyle` | Enable style validation for Kconfig files | |
| `idf.telemetry` | Enable Telemetry | User, Remote or Workspace |
| `idf.wslEnable` | Enable use of powershell executable for flash and monitor tasks in WSL | |

## Custom tasks for build and flash tasks

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"mac": "cmd+i b"
},
{
"command": "espIdf.selectFlashMethodAndFlash",
"command": "espIdf.startFlashing",
"key": "ctrl+e f",
"mac": "cmd+i f"
},
Expand Down Expand Up @@ -499,7 +499,7 @@
"idf.showOnboardingOnInit": {
"type": "boolean",
"default": true,
"scope": "resource",
"scope": "window",
"description": "%param.showOnboardingOnInit%"
},
"trace.poll_period": {
Expand Down Expand Up @@ -541,7 +541,6 @@
"idf.notificationSilentMode": {
"type": "boolean",
"default": false,
"scope": "resource",
"description": "%param.notificationSilentMode%"
},
"idf.saveScope": {
Expand Down Expand Up @@ -637,7 +636,7 @@
},
"idf.listDfuDevices": {
"type": "array",
"default": "[]"
"default": []
},
"openocd.tcl.host": {
"type": "string",
Expand Down Expand Up @@ -682,7 +681,7 @@
"idf.enableUpdateSrcsToCMakeListsFile": {
"type": "boolean",
"description": "%param.enableUpdateSrcsToCMakeListsFile%",
"scope": "resource",
"scope": "window",
"default": true
},
"idf.qemuTcpPort": {
Expand Down Expand Up @@ -825,6 +824,10 @@
"command": "espIdf.flashDFU",
"title": "%espIdf.flashDFU.title%"
},
{
"command": "espIdf.startFlashing",
"title": "%espIdf.flashDevice.title%"
},
{
"command": "espIdf.monitorDevice",
"title": "%espIdf.monitorDevice.title%"
Expand Down
15 changes: 5 additions & 10 deletions src/build/buildCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export async function buildCommand(
buildType: string
) {
let continueFlag = true;
const buildTask = new BuildTask(workspace.fsPath);
const sizeTask = new IdfSizeTask(workspace.fsPath);
const customTask = new CustomTask(workspace.fsPath);
const buildTask = new BuildTask(workspace);
const sizeTask = new IdfSizeTask(workspace);
const customTask = new CustomTask(workspace);
if (BuildTask.isBuilding || FlashTask.isFlashing) {
const waitProcessIsFinishedMsg = locDic.localize(
"build.waitProcessIsFinishedMessage",
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function buildCommand(
"flasher_args.json file is missing from the build directory, can't proceed, please build properly!!"
);
}
const adapterTargetName = readParameter("idf.adapterTargetName");
const adapterTargetName = readParameter("idf.adapterTargetName", workspace);
if (adapterTargetName !== "esp32s2" && adapterTargetName !== "esp32s3") {
return Logger.warnNotify(
`The selected device target "${adapterTargetName}" is not compatible for DFU, as a result the DFU.bin was not created.`
Expand All @@ -80,12 +80,7 @@ export async function buildCommand(
await TaskManager.runTasks();
}
if (!cancelToken.isCancellationRequested) {
const projDescPath = join(
workspace.fsPath,
"build",
"project_description.json"
);
updateIdfComponentsTree(projDescPath);
updateIdfComponentsTree(workspace);
Logger.infoNotify("Build Successfully");
TaskManager.disposeListeners();
}
Expand Down
70 changes: 44 additions & 26 deletions src/build/buildTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@ import { join, dirname } from "path";
import { Logger } from "../logger/logger";
import * as vscode from "vscode";
import * as idfConf from "../idfConfiguration";
import {
appendIdfAndToolsToPath,
isBinInPath,
} from "../utils";
import { appendIdfAndToolsToPath, isBinInPath } from "../utils";
import { TaskManager } from "../taskManager";
import { selectedDFUAdapterId } from "../flash/dfu";

export class BuildTask {
public static isBuilding: boolean;
private curWorkspace: string;
private curWorkspace: vscode.Uri;
private idfPathDir: string;
private adapterTargetName: string;

constructor(workspace: string) {
this.curWorkspace = join(workspace, "build");
this.idfPathDir = idfConf.readParameter("idf.espIdfPath") as string;
constructor(workspace: vscode.Uri) {
this.curWorkspace = workspace;
this.idfPathDir = idfConf.readParameter(
"idf.espIdfPath",
workspace
) as string;
this.adapterTargetName = idfConf.readParameter(
"idf.adapterTargetName"
"idf.adapterTargetName",
workspace
) as string;
}

Expand All @@ -47,7 +48,10 @@ export class BuildTask {
}

private async saveBeforeBuild() {
const shallSaveBeforeBuild = idfConf.readParameter("idf.saveBeforeBuild");
const shallSaveBeforeBuild = idfConf.readParameter(
"idf.saveBeforeBuild",
this.curWorkspace
);
if (shallSaveBeforeBuild) {
await vscode.workspace.saveAll();
}
Expand All @@ -70,10 +74,10 @@ export class BuildTask {
public dfuShellExecution(options?: vscode.ShellExecutionOptions) {
return new vscode.ShellExecution(
`${join(this.idfPathDir, "tools", "mkdfu.py")} write -o ${join(
this.curWorkspace,
join(this.curWorkspace.fsPath, "build"),
"dfu.bin"
)} --json ${join(
this.curWorkspace,
join(this.curWorkspace.fsPath, "build"),
"flasher_args.json"
)} --pid ${selectedDFUAdapterId(this.adapterTargetName)}`,
options
Expand All @@ -93,48 +97,57 @@ export class BuildTask {
throw new Error("ALREADY_BUILDING");
}
this.building(true);
const modifiedEnv = appendIdfAndToolsToPath();
await ensureDir(this.curWorkspace);
const modifiedEnv = appendIdfAndToolsToPath(this.curWorkspace);
await ensureDir(join(this.curWorkspace.fsPath, "build"));
const canAccessCMake = await isBinInPath(
"cmake",
this.curWorkspace,
this.curWorkspace.fsPath,
modifiedEnv
);
const canAccessNinja = await isBinInPath(
"ninja",
this.curWorkspace,
this.curWorkspace.fsPath,
modifiedEnv
);

const cmakeCachePath = join(this.curWorkspace, "CMakeCache.txt");
const cmakeCachePath = join(
this.curWorkspace.fsPath,
"build",
"CMakeCache.txt"
);
const cmakeCacheExists = await pathExists(cmakeCachePath);

if (canAccessCMake === "" || canAccessNinja === "") {
throw new Error("CMake or Ninja executables not found");
}

const options: vscode.ShellExecutionOptions = {
cwd: this.curWorkspace,
cwd: join(this.curWorkspace.fsPath, "build"),
env: modifiedEnv,
};
const isSilentMode = idfConf.readParameter(
"idf.notificationSilentMode"
"idf.notificationSilentMode",
this.curWorkspace
) as boolean;
const showTaskOutput = isSilentMode
? vscode.TaskRevealKind.Always
: vscode.TaskRevealKind.Silent;

if (!cmakeCacheExists) {
const compilerArgs = (idfConf.readParameter(
"idf.cmakeCompilerArgs"
"idf.cmakeCompilerArgs",
this.curWorkspace
) as Array<string>) || [
"-G",
"Ninja",
"-DPYTHON_DEPS_CHECKED=1",
"-DESP_PLATFORM=1",
"..",
];
const enableCCache = idfConf.readParameter("idf.enableCCache") as boolean;
const enableCCache = idfConf.readParameter(
"idf.enableCCache",
this.curWorkspace
) as boolean;
if (enableCCache && compilerArgs && compilerArgs.length) {
const indexOfCCache = compilerArgs.indexOf("-DCCACHE_ENABLE=1");
if (indexOfCCache === -1) {
Expand All @@ -157,7 +170,9 @@ export class BuildTask {
}

const buildArgs =
(idfConf.readParameter("idf.ninjaArgs") as Array<string>) || [];
(idfConf.readParameter("idf.ninjaArgs", this.curWorkspace) as Array<
string
>) || [];
const buildExecution = this.getNinjaShellExecution(buildArgs, options);
TaskManager.addTask(
{ type: "esp-idf", command: "ESP-IDF Build", taskId: "idf-build-task" },
Expand All @@ -171,15 +186,18 @@ export class BuildTask {

public async buildDfu() {
this.building(true);
const modifiedEnv = appendIdfAndToolsToPath();
await ensureDir(this.curWorkspace);
const modifiedEnv = appendIdfAndToolsToPath(this.curWorkspace);
await ensureDir(join(this.curWorkspace.fsPath, "build"));

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

const isSilentMode = idfConf.readParameter("idf.notificationSilentMode");
const isSilentMode = idfConf.readParameter(
"idf.notificationSilentMode",
this.curWorkspace
);
const showTaskOutput = isSilentMode
? vscode.TaskRevealKind.Always
: vscode.TaskRevealKind.Silent;
Expand Down
13 changes: 10 additions & 3 deletions src/checkExtensionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import { OutputChannel } from "./logger/outputChannel";
import { installExtensionPyReqs } from "./pythonManager";
import { readParameter } from "./idfConfiguration";

export async function checkExtensionSettings(extensionPath: string) {
export async function checkExtensionSettings(
extensionPath: string,
workspace: vscode.Uri
) {
const showSetupWindow = readParameter("idf.showOnboardingOnInit") as boolean;
const isExtensionConfigured = await isCurrentInstallValid();
const isExtensionConfigured = await isCurrentInstallValid(workspace);
if (isExtensionConfigured) {
return;
}
Expand All @@ -43,7 +46,11 @@ export async function checkExtensionSettings(extensionPath: string) {
cancelToken: vscode.CancellationToken
) => {
try {
const setupArgs = await getSetupInitialValues(extensionPath, progress);
const setupArgs = await getSetupInitialValues(
extensionPath,
progress,
workspace
);
if (
setupArgs.espIdfPath &&
setupArgs.espToolsPath &&
Expand Down
Loading