Skip to content

Commit 94413ae

Browse files
[VSC-1640] profiles env should merge customExtraVars with profile env (#1498)
* profiles env should merge customExtraVars with profile env * add idfTarget to new project wizard * add idfTarget to project conf editor * setTarget update current profile idfTarget, notification mismatch idftarget sdkconfig setting * fix saveProjectConfFile reference
1 parent e144fbc commit 94413ae

24 files changed

+358
-157
lines changed

l10n/bundle.l10n.es.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,7 @@
209209
"Warning: Could not fully remove setting {0}: {1}": "Advertencia: No se pudo eliminar completamente la configuración {0}: {1}",
210210
"ESP-IDF settings removed successfully.": "Configuraciones de ESP-IDF eliminadas exitosamente.",
211211
"Failed to remove settings: {0}": "Error al eliminar las configuraciones: {0}",
212-
"Error: {0}": "Error: {0}"
212+
"Error: {0}": "Error: {0}",
213+
"IDF_TARGET mismatch: SDKConfig value is \"{0}\" but settings value is \"{1}\".": "Desajuste de IDF_TARGET: el valor de SDKConfig es \"{0}\" pero el valor de configuración es \"{1}\".",
214+
"Set IDF_TARGET": "Establecer IDF_TARGET"
213215
}

l10n/bundle.l10n.pt.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,7 @@
209209
"Warning: Could not fully remove setting {0}: {1}": "Aviso: Não foi possível remover completamente a configuração {0}: {1}",
210210
"ESP-IDF settings removed successfully.": "Configurações ESP-IDF removidas com sucesso.",
211211
"Failed to remove settings: {0}": "Falha ao remover configurações: {0}",
212-
"Error: {0}": "Erro: {0}"
212+
"Error: {0}": "Erro: {0}",
213+
"IDF_TARGET mismatch: SDKConfig value is \"{0}\" but settings value is \"{1}\".": "Incompatibilidade de IDF_TARGET: o valor de SDKConfig é \"{0}\" mas o valor das configurações é \"{1}\".",
214+
"Set IDF_TARGET": "Definir IDF_TARGET"
213215
}

l10n/bundle.l10n.ru.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,7 @@
209209
"Warning: Could not fully remove setting {0}: {1}": "Предупреждение: Не удалось полностью удалить настройку {0}: {1}",
210210
"ESP-IDF settings removed successfully.": "Настройки ESP-IDF успешно удалены.",
211211
"Failed to remove settings: {0}": "Не удалось удалить настройки: {0}",
212-
"Error: {0}": "Ошибка: {0}"
212+
"Error: {0}": "Ошибка: {0}",
213+
"IDF_TARGET mismatch: SDKConfig value is \"{0}\" but settings value is \"{1}\".": "Несоответствие IDF_TARGET: значение SDKConfig \"{0}\", но значение настроек \"{1}\".",
214+
"Set IDF_TARGET": "Установить IDF_TARGET"
213215
}

l10n/bundle.l10n.zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,7 @@
209209
"Warning: Could not fully remove setting {0}: {1}": "警告:无法完全删除设置 {0}:{1}",
210210
"ESP-IDF settings removed successfully.": "ESP-IDF设置已成功删除。",
211211
"Failed to remove settings: {0}": "删除设置失败:{0}",
212-
"Error: {0}": "错误:{0}"
212+
"Error: {0}": "错误:{0}",
213+
"IDF_TARGET mismatch: SDKConfig value is \"{0}\" but settings value is \"{1}\".": "IDF_TARGET 不匹配:SDKConfig 值为 \"{0}\",但设置值为 \"{1}\"",
214+
"Set IDF_TARGET": "设置 IDF_TARGET"
213215
}

src/espIdf/setTarget/getTargets.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ export interface IdfTarget {
2828
target: string;
2929
}
3030

