Skip to content

Commit

Permalink
fix support for multiple sdkconfig files (#1252)
Browse files Browse the repository at this point in the history
* fix support for multiple sdkconfig files

* dispose confserver when project config has changed

* update compile commands json proj conf change

* rm selected project config upon workspace change

* rm idfTarget from project conf editor

* fix set target status bar update

* add open file button in project config editor

* update pr comment action version

* update default idf target
  • Loading branch information
brianignacio5 authored Oct 11, 2024
1 parent bdadcd0 commit ed521c9
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
- uses: actions/github-script@v7
with:
# This snippet is public-domain, taken from
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ To allow you to have multiple configurations for the same project, you can defin
+-----------------------------------+-------------------------------------------------------------------------------------------+
| **idf.customExtraVars** | Variables to be added to system environment variables |
+-----------------------------------+-------------------------------------------------------------------------------------------+
| **idf.adapterTargetName** | ESP-IDF Target Chip (Example: esp32) |
+-----------------------------------+-------------------------------------------------------------------------------------------+
| **idf.flashBaudRate** | Flash Baud rate |
+-----------------------------------+-------------------------------------------------------------------------------------------+
| **idf.monitorBaudRate** | Monitor Baud Rate (Empty by default to use SDKConfig CONFIG_ESP_CONSOLE_UART_BAUDRATE) |
Expand Down
2 changes: 1 addition & 1 deletion docs_espressif/en/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ This is how the extension uses them:
6. **idf.openOcdLaunchArgs**: Launch arguments string array for OpenOCD. The resulting OpenOCD launch command looks like this: ``openocd -d${idf.openOcdDebugLevel} -f ${idf.openOcdConfigs} ${idf.openOcdLaunchArgs}``.

.. note::
* When you use the command **ESP-IDF: Set Espressif Device Target** it will override **idf.adapterTargetName** with selected chip and **idf.openOcdConfigs** with its default OpenOCD Configuration Files.
* When you use the command **ESP-IDF: Set Espressif Device Target** it will override the current sdkconfig IDF_TARGET with selected Espressif chip and **idf.openOcdConfigs** with its default OpenOCD Configuration Files.
* If you want to customize the **idf.openOcdConfigs** alone, you can use the **ESP-IDF: Select OpenOCD Board Configuration** or modify your settings.json directly.

Code Coverage Specific Settings
Expand Down
10 changes: 8 additions & 2 deletions src/build/buildTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import * as vscode from "vscode";
import * as idfConf from "../idfConfiguration";
import {
appendIdfAndToolsToPath,
isBinInPath,
getEspIdfFromCMake,
compareVersion,
getEspIdfFromCMake,
getSDKConfigFilePath,
isBinInPath,
} from "../utils";
import { TaskManager } from "../taskManager";
import { selectedDFUAdapterId } from "../flash/dfu";
Expand Down Expand Up @@ -167,6 +168,11 @@ export class BuildTask {
}
}

const sdkconfigFile = await getSDKConfigFilePath(this.currentWorkspace);
if (compilerArgs.indexOf("SDKCONFIG") === -1) {
compilerArgs.push(`-DSDKCONFIG=${sdkconfigFile}`);
}

const sdkconfigDefaults =
(idfConf.readParameter("idf.sdkconfigDefaults") as string[]) || [];

