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

Switch ESP-IDF versions #1173

Merged
merged 7 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions i18n/en/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"espIdf.efuse.clearResults.title": "Clear eFuse Summary",
"espIdf.jtag_flash.title": "Flash (with JTag)",
"espIdf.selectFlashMethodAndFlash.title": "Select Flash Method",
"espIdf.selectCurrentIdfVersion.title": "Select Current ESP-IDF Version",
"idf.flashType.description": "Device flash method, UART or JTag",
"openocd.tcl.host.description": "Host for openocd tcl connection",
"openocd.tcl.port.description": "Port for openocd tcl connection",
Expand Down
1 change: 1 addition & 0 deletions i18n/es/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"espIdf.efuse.clearResults.title": "Limpiar el resumen de eFuse",
"espIdf.jtag_flash.title": "Flash (con JTag)",
"espIdf.selectFlashMethodAndFlash.title": "Seleccione el método de programar",
"espIdf.selectCurrentIdfVersion.title": "Seleccione la versión ESP-IDF a usar",
"idf.flashType.description": "Método de flash del dispositivo, UART o JTag",
"openocd.tcl.host.description": "Anfitrión para conexión tcl openocd",
"openocd.tcl.port.description": "Puerto para conexión tcl openocd",
Expand Down
1 change: 1 addition & 0 deletions i18n/ru/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"espIdf.efuse.clearResults.title": "Очистить сводку eFuse",
"espIdf.jtag_flash.title": "Прошить (через JTag)",
"espIdf.selectFlashMethodAndFlash.title": "Выбрать метод прошивки",
"espIdf.selectCurrentIdfVersion.title": "Выберите текущую версию ESP-IDF",
"idf.flashType.description": "Метод прошивки устройства, UART или JTag",
"openocd.tcl.host.description": "Хост для подключения openocd tcl",
"openocd.tcl.port.description": "Порт для подключения openocd tcl",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"espIdf.efuse.clearResults.title": "清除 eFuse 摘要",
"espIdf.jtag_flash.title": "JTag 烧录",
"espIdf.selectFlashMethodAndFlash.title": "选择烧录方式烧录",
"espIdf.selectCurrentIdfVersion.title": "选择当前ESP-IDF版本",
"idf.flashType.description": "设备烧录方式,UART 或 JTag",
"openocd.tcl.host.description": "OpenOCD TCL 主机",
"openocd.tcl.port.description": "OpenOCD TCL 端口",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,11 @@
"command": "espIdf.createSbom",
"title": "%espIdf.createSbom.title%",
"category": "ESP-IDF"
},
{
"command": "espIdf.selectCurrentIdfVersion",
"title": "%espIdf.selectCurrentIdfVersion.title%",
"category": "ESP-IDF"
}
],
"breakpoints": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"espIdf.efuse.clearResults.title": "Clear eFuse Summary",
"espIdf.jtag_flash.title": "Flash (with JTag)",
"espIdf.selectFlashMethodAndFlash.title": "Select Flash Method",
"espIdf.selectCurrentIdfVersion.title": "Select Current ESP-IDF Version",
"idf.flashType.description": "Device flash method, UART or JTag",
"openocd.tcl.host.description": "Host for openocd tcl connection",
"openocd.tcl.port.description": "Port for openocd tcl connection",
Expand Down
1 change: 1 addition & 0 deletions schema.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"espIdf.efuse.clearResults.title",
"espIdf.jtag_flash.title",
"espIdf.selectFlashMethodAndFlash.title",
"espIdf.selectCurrentIdfVersion.title",
"idf.flashType.description",
"openocd.tcl.host.description",
"openocd.tcl.port.description",
Expand Down
28 changes: 25 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ import { getFileList, getTestComponents } from "./espIdf/unitTest/utils";
import { saveDefSdkconfig } from "./espIdf/menuconfig/saveDefConfig";
import { createSBOM, installEspSBOM } from "./espBom";
import { getEspHomeKitSdk } from "./espHomekit/espHomekitDownload";
import { getCurrentIdfSetup, selectIdfSetup } from "./versionSwitcher";