31-
export async function getTargetsFromEspIdf(workspaceFolder: Uri) {
32-
const idfPathDir = readParameter("idf.espIdfPath", workspaceFolder);
31+
export async function getTargetsFromEspIdf(
32+
workspaceFolder: Uri,
33+
givenIdfPathDir?: string
34+
) {
35+
const idfPathDir = givenIdfPathDir
36+
? givenIdfPathDir
37+
: readParameter("idf.espIdfPath", workspaceFolder);
3338
const idfPyPath = join(idfPathDir, "tools", "idf.py");
3439
const modifiedEnv = await appendIdfAndToolsToPath(workspaceFolder);
3540
const pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder);

src/espIdf/setTarget/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { OutputChannel } from "../../logger/outputChannel";
3434
import { getBoards, getOpenOcdScripts } from "../openOcd/boardConfiguration";
3535
import { getTargetsFromEspIdf } from "./getTargets";
3636
import { setTargetInIDF } from "./setTargetInIdf";
37+
import { updateCurrentProfileIdfTarget } from "../../project-conf";
3738

3839
export async function setIdfTarget(
3940
placeHolderMsg: string,
@@ -77,6 +78,7 @@ export async function setIdfTarget(
7778
configurationTarget,
7879
workspaceFolder.uri
7980
);
81+
await updateCurrentProfileIdfTarget(selectedTarget.target, workspaceFolder.uri);
8082
const openOcdScriptsPath = await getOpenOcdScripts(workspaceFolder.uri);
8183
const boards = await getBoards(
8284
openOcdScriptsPath,

src/extension.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ import { IdfSetup } from "./views/setup/types";
171171
import { asyncRemoveEspIdfSettings } from "./uninstall";
172172
import { ProjectConfigurationManager } from "./project-conf/ProjectConfigurationManager";
173173
import { readPartition } from "./espIdf/partition-table/partitionReader";
174+
import { getTargetsFromEspIdf } from "./espIdf/setTarget/getTargets";
174175

175176
// Global variables shared by commands
176177
let workspaceRoot: vscode.Uri;
@@ -477,8 +478,6 @@ export async function activate(context: vscode.ExtensionContext) {
477478
})
478479
);
479480

480-
context.subscriptions.push(projectConfigManager);
481-
482481
vscode.debug.onDidTerminateDebugSession((e) => {
483482
if (isOpenOCDLaunchedByDebug && !isDebugRestarted) {
484483
isOpenOCDLaunchedByDebug = false;
@@ -1151,9 +1150,11 @@ export async function activate(context: vscode.ExtensionContext) {
11511150
progress: vscode.Progress<{ message: string; increment: number }>
11521151
) => {
11531152
try {
1153+
const targetsFromIdf = await getTargetsFromEspIdf(workspaceRoot);
11541154
projectConfigurationPanel.createOrShow(
11551155
context.extensionPath,
1156-
workspaceRoot
1156+
workspaceRoot,
1157+
targetsFromIdf
11571158
);
11581159
} catch (error) {
11591160
Logger.errorNotify(
@@ -3737,24 +3738,19 @@ export async function activate(context: vscode.ExtensionContext) {
37373738
context,
37383739
statusBarItems
37393740
);
3741+
context.subscriptions.push(projectConfigManager);
37403742

3741-
const projectConfCommandDisposable = vscode.commands.registerCommand(
3742-
"espIdf.projectConf",
3743-
async () => {
3744-
PreCheck.perform([openFolderCheck], async () => {
3745-
if (projectConfigManager) {
3746-
await projectConfigManager.selectProjectConfiguration();
3747-
} else {
3748-
vscode.window.showErrorMessage(
3749-
"Project Configuration Manager not initialized."
3750-
);
3751-
}
3752-
});
3753-
}
3754-
);
3755-
3756-
// Add the disposable to context subscriptions
3757-
context.subscriptions.push(projectConfCommandDisposable);
3743+
registerIDFCommand("espIdf.projectConf", () => {
3744+
PreCheck.perform([openFolderCheck], async () => {
3745+
if (projectConfigManager) {
3746+
await projectConfigManager.selectProjectConfiguration();
3747+
} else {
3748+
vscode.window.showErrorMessage(
3749+
"Project Configuration Manager not initialized."
3750+
);
3751+
}
3752+
});
3753+
});
37583754
}
37593755

37603756
function checkAndNotifyMissingCompileCommands() {

src/idfConfiguration.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export function addWinIfRequired(param: string) {
3434
return param;
3535
}
3636

37-
export function parameterToProjectConfigMap(param: string) {
37+
export function parameterToProjectConfigMap(
38+
param: string,
39+
scope?: vscode.ConfigurationScope
40+
) {
3841
if (!ESP.ProjectConfiguration.store) {
3942
return "";
4043
}
@@ -66,7 +69,22 @@ export function parameterToProjectConfigMap(param: string) {
6669
? currentProjectConf.build.sdkconfigDefaults
6770
: "";
6871
case "idf.customExtraVars":
69-
return currentProjectConf.env;
72+
const paramUpdated = addWinIfRequired(param);
73+
let settingsVars = vscode.workspace
74+
.getConfiguration("", scope)
75+
.get(paramUpdated) as { [key: string]: any };
76+
let resultVars = {};
77+
for (const envKey of Object.keys(settingsVars)) {
78+
resultVars[envKey] = settingsVars[envKey];
79+
}
80+
for (const projectConfEnvKey of Object.keys(currentProjectConf.env)) {
81+
resultVars[projectConfEnvKey] =
82+
currentProjectConf.env[projectConfEnvKey];
83+
}
84+
if (currentProjectConf.idfTarget) {
85+
resultVars["IDF_TARGET"] = currentProjectConf.idfTarget;
86+
}
87+
return resultVars;
7088
case "idf.flashBaudRate":
7189
return currentProjectConf.flashBaudRate;
7290
case "idf.monitorBaudRate":

src/newProject/newProjectInit.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
loadIdfSetupsFromEspIdfJson,
2929
} from "../setup/existingIdfSetups";
3030
import { IdfSetup } from "../views/setup/types";
31+
import { getTargetsFromEspIdf, IdfTarget } from "../espIdf/setTarget/getTargets";
3132

3233
export interface INewProjectArgs {
3334
espIdfSetup: IdfSetup;
@@ -36,6 +37,7 @@ export interface INewProjectArgs {
3637
espMatterPath: string;
3738
espHomeKitSdkPath: string;
3839
espRainmakerPath: string;
40+
idfTargets: IdfTarget[];
3941
boards: IdfBoard[];
4042
components: IComponent[];
4143
serialPortList: string[];
@@ -163,13 +165,17 @@ export async function getNewProjectArgs(
163165
const homeKitSdkTemplates = getExamplesList(espHomeKitSdkPath);
164166
templates["ESP-HOMEKIT-SDK"] = homeKitSdkTemplates;
165167
}
168+
169+
const targetsFromIdf = await getTargetsFromEspIdf(workspace, idfSetup.idfPath);
170+
166171
progress.report({ increment: 50, message: "Initializing wizard..." });
167172
return {
168173
boards: espBoards,
169174
components,
170175
espIdfSetup: idfSetup,
171176
espAdfPath: adfExists ? espAdfPath : undefined,
172177
espMdfPath: mdfExists ? espMdfPath : undefined,
178+
idfTargets: targetsFromIdf,
173179
espMatterPath: matterExists ? espMatterPath : undefined,
174180
espHomeKitSdkPath: homekitSdkExists ? espHomeKitSdkPath : undefined,
175181
espRainmakerPath: rainmakerExists ? espRainmakerPath : undefined,

src/newProject/newProjectPanel.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export class NewProjectPanel {
124124
message.port &&
125125
message.projectName &&
126126
message.openOcdConfigFiles &&
127-
message.template
127+
message.template &&
128+
message.selectedIdfTarget
128129
) {
129130
this.createProject(
130131
newProjectArgs.espIdfSetup,
@@ -134,7 +135,8 @@ export class NewProjectPanel {
134135
message.projectName,
135136
JSON.parse(message.template),
136137
message.openOcdConfigFiles,
137-
newProjectArgs.workspaceFolder
138+
newProjectArgs.workspaceFolder,
139+
message.selectedIdfTarget
138140
);
139141
}
140142
break;
@@ -183,6 +185,7 @@ export class NewProjectPanel {
183185
command: "initialLoad",
184186
containerDirectory: containerPath,
185187
projectName: "project-name",
188+
idfTargets: newProjectArgs.idfTargets,
186189
serialPortList: newProjectArgs.serialPortList,
187190
openOcdConfigFiles: defConfigFiles,
188191
templates: newProjectArgs.templates,
@@ -211,7 +214,8 @@ export class NewProjectPanel {
211214
projectName: string,
212215
template: IExample,
213216
openOcdConfigs?: string,
214-
workspaceFolder?: vscode.Uri
217+
workspaceFolder?: vscode.Uri,
218+
selectedIdfTarget?: string
215219
) {
216220
const newProjectPath = path.join(projectDirectory, projectName);
217221
let isSkipped = false;
@@ -293,6 +297,7 @@ export class NewProjectPanel {
293297
settingsJsonPath,
294298
idfSetup,
295299
port,
300+
selectedIdfTarget,
296301
openOcdConfigs,
297302
workspaceFolder
298303
);

0 commit comments

Comments
 (0)