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

[VSC-1537] use IDF_TARGET in customExtraVars if no sdkconfig #1385

Merged
merged 2 commits into from
Jan 6, 2025
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,9 @@ We have implemented some utilities commands that can be used in `tasks.json` and
- `espIdf.getOpenOcdScriptValue`: Return the value of OPENOCD_SCRIPTS computed from ESP-IDF Tools path, `idf.customExtraVars`, or the system's OPENOCD_SCRIPTS environment variable.
- `espIdf.getOpenOcdConfig`: Return the openOCD configuration files as string. Example `-f interface/ftdi/esp32_devkitj_v1.cfg -f board/esp32-wrover.cfg`.
- `espIdf.getProjectName`: Return the project name from current workspace folder `build/project_description.json`.
- `espIdf.getToolchainGcc`: Return the absolute path of the toolchain GCC for the ESP-IDF target given by current IDF_TARGET in sdkconfig.
- `espIdf.getToolchainGdb`: Return the absolute path of the toolchain gdb for the ESP-IDF target given by current IDF_TARGET in sdkconfig.
- `espIdf.getToolchainGcc`: Return the absolute path of the toolchain GCC for the ESP-IDF target given by current IDF_TARGET in sdkconfig or `idf.customExtraVars`["IDF_TARGET"] configuration setting.
- `espIdf.getToolchainGdb`: Return the absolute path of the toolchain gdb for the ESP-IDF target given by current IDF_TARGET in sdkconfig or `idf.customExtraVars`["IDF_TARGET"] configuration setting.
- `espIdf.getIDFTarget`: Return the current IDF_TARGET from sdkconfig or `idf.customExtraVars`["IDF_TARGET"] configuration setting.

See an example in the [debugging](https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/debugproject.html) documentation.

Expand Down
5 changes: 3 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,9 @@ ESP-IDF 扩展在 VS Code 底部蓝色窗口的状态栏中提供了一系列命
- `espIdf.getOpenOcdScriptValue`:返回从 ESP-IDF 工具路径、`idf.customExtraVars` 或系统 OPENOCD_SCRIPTS 环境变量中计算出的 OPENOCD_SCRIPTS 的值。
- `espIdf.getOpenOcdConfig`:以字符串形式返回 openOCD 配置文件。例如 `-f interface/ftdi/esp32_devkitj_v1.cfg -f board/esp32-wrover.cfg`。
- `espIdf.getProjectName`:从当前工作区文件夹的 `build/project_description.json` 文件中提取项目名称。
- `espIdf.getToolchainGcc`:根据 sdkconfig 文件中指定的 IDF_TARGET,该命令将返回相应 GCC 工具链的绝对路径。
- `espIdf.getToolchainGdb`:根据 sdkconfig 文件中指定的 IDF_TARGET,该命令将返回相应 GDB 工具链的绝对路径。
- `espIdf.getToolchainGcc`:根据 sdkconfig 或 `idf.customExtraVars`[“IDF_TARGET”] 文件中指定的 IDF_TARGET,该命令将返回相应 GCC 工具链的绝对路径。
- `espIdf.getToolchainGdb`:根据 sdkconfig 或 `idf.customExtraVars`[“IDF_TARGET”] 文件中指定的 IDF_TARGET,该命令将返回相应 GDB 工具链的绝对路径。
- `espIdf.getIDFTarget`: 根据 sdkconfig 或 `idf.customExtraVars`[“IDF_TARGET”] 该命令将返回相应 IDF_TARGET。

在[调试](https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/debugproject.html)文档中查看示例。

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"onCommand:espIdf.apptrace.archive.showReport",
"onCommand:espIdf.apptrace.customize",
"onCommand:espIdf.getExtensionPath",
"onCommand:espIdf.getIDFTarget",
"onCommand:espIdf.getOpenOcdConfigs",
"onCommand:espIdf.genCoverage",
"onCommand:espIdf.partition.table.refresh",
Expand Down
11 changes: 11 additions & 0 deletions src/espIdf/setTarget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ export async function setIdfTarget(
if (!selectedTarget) {
return;
}
const customExtraVars = readParameter(
"idf.customExtraVars",
workspaceFolder
) as { [key: string]: string };
customExtraVars["IDF_TARGET"] = selectedTarget.target;
await writeParameter(
"idf.customExtraVars",
customExtraVars,
configurationTarget,
workspaceFolder.uri
);
const openOcdScriptsPath = await getOpenOcdScripts(workspaceFolder.uri);
const boards = await getBoards(
openOcdScriptsPath,
Expand Down
7 changes: 7 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(sdkWatchDisposable);
const sdkDeleteWatchDisposable = sdkconfigWatcher.onDidDelete(async () => {
ConfserverProcess.dispose();
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
});
context.subscriptions.push(sdkDeleteWatchDisposable);

Expand Down Expand Up @@ -1234,6 +1235,8 @@ export async function activate(context: vscode.ExtensionContext) {
}
} else if (e.affectsConfiguration("idf.buildPath")) {
updateIdfComponentsTree(workspaceRoot);
} else if (e.affectsConfiguration("idf.customExtraVars")) {
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
}
});

Expand Down Expand Up @@ -2152,6 +2155,10 @@ export async function activate(context: vscode.ExtensionContext) {
return context.extensionPath;
});

registerIDFCommand("espIdf.getIDFTarget", async () => {
return await getIdfTargetFromSdkconfig(workspaceRoot);
});

registerIDFCommand("espIdf.getOpenOcdConfigs", () => {
const openOcfConfigs = idfConf.readParameter(
"idf.openOcdConfigs",
Expand Down
4 changes: 4 additions & 0 deletions src/idfConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ export function resolveVariables(
}
if (match.indexOf("env:") > 0) {
const envVariable = name.substring(name.indexOf("env:") + "env:".length);
const customExtraVars = readParameter("idf.customExtraVars", scope);
if (Object.keys(customExtraVars).indexOf(envVariable) !== -1) {
return customExtraVars[envVariable];
}
if (Object.keys(process.env).indexOf(envVariable) === -1) {
return "";
}
Expand Down
19 changes: 15 additions & 4 deletions src/workspaceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
// limitations under the License.

import * as fs from "fs";
import { pathExists } from "fs-extra";
import * as path from "path";
import * as vscode from "vscode";
import { IdfTreeDataProvider } from "./idfComponentsDataProvider";
import { Logger } from "./logger/logger";
import * as utils from "./utils";
import { getSDKConfigFilePath } from "./utils";
import { readParameter } from "./idfConfiguration";

export function initSelectedWorkspace(status?: vscode.StatusBarItem) {
const workspaceRoot = vscode.workspace.workspaceFolders[0].uri;
Expand Down Expand Up @@ -92,6 +91,13 @@ export async function getIdfTargetFromSdkconfig(
workspacePath
);
let idfTarget = configIdfTarget.replace(/\"/g, "");
if (!idfTarget) {
const customExtraVars = readParameter(
"idf.customExtraVars",
workspacePath
) as { [key: string]: string };
idfTarget = customExtraVars["IDF_TARGET"];
}
if (!idfTarget) {
idfTarget = "esp32";
}
Expand All @@ -100,9 +106,14 @@ export async function getIdfTargetFromSdkconfig(
}
return idfTarget;
} catch (error) {
const customExtraVars = readParameter(
"idf.customExtraVars",
workspacePath
) as { [key: string]: string };
let idfTarget = customExtraVars["IDF_TARGET"] || "esp32";
if (statusItem) {
statusItem.text = "$(chip) esp32";
statusItem.text = `$(chip) ${idfTarget}`;
}
return "esp32";
return idfTarget;
}
}
Loading