Expand Down
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export namespace ESP {

export namespace ProjectConfiguration {
export let store: ProjectConfigStore;
export const CONFIGURATION_LIST_KEY = "PROJECT_CONFIGURATION_KEYS";
export const SELECTED_CONFIG = "SELECTED_PROJECT_CONFIG";
export const PROJECT_CONFIGURATION_FILENAME =
"esp_idf_project_configuration.json";
Expand Down
45 changes: 43 additions & 2 deletions src/espIdf/menuconfig/confServerProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ export class ConfserverProcess {
const pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder);
const modifiedEnv = await appendIdfAndToolsToPath(workspaceFolder);
if (!ConfserverProcess.instance) {
const configFile = await getSDKConfigFilePath(workspaceFolder);
ConfserverProcess.instance = new ConfserverProcess(
workspaceFolder,
extensionPath,
pythonBinPath,
configFile,
modifiedEnv
);
ConfserverProcess.instance.configFile = await getSDKConfigFilePath(workspaceFolder);
}
ConfserverProcess.instance.emitter.once("valuesLoaded", resolve);
});
Expand Down Expand Up @@ -220,7 +221,24 @@ export class ConfserverProcess {
if (enableCCache) {
reconfigureArgs.push("--ccache");
}
reconfigureArgs.push("-C", currWorkspace.fsPath, "reconfigure");
reconfigureArgs.push("-C", currWorkspace.fsPath);
const sdkconfigDefaults =
(idfConf.readParameter("idf.sdkconfigDefaults") as string[]) || [];

if (reconfigureArgs.indexOf("SDKCONFIG") === -1) {
reconfigureArgs.push(`-DSDKCONFIG=${ConfserverProcess.instance.configFile}`)
}

if (
reconfigureArgs.indexOf("SDKCONFIG_DEFAULTS") === -1 &&
sdkconfigDefaults &&
sdkconfigDefaults.length
) {
reconfigureArgs.push(
`-DSDKCONFIG_DEFAULTS='${sdkconfigDefaults.join(";")}'`
);
}
reconfigureArgs.push("reconfigure");
const getSdkconfigProcess = spawn(pythonBinPath, reconfigureArgs, {
env: modifiedEnv,
});
Expand Down Expand Up @@ -299,6 +317,7 @@ export class ConfserverProcess {
workspaceFolder: vscode.Uri,
extensionPath: string,
pythonBinPath: string,
configFile: string,
modifiedEnv: { [key: string]: string }
) {
this.workspaceFolder = workspaceFolder;
Expand All @@ -308,6 +327,7 @@ export class ConfserverProcess {
idfConf.readParameter("idf.espIdfPath", workspaceFolder).toString() ||
process.env.IDF_PATH;
modifiedEnv.PYTHONUNBUFFERED = "0";
this.configFile = configFile;
const idfPath = path.join(this.espIdfPath, "tools", "idf.py");
const enableCCache = idfConf.readParameter(
"idf.enableCCache",
Expand All @@ -317,6 +337,27 @@ export class ConfserverProcess {
if (enableCCache) {
confServerArgs.push("--ccache");
}
const buildDirPath = idfConf.readParameter(
"idf.buildPath",
workspaceFolder
) as string;
confServerArgs.push("-B", buildDirPath);
const sdkconfigDefaults =
(idfConf.readParameter("idf.sdkconfigDefaults") as string[]) || [];

if (confServerArgs.indexOf("SDKCONFIG") === -1) {
confServerArgs.push(`-DSDKCONFIG=${this.configFile}`)
}

if (
confServerArgs.indexOf("SDKCONFIG_DEFAULTS") === -1 &&
sdkconfigDefaults &&
sdkconfigDefaults.length
) {
confServerArgs.push(
`-DSDKCONFIG_DEFAULTS='${sdkconfigDefaults.join(";")}'`
);
}
confServerArgs.push("-C", workspaceFolder.fsPath, "confserver");
this.confServerProcess = spawn(pythonBinPath, confServerArgs, {
env: modifiedEnv,
Expand Down
17 changes: 14 additions & 3 deletions src/espIdf/reconfigure/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
workspace,
} from "vscode";
import { NotificationMode, readParameter } from "../../idfConfiguration";
import { appendIdfAndToolsToPath } from "../../utils";
import { appendIdfAndToolsToPath, compareVersion, getEspIdfFromCMake, getSDKConfigFilePath } from "../../utils";
import { join } from "path";
import { TaskManager } from "../../taskManager";
import { getVirtualEnvPythonPath } from "../../pythonManager";
Expand Down Expand Up @@ -65,12 +65,23 @@ export class IdfReconfigureTask {

const idfPy = join(this.idfPathDir, "tools", "idf.py");
const reconfigureArgs = [idfPy];
const espIdfVersion = await getEspIdfFromCMake(this.idfPathDir);
const useEqualSign = compareVersion(espIdfVersion, "4.4") >= 0;

let buildPathArgsIndex = reconfigureArgs.indexOf("-B");
if (buildPathArgsIndex !== -1) {
reconfigureArgs.splice(buildPathArgsIndex, 2);
reconfigureArgs.splice(buildPathArgsIndex, useEqualSign ? 1 : 2);
}
if (useEqualSign) {
reconfigureArgs.push(`-B=${this.buildDirPath}`);
} else {
reconfigureArgs.push("-B", this.buildDirPath);
}

const sdkconfigFile = await getSDKConfigFilePath(this.curWorkspace);
if (reconfigureArgs.indexOf("SDKCONFIG") === -1) {
reconfigureArgs.push(`-DSDKCONFIG=${sdkconfigFile}`);
}
reconfigureArgs.push("-B", this.buildDirPath);

const sdkconfigDefaults =
(readParameter("idf.sdkconfigDefaults") as string[]) || [];
Expand Down
10 changes: 10 additions & 0 deletions src/espIdf/setTarget/setTargetInIdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ export async function setTargetInIDF(
} else {
modifiedEnv.IDF_CCACHE_ENABLE = undefined;
}
if (modifiedEnv.SDKCONFIG) {
setTargetArgs.push(`-DSDKCONFIG='${modifiedEnv.SDKCONFIG}'`);
}
const sdkconfigDefaults =
(readParameter("idf.sdkconfigDefaults") as string[]) || [];

if (sdkconfigDefaults && sdkconfigDefaults.length) {
setTargetArgs.push(`-DSDKCONFIG_DEFAULTS='${sdkconfigDefaults.join(";")}'`);
}

setTargetArgs.push("set-target", selectedTarget.target);
const pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder.uri);
const setTargetResult = await spawn(pythonBinPath, setTargetArgs, {
Expand Down
52 changes: 50 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import { ArduinoComponentInstaller } from "./espIdf/arduino/addArduinoComponent"
import { PartitionTableEditorPanel } from "./espIdf/partition-table";
import { ESPEFuseTreeDataProvider } from "./efuse/view";
import { ESPEFuseManager } from "./efuse";
import { constants, createFileSync, pathExists, readJson } from "fs-extra";
import { constants, createFileSync, pathExists } from "fs-extra";
import { getEspAdf } from "./espAdf/espAdfDownload";
import { getEspMdf } from "./espMdf/espMdfDownload";
import { SetupPanel } from "./setup/SetupPanel";
Expand Down Expand Up @@ -143,7 +143,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 { selectIdfSetup } from "./versionSwitcher";
import { getCurrentIdfSetup, selectIdfSetup } from "./versionSwitcher";
import { checkDebugAdapterRequirements } from "./espIdf/debugAdapter/checkPyReqs";
import { CDTDebugConfigurationProvider } from "./cdtDebugAdapter/debugConfProvider";
import { CDTDebugAdapterDescriptorFactory } from "./cdtDebugAdapter/server";
Expand Down Expand Up @@ -373,6 +373,30 @@ export async function activate(context: vscode.ExtensionContext) {
`$(${commandDictionary[CommandKeys.SelectSerialPort].iconId}) ` +
idfConf.readParameter("idf.port", workspaceRoot);
}
if (statusBarItems["projectConf"]) {
statusBarItems["projectConf"].dispose();
statusBarItems["projectConf"] = undefined;
const selectedConfig = ESP.ProjectConfiguration.store.get<string>(
ESP.ProjectConfiguration.SELECTED_CONFIG
);
ESP.ProjectConfiguration.store.clear(selectedConfig);
ESP.ProjectConfiguration.store.clear(
ESP.ProjectConfiguration.SELECTED_CONFIG
);
}
const currentIdfSetup = await getCurrentIdfSetup(
workspaceRoot,
false
);
if (statusBarItems["currentIdfVersion"]) {
statusBarItems["currentIdfVersion"].text = currentIdfSetup.isValid
? `$(${
commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId
}) ESP-IDF v${currentIdfSetup.version}`
: `$(${
commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId
}) ESP-IDF InvalidSetup`;
}
const coverageOptions = getCoverageOptions(workspaceRoot);
covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions);
break;
Expand Down Expand Up @@ -911,6 +935,27 @@ export async function activate(context: vscode.ExtensionContext) {
tooltip: option.uri.fsPath,
};
utils.updateStatus(statusBarItems["workspace"], workspaceFolderInfo);
if (statusBarItems["projectConf"]) {
statusBarItems["projectConf"].dispose();
statusBarItems["projectConf"] = undefined;
const selectedConfig = ESP.ProjectConfiguration.store.get<string>(
ESP.ProjectConfiguration.SELECTED_CONFIG
);
ESP.ProjectConfiguration.store.clear(selectedConfig);
ESP.ProjectConfiguration.store.clear(
ESP.ProjectConfiguration.SELECTED_CONFIG
);
}
const currentIdfSetup = await getCurrentIdfSetup(workspaceRoot, false);
if (statusBarItems["currentIdfVersion"]) {
statusBarItems["currentIdfVersion"].text = currentIdfSetup.isValid
? `$(${
commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId
}) ESP-IDF v${currentIdfSetup.version}`
: `$(${
commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId
}) ESP-IDF InvalidSetup`;
}
const debugAdapterConfig = {
currentWorkspace: workspaceRoot,
} as IDebugAdapterConfig;
Expand Down Expand Up @@ -1106,6 +1151,8 @@ export async function activate(context: vscode.ExtensionContext) {
commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
);
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
await utils.setCCppPropertiesJsonCompileCommands(workspaceRoot);
ConfserverProcess.dispose();
});
});

Expand Down Expand Up @@ -1830,6 +1877,7 @@ export async function activate(context: vscode.ExtensionContext) {
workspaceRoot
);
await setIdfTarget(enterDeviceTargetMsg, workspaceFolder);
await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]);
});
});