// Global variables shared by commands
let workspaceRoot: vscode.Uri;
Expand Down Expand Up @@ -276,7 +277,7 @@ export async function activate(context: vscode.ExtensionContext) {
// Create a status bar item with current workspace

// Status Bar Item with common commands
statusBarItems = createCmdsStatusBarItems();
statusBarItems = await createCmdsStatusBarItems();

// Create Kconfig Language Server Client
KconfigLangClient.startKconfigLangServer(context);
Expand Down Expand Up @@ -804,6 +805,16 @@ export async function activate(context: vscode.ExtensionContext) {
);
});

registerIDFCommand("espIdf.selectCurrentIdfVersion", () => {
PreCheck.perform([webIdeCheck, openFolderCheck], async () => {
const currentIdfSetup = await selectIdfSetup(workspaceRoot);
if (currentIdfSetup) {
statusBarItems["currentIdfVersion"].text =
"$(octoface) ESP-IDF v" + currentIdfSetup.version;
}
});
});

registerIDFCommand("espIdf.customTask", async () => {
try {
const customTask = new CustomTask(workspaceRoot);
Expand Down Expand Up @@ -1222,7 +1233,7 @@ export async function activate(context: vscode.ExtensionContext) {
workspaceRoot
) as boolean;
if (enableStatusBar) {
statusBarItems = createCmdsStatusBarItems();
statusBarItems = await createCmdsStatusBarItems();
} else if (!enableStatusBar) {
for (let statusItem in statusBarItems) {
statusBarItems[statusItem].dispose();
Expand Down Expand Up @@ -1258,6 +1269,9 @@ export async function activate(context: vscode.ExtensionContext) {
}
} else if (e.affectsConfiguration("idf.espIdfPath" + winFlag)) {
ESP.URL.Docs.IDF_INDEX = undefined;
let currentIdfVersion = await getCurrentIdfSetup(workspaceRoot);
statusBarItems["currentIdfVersion"].text =
"$(octoface) ESP-IDF v" + currentIdfVersion.version;
} else if (e.affectsConfiguration("idf.qemuTcpPort")) {
qemuManager.configure({
tcpPort: idfConf.readParameter("idf.qemuTcpPort", workspaceRoot),
Expand Down Expand Up @@ -3603,7 +3617,7 @@ function registerTreeProvidersForIDFExplorer(context: vscode.ExtensionContext) {
);
}

function createCmdsStatusBarItems() {
async function createCmdsStatusBarItems() {
const enableStatusBar = idfConf.readParameter(
"idf.enableStatusBar"
) as boolean;
Expand All @@ -3625,8 +3639,16 @@ function createCmdsStatusBarItems() {
workspaceRoot
);
}
let currentIdfVersion = await getCurrentIdfSetup(workspaceRoot);
const statusBarItems: { [key: string]: vscode.StatusBarItem } = {};

statusBarItems["currentIdfVersion"] = createStatusBarItem(
"$(octoface) ESP-IDF v" + currentIdfVersion.version,
"ESP-IDF: Select current ESP-IDF version",
"espIdf.selectCurrentIdfVersion",
102
);

statusBarItems["port"] = createStatusBarItem(
"$(plug)" + port,
"ESP-IDF: Select Port to Use (COM, tty, usbserial)",
Expand Down
15 changes: 0 additions & 15 deletions src/setup/installPyReqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,6 @@ export async function installPyReqs(
return;
}

export async function installExtensionPyReqs(
idfToolsDir: string,
pythonBinPath: string,
espIdfPath: string
) {
const logTracker = new PyReqLog(sendPyReqLog);
await pythonManager.installExtensionPyReqs(
pythonBinPath,
espIdfPath,
idfToolsDir,
logTracker,
OutputChannel.init()
);
}

export function sendPyReqLog(log: string) {
SetupPanel.postMessage({
command: "updatePyReqsLog",
Expand Down
2 changes: 1 addition & 1 deletion src/setup/setupInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,5 @@ export async function saveSettings(
workspaceFolder
);
await createIdfSetup(espIdfPath, toolsPath, pythonBinPath, gitPath);
window.showInformationMessage("ESP-IDF has been configured");
Logger.infoNotify("ESP-IDF has been configured");
}
6 changes: 0 additions & 6 deletions src/setup/setupValidation/espIdfSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { IdfToolsManager } from "../../idfToolsManager";
import { saveSettings } from "../setupInit";
import { pathExists } from "fs-extra";
import { Logger } from "../../logger/logger";
import { installExtensionPyReqs } from "../installPyReqs";
import { checkPyVenv } from "./pythonEnv";
import { ConfigurationTarget, Uri } from "vscode";

Expand All @@ -42,11 +41,6 @@ export async function useIdfSetupSettings(
const exportedVars = await idfToolsManager.exportVars(
join(setupConf.toolsPath, "tools")
);
await installExtensionPyReqs(
setupConf.toolsPath,
setupConf.python,
setupConf.idfPath
);
await saveSettings(
setupConf.idfPath,
setupConf.python,
Expand Down
81 changes: 81 additions & 0 deletions src/versionSwitcher/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Project: ESP-IDF VSCode Extension
* File Created: Thursday, 28th March 2024 7:18:49 pm
* Copyright 2024 Espressif Systems (Shanghai) CO LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ConfigurationTarget, Uri, window } from "vscode";
import { getPreviousIdfSetups } from "../setup/existingIdfSetups";
import {
checkIdfSetup,
useIdfSetupSettings,
} from "../setup/setupValidation/espIdfSetup";
import { readParameter } from "../idfConfiguration";
import { getIdfMd5sum } from "../setup/espIdfJson";
import { getEspIdfFromCMake } from "../utils";
import { IdfSetup } from "../views/setup/types";

export async function selectIdfSetup(workspaceFolder: Uri) {
const idfSetups = await getPreviousIdfSetups(true);
if (idfSetups.length === 0) {
await window.showInformationMessage("No ESP-IDF Setups found");
return;
}
const onlyValidIdfSetups = idfSetups.filter((i) => i.isValid);
const idfSetupOptions = onlyValidIdfSetups.map((idfSetup) => {
return {
label: `Version: v${idfSetup.version}`,
description: `IDF_PATH: ${idfSetup.idfPath}`,
detail: `IDF_TOOLS_PATH: ${idfSetup.toolsPath}`,
target: idfSetup,
};
});
const selectedIdfSetupOption = await window.showQuickPick(idfSetupOptions, {
placeHolder: "Select a ESP-IDF version to use",
});
if (!selectedIdfSetupOption) {
return;
}
await useIdfSetupSettings(
selectedIdfSetupOption.target,
ConfigurationTarget.WorkspaceFolder,
workspaceFolder
);
return selectedIdfSetupOption.target;
}

export async function getCurrentIdfSetup(workspaceFolder: Uri) {
let idfPath = readParameter("idf.espIdfPath", workspaceFolder);
const toolsPath = readParameter("idf.toolsPath", workspaceFolder) as string;
const gitPath = readParameter("idf.gitPath", workspaceFolder);
const pythonPath = readParameter(
"idf.pythonBinPath",
workspaceFolder
) as string;

const idfSetupId = getIdfMd5sum(idfPath);
const idfVersion = await getEspIdfFromCMake(idfPath);
const currentIdfSetup: IdfSetup = {
id: idfSetupId,
idfPath,
gitPath,
toolsPath,
python: pythonPath,
version: idfVersion,
isValid: false,
};
currentIdfSetup.isValid = await checkIdfSetup(currentIdfSetup);
return currentIdfSetup;
}
Loading