Skip to content

Commit

Permalink
extension auto configuration (#1075)
Browse files Browse the repository at this point in the history
* add option to select initial setup if not configured

* rm error log to channel on autoconf

* rm checkIdfSetup log to channel

* rm exec child process channel log

* fix lint
  • Loading branch information
brianignacio5 authored Dec 7, 2023
1 parent caac086 commit f549ded
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
24 changes: 17 additions & 7 deletions src/checkExtensionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import {
import { Logger } from "./logger/logger";
import { readParameter } from "./idfConfiguration";
import { useIdfSetupSettings } from "./setup/setupValidation/espIdfSetup";
import { getIdfMd5sum } from "./setup/espIdfJson";
import { getEspIdfFromCMake } from "./utils";
import { IdfSetup } from "./views/setup/types";

export async function checkExtensionSettings(
extensionPath: string,
Expand Down Expand Up @@ -52,20 +55,27 @@ export async function checkExtensionSettings(
progress,
workspace
);
if (
setupArgs.espIdfPath &&
setupArgs.espToolsPath &&
setupArgs.existingIdfSetups &&
setupArgs.existingIdfSetups.length
) {
if (setupArgs.existingIdfSetups && setupArgs.existingIdfSetups.length) {
progress.report({
increment: 5,
message: "ESP-IDF and tools found, configuring the extension...",
});
const confTarget = readParameter(
"idf.saveScope"
) as vscode.ConfigurationTarget;
await useIdfSetupSettings(setupArgs.existingIdfSetups[0], confTarget);
const options = setupArgs.existingIdfSetups.map((existingSetup) => {
return {
label: `ESP-IDF ${existingSetup.version} in ${existingSetup.idfPath}`,
target: existingSetup,
};
});
const selectedSetup = await vscode.window.showQuickPick(options, {
placeHolder: "Select a ESP-IDF setup to use",
});
if (!selectedSetup) {
return;
}
await useIdfSetupSettings(selectedSetup.target, confTarget);
} else if (
typeof process.env.WEB_IDE === "undefined" &&
showSetupWindow
Expand Down
31 changes: 23 additions & 8 deletions src/idfToolsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ export class IdfToolsManager {
});
}

public async verifyPackages(pathsToVerify: string, onReqPkgs?: string[]) {
public async verifyPackages(
pathsToVerify: string,
onReqPkgs?: string[],
logToChannel: boolean = true
) {
const pkgs = await this.getPackageList(onReqPkgs);
const promiseArr: { [key: string]: string } = {};
const names = pkgs.map((pkg) => pkg.name);
const promises = pkgs.map((p) =>
this.checkBinariesVersion(p, pathsToVerify)
this.checkBinariesVersion(p, pathsToVerify, logToChannel)
);
const versionExistsArr = await Promise.all(promises);
names.forEach((pkgName, i) => (promiseArr[pkgName] = versionExistsArr[i]));
Expand Down Expand Up @@ -195,7 +199,11 @@ export class IdfToolsManager {
return versions.length > 0 ? versions[0].name : undefined;
}

public async checkBinariesVersion(pkg: IPackage, pathsToVerify: string) {
public async checkBinariesVersion(
pkg: IPackage,
pathsToVerify: string,
logToChannel: boolean = true
) {
const pathNameInEnv: string =
process.platform === "win32" ? "Path" : "PATH";
let modifiedPath = process.env[pathNameInEnv];
Expand All @@ -220,7 +228,7 @@ export class IdfToolsManager {
const binVersionResponse = await utils.execChildProcess(
versionCmd,
process.cwd(),
this.toolsManagerChannel,
logToChannel ? this.toolsManagerChannel : undefined,
{
env: modifiedEnv,
maxBuffer: 500 * 1024,
Expand All @@ -246,8 +254,10 @@ export class IdfToolsManager {
return "No match";
} catch (error) {
const errMsg = `Error checking ${pkg.name} version`;
this.toolsManagerChannel.appendLine(errMsg);
this.toolsManagerChannel.appendLine(error);
if (logToChannel) {
this.toolsManagerChannel.appendLine(errMsg);
this.toolsManagerChannel.appendLine(error);
}
Logger.error(errMsg, error);
return errMsg;
}
Expand Down Expand Up @@ -315,11 +325,16 @@ export class IdfToolsManager {
public async getRequiredToolsInfo(
basePath?: string,
pathToVerify?: string,
onReqPkgs?: string[]
onReqPkgs?: string[],
logToChannel: boolean = true
) {
let versions: { [key: string]: string } = {};
if (pathToVerify) {
versions = await this.verifyPackages(pathToVerify, onReqPkgs);
versions = await this.verifyPackages(
pathToVerify,
onReqPkgs,
logToChannel
);
}
const packages = await this.getPackageList(onReqPkgs);
const idfToolsList = packages.map((pkg) => {
Expand Down
8 changes: 4 additions & 4 deletions src/setup/existingIdfSetups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IdfSetup } from "../views/setup/types";
import { getIdfMd5sum, loadEspIdfJson } from "./espIdfJson";
import { checkIdfSetup } from "./setupValidation/espIdfSetup";

export async function getPreviousIdfSetups() {
export async function getPreviousIdfSetups(logToChannel: boolean = true) {
const setupKeys = ESP.GlobalConfiguration.store.getIdfSetupKeys();
const idfSetups: IdfSetup[] = [];
for (let idfSetupKey of setupKeys) {
Expand All @@ -33,15 +33,15 @@ export async function getPreviousIdfSetups() {
);
if (idfSetup && idfSetup.idfPath) {
try {
idfSetup.isValid = await checkIdfSetup(idfSetup);
idfSetup.isValid = await checkIdfSetup(idfSetup, logToChannel);
idfSetup.version = await getEspIdfFromCMake(idfSetup.idfPath);
idfSetups.push(idfSetup);
} catch (err) {
const msg = err.message
? err.message
: "Error checkIdfSetup in getPreviousIdfSetups";
Logger.error(msg, err);
ESP.GlobalConfiguration.store.clearIdfSetup(idfSetup.id)
ESP.GlobalConfiguration.store.clearIdfSetup(idfSetup.id);
}
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ export async function loadIdfSetupsFromEspIdfJson(toolsPath: string) {
isValid: false,
} as IdfSetup;
try {
setupConf.isValid = await checkIdfSetup(setupConf);
setupConf.isValid = await checkIdfSetup(setupConf, false);
} catch (err) {
const msg = err.message
? err.message
Expand Down
5 changes: 3 additions & 2 deletions src/setup/setupInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function getSetupInitialValues(
const espIdfTagsList = await getEspIdfTags();
progress.report({ increment: 10, message: "Getting Python versions..." });
const pythonVersions = await getPythonList(extensionPath);
const idfSetups = await getPreviousIdfSetups();
const idfSetups = await getPreviousIdfSetups(false);
const setupInitArgs = {
espIdfVersionsList,
espIdfTagsList,
Expand Down Expand Up @@ -284,7 +284,8 @@ export async function isCurrentInstallValid(workspaceFolder: Uri) {
const toolsInfo = await idfToolsManager.getRequiredToolsInfo(
path.join(toolsPath, "tools"),
extraPaths,
extraReqPaths
extraReqPaths,
false
);
const failedToolsResult = toolsInfo.filter(
(tInfo) =>
Expand Down
6 changes: 4 additions & 2 deletions src/setup/setupValidation/espIdfSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export async function useIdfSetupSettings(
);
}

export async function checkIdfSetup(setupConf: IdfSetup) {
export async function checkIdfSetup(setupConf: IdfSetup,
logToChannel: boolean = true) {
try {
if (!setupConf.idfPath) {
return false;
Expand All @@ -76,7 +77,8 @@ export async function checkIdfSetup(setupConf: IdfSetup) {
const toolsInfo = await idfToolsManager.getRequiredToolsInfo(
join(setupConf.toolsPath, "tools"),
exportedToolsPaths,
["cmake", "ninja"]
["cmake", "ninja"],
logToChannel
);

const failedToolsResult = toolsInfo.filter(
Expand Down

0 comments on commit f549ded

Please sign in to comment.