Expand Down
8 changes: 0 additions & 8 deletions src/project-conf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ export class ProjectConfigStore {
public clear(key: string) {
return this.set(key, undefined);
}

public getKeys() {
return this.ctx.workspaceState.get<string[]>(
ESP.ProjectConfiguration.CONFIGURATION_LIST_KEY,
undefined
);
}
}

export async function getProjectConfigurationElements(workspaceFolder: Uri) {
Expand All @@ -76,7 +69,6 @@ export async function getProjectConfigurationElements(workspaceFolder: Uri) {
},
env: projectConfJson[elem].env,
flashBaudRate: projectConfJson[elem].flashBaudRate,
idfTarget: projectConfJson[elem].idfTarget,
monitorBaudRate: projectConfJson[elem].monitorBaudRate,
openOCD: {
debugLevel: projectConfJson[elem].openOCD?.debugLevel,
Expand Down
32 changes: 22 additions & 10 deletions src/project-conf/projectConfPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,24 @@ export class projectConfigurationPanel {
});
}
break;
case "openFilePath":
let selectedFile = await this.openFile();
if (selectedFile) {
this.panel.webview.postMessage({
command: "setFilePath",
confKey: message.confKey,
newPath: selectedFile,
sectionsKeys: message.sectionsKeys,
});
}
break;
default:
break;
}
});
this.panel.onDidDispose(() => this.dispose(), null, this.disposables);
}

