Skip to content

Commit d2ae042

Browse files
[VSC-1537] use IDF_TARGET in customExtraVars if no sdkconfig (#1385)
* use IDF_TARGET in customExtraVars if no sdkconfig * add idf customExtraVars to readParameter variable resolution
1 parent f911c83 commit d2ae042

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,9 @@ We have implemented some utilities commands that can be used in `tasks.json` and
555555
- `espIdf.getOpenOcdScriptValue`: Return the value of OPENOCD_SCRIPTS computed from ESP-IDF Tools path, `idf.customExtraVars`, or the system's OPENOCD_SCRIPTS environment variable.
556556
- `espIdf.getOpenOcdConfig`: Return the openOCD configuration files as string. Example `-f interface/ftdi/esp32_devkitj_v1.cfg -f board/esp32-wrover.cfg`.
557557
- `espIdf.getProjectName`: Return the project name from current workspace folder `build/project_description.json`.
558-
- `espIdf.getToolchainGcc`: Return the absolute path of the toolchain GCC for the ESP-IDF target given by current IDF_TARGET in sdkconfig.
559-
- `espIdf.getToolchainGdb`: Return the absolute path of the toolchain gdb for the ESP-IDF target given by current IDF_TARGET in sdkconfig.
558+
- `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.
559+
- `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.
560+
- `espIdf.getIDFTarget`: Return the current IDF_TARGET from sdkconfig or `idf.customExtraVars`["IDF_TARGET"] configuration setting.
560561

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

README_CN.md

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

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

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"onCommand:espIdf.apptrace.archive.showReport",
8080
"onCommand:espIdf.apptrace.customize",
8181
"onCommand:espIdf.getExtensionPath",
82+
"onCommand:espIdf.getIDFTarget",
8283
"onCommand:espIdf.getOpenOcdConfigs",
8384
"onCommand:espIdf.genCoverage",
8485
"onCommand:espIdf.partition.table.refresh",

src/espIdf/setTarget/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ export async function setIdfTarget(
6666
if (!selectedTarget) {
6767
return;
6868
}
69+
const customExtraVars = readParameter(
70+
"idf.customExtraVars",
71+
workspaceFolder
72+
) as { [key: string]: string };
73+
customExtraVars["IDF_TARGET"] = selectedTarget.target;
74+
await writeParameter(
75+
"idf.customExtraVars",
76+
customExtraVars,
77+
configurationTarget,
78+
workspaceFolder.uri
79+
);
6980
const openOcdScriptsPath = await getOpenOcdScripts(workspaceFolder.uri);
7081
const boards = await getBoards(
7182
openOcdScriptsPath,

src/extension.ts

+7
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ export async function activate(context: vscode.ExtensionContext) {
508508
context.subscriptions.push(sdkWatchDisposable);
509509
const sdkDeleteWatchDisposable = sdkconfigWatcher.onDidDelete(async () => {
510510
ConfserverProcess.dispose();
511+
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
511512
});
512513
context.subscriptions.push(sdkDeleteWatchDisposable);
513514

@@ -1234,6 +1235,8 @@ export async function activate(context: vscode.ExtensionContext) {
12341235
}
12351236
} else if (e.affectsConfiguration("idf.buildPath")) {
12361237
updateIdfComponentsTree(workspaceRoot);
1238+
} else if (e.affectsConfiguration("idf.customExtraVars")) {
1239+
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
12371240
}
12381241
});
12391242

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

2158+
registerIDFCommand("espIdf.getIDFTarget", async () => {
2159+
return await getIdfTargetFromSdkconfig(workspaceRoot);
2160+
});
2161+
21552162
registerIDFCommand("espIdf.getOpenOcdConfigs", () => {
21562163
const openOcfConfigs = idfConf.readParameter(
21572164
"idf.openOcdConfigs",

src/idfConfiguration.ts

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ export function resolveVariables(
259259
}
260260
if (match.indexOf("env:") > 0) {
261261
const envVariable = name.substring(name.indexOf("env:") + "env:".length);
262+
const customExtraVars = readParameter("idf.customExtraVars", scope);
263+
if (Object.keys(customExtraVars).indexOf(envVariable) !== -1) {
264+
return customExtraVars[envVariable];
265+
}
262266
if (Object.keys(process.env).indexOf(envVariable) === -1) {
263267
return "";
264268
}

src/workspaceConfig.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
// limitations under the License.
1414

1515
import * as fs from "fs";
16-
import { pathExists } from "fs-extra";
1716
import * as path from "path";
1817
import * as vscode from "vscode";
1918
import { IdfTreeDataProvider } from "./idfComponentsDataProvider";
2019
import { Logger } from "./logger/logger";
2120
import * as utils from "./utils";
22-
import { getSDKConfigFilePath } from "./utils";
21+
import { readParameter } from "./idfConfiguration";
2322

2423
export function initSelectedWorkspace(status?: vscode.StatusBarItem) {
2524
const workspaceRoot = vscode.workspace.workspaceFolders[0].uri;
@@ -92,6 +91,13 @@ export async function getIdfTargetFromSdkconfig(
9291
workspacePath
9392
);
9493
let idfTarget = configIdfTarget.replace(/\"/g, "");
94+
if (!idfTarget) {
95+
const customExtraVars = readParameter(
96+
"idf.customExtraVars",
97+
workspacePath
98+
) as { [key: string]: string };
99+
idfTarget = customExtraVars["IDF_TARGET"];
100+
}
95101
if (!idfTarget) {
96102
idfTarget = "esp32";
97103
}
@@ -100,9 +106,14 @@ export async function getIdfTargetFromSdkconfig(
100106
}
101107
return idfTarget;
102108
} catch (error) {
109+
const customExtraVars = readParameter(
110+
"idf.customExtraVars",
111+
workspacePath
112+
) as { [key: string]: string };
113+
let idfTarget = customExtraVars["IDF_TARGET"] || "esp32";
103114
if (statusItem) {
104-
statusItem.text = "$(chip) esp32";
115+
statusItem.text = `$(chip) ${idfTarget}`;
105116
}
106-
return "esp32";
117+
return idfTarget;
107118
}
108119
}

0 commit comments

Comments
 (0)