private async clearProjectConfFile() {
let projectConfKeys = ESP.ProjectConfiguration.store.getKeys();
if (projectConfKeys && projectConfKeys.length) {
for (const confKey of projectConfKeys) {
ESP.ProjectConfiguration.store.clear(confKey);
}
}
}

private async openFolder() {
const selectedFolder = await window.showOpenDialog({
canSelectFolders: true,
Expand All @@ -146,6 +148,17 @@ export class projectConfigurationPanel {
}
}

private async openFile() {
const selectedFile = await window.showOpenDialog({
canSelectFolders: false,
canSelectFiles: true,
canSelectMany: false,
});
if (selectedFile && selectedFile.length > 0) {
return selectedFile[0].fsPath;
}
}

private clearSelectedProject(projectKeys: string[]) {
const selectedConfig = ESP.ProjectConfiguration.store.get<string>(
ESP.ProjectConfiguration.SELECTED_CONFIG
Expand All @@ -163,7 +176,6 @@ export class projectConfigurationPanel {
private async saveProjectConfFile(projectConfDict: {
[key: string]: ProjectConfElement;
}) {
this.clearProjectConfFile();
const projectConfKeys = Object.keys(projectConfDict);
this.clearSelectedProject(projectConfKeys);
await saveProjectConfFile(this.workspaceFolder, projectConfDict);
Expand Down
1 change: 0 additions & 1 deletion src/project-conf/projectConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface ProjectConfElement {
};
env: { [key: string]: string };
flashBaudRate: string;
idfTarget: string;
monitorBaudRate: string;
openOCD: {
debugLevel: number;
Expand Down
6 changes: 6 additions & 0 deletions src/pythonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ export async function getVirtualEnvPythonPath(workspaceFolder: Uri) {
let pythonPath = readParameter("idf.pythonInstallPath") as string;
let espIdfDir = readParameter("idf.espIdfPath", workspaceFolder) as string;
let idfToolsDir = readParameter("idf.toolsPath", workspaceFolder) as string;
const idfPathExists = await pathExists(espIdfDir);
const idfToolsPathExists = await pathExists(idfToolsDir);
const pythonPathExists = await pathExists(pythonPath);
if (!idfPathExists || !idfToolsPathExists || !pythonPathExists) {
return;
}
const virtualEnvPython = await getPythonEnvPath(
espIdfDir,
idfToolsDir,
Expand Down
Loading

0 comments on commit ed521c9

Please sign in to comment.