Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 3 additions & 11 deletions src/clang/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
*/

import { l10n, Uri, workspace } from "vscode";
import {
appendIdfAndToolsToPath,
getToolchainPath,
isBinInPath,
} from "../utils";
import { appendIdfAndToolsToPath, isBinInPath } from "../utils";
import { pathExists, writeJSON, writeFile } from "fs-extra";
import { readParameter } from "../idfConfiguration";
import { join } from "path";
Expand All @@ -32,10 +28,7 @@ import { EOL } from "os";
export async function validateEspClangExists(workspaceFolder: Uri) {
const modifiedEnv = await appendIdfAndToolsToPath(workspaceFolder);

const espClangdPath = await isBinInPath(
"clangd",
modifiedEnv
);
const espClangdPath = await isBinInPath("clangd", modifiedEnv, ["esp-clang"]);
if (espClangdPath && espClangdPath.includes("esp-clang")) {
return espClangdPath;
}
Expand All @@ -62,11 +55,10 @@ export async function setClangSettings(
return;
}
const buildPath = readParameter("idf.buildPath", workspaceFolder);
const gccPath = await getToolchainPath(workspaceFolder, "gcc");
settingsJson["clangd.path"] = espClangPath;
settingsJson["clangd.arguments"] = [
"--background-index",
`--query-driver=${gccPath}`,
`--query-driver=**`,
`--compile-commands-dir=${buildPath}`,
];
}
Expand Down
16 changes: 11 additions & 5 deletions src/espIdf/openOcd/openOcdManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ export class OpenOCDManager extends EventEmitter {

public async version(): Promise<string> {
const modifiedEnv = await appendIdfAndToolsToPath(this.workspace);
if (!isBinInPath("openocd", modifiedEnv)) {
const openOcdPath = await isBinInPath("openocd", modifiedEnv, [
"openocd-esp32",
]);
if (!openOcdPath) {
return "";
}
const resp = await sspawn("openocd", ["--version"], {
const resp = await sspawn(openOcdPath, ["--version"], {
cwd: this.workspace.fsPath,
env: modifiedEnv,
});
Expand Down Expand Up @@ -157,7 +160,10 @@ export class OpenOCDManager extends EventEmitter {
return;
}
const modifiedEnv = await appendIdfAndToolsToPath(this.workspace);
if (!isBinInPath("openocd", modifiedEnv)) {
const openOcdPath = await isBinInPath("openocd", modifiedEnv, [
"openocd-esp32",
]);
if (!openOcdPath) {
throw new Error(
"Invalid OpenOCD bin path or access is denied for the user"
);
Expand Down Expand Up @@ -208,7 +214,7 @@ export class OpenOCDManager extends EventEmitter {
});
}

this.server = spawn("openocd", openOcdArgs, {
this.server = spawn(openOcdPath, openOcdArgs, {
cwd: this.workspace.fsPath,
env: modifiedEnv,
});
Expand Down Expand Up @@ -263,7 +269,7 @@ export class OpenOCDManager extends EventEmitter {
}
this.stop();
});
this.updateStatusText("❇️ OpenOCD Server (Running)");
this.updateStatusText("❇️ OpenOCD Server (Running)");
OutputChannel.show();
}

Expand Down
2 changes: 1 addition & 1 deletion src/newProject/newProjectPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class NewProjectPanel {
port,
selectedIdfTarget,
openOcdConfigs,
workspaceFolder || vscode.Uri.file(newProjectPath)
vscode.Uri.file(newProjectPath)
);
await createClangdFile(vscode.Uri.file(newProjectPath));
await writeJSON(settingsJsonPath, settingsJson, {
Expand Down
38 changes: 0 additions & 38 deletions src/pythonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,44 +451,6 @@ export async function checkPythonExists(pythonBin: string, workingDir: string) {
return false;
}

export async function checkPipExists(pyBinPath: string, workingDir: string) {
try {
const args = ["-m", "pip", "--version"];
const pipResult = await utils.execChildProcess(pyBinPath, args, workingDir);
if (pipResult) {
const match = pipResult.match(/pip\s\d+(.\d+)?(.\d+)?/g);
if (match && match.length > 0) {
return true;
}
}
} catch (error) {
const newErr =
error && error.message
? error
: new Error("Pip is not found in current environment");
Logger.error(newErr.message, newErr, "pythonManager checkPipExists");
}
return false;
}

export async function checkVenvExists(pyBinPath: string, workingDir: string) {
try {
const pipResult = await utils.execChildProcess(
pyBinPath,
["-c", "import venv"],
workingDir
);
return true;
} catch (error) {
const newErr =
error && error.message
? error
: new Error("Venv is not found in current environment");
Logger.error(newErr.message, newErr, "pythonManager checkVenvExists");
}
return false;
}

export async function getPythonBinList(workingDir: string) {
if (process.platform === "win32") {
return [];
Expand Down
20 changes: 2 additions & 18 deletions src/setup/espIdfDownloadStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
import { pathExists } from "fs-extra";
import * as vscode from "vscode";
import { ESP } from "../config";
import { checkPythonExists, checkPipExists, checkVenvExists } from "../pythonManager";
import { checkPythonExists } from "../pythonManager";
import { SetupPanel } from "./SetupPanel";
import * as utils from "../utils";
import {
IEspIdfLink,
SetupMode,
StatusType,
} from "../views/setup/types";
import { IEspIdfLink, SetupMode, StatusType } from "../views/setup/types";
import { downloadInstallIdfVersion } from "./espIdfDownload";
import { Logger } from "../logger/logger";
import { downloadIdfTools } from "./toolsDownloadStep";
Expand Down Expand Up @@ -53,18 +49,6 @@ export async function expressInstall(
Logger.infoNotify(containerNotFoundMsg);
throw new Error(containerNotFoundMsg);
}
const doesPipExists = await checkPipExists(pyPath, __dirname);
if (!doesPipExists) {
const containerNotFoundMsg = `"${pyPath} -m pip" is not valid. (ERROR_INVALID_PIP)`;
Logger.infoNotify(containerNotFoundMsg);
throw new Error(containerNotFoundMsg);
}
const doesVenvExists = await checkVenvExists(pyPath, __dirname);
if (!doesVenvExists) {
const containerNotFoundMsg = `"${pyPath} -m venv" is not valid. (ERROR_INVALID_VENV)`;
Logger.infoNotify(containerNotFoundMsg);
throw new Error(containerNotFoundMsg);
}
let idfPath: string;
if (selectedIdfVersion.filename === "manual") {
idfPath = espIdfPath;
Expand Down
11 changes: 0 additions & 11 deletions src/setup/installPyReqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ export async function installPyReqs(
Logger.info(msg);
return;
}
const doesPipExists = await pythonManager.checkPipExists(
sysPyBinPath,
workingDir
);
if (!doesPipExists) {
const msg = "Pip have not been found in your environment.";
sendPyReqLog(msg);
OutputChannel.appendLine(msg);
Logger.info(msg);
return;
}
const isNotVirtualEnv = await pythonManager.checkIfNotVirtualEnv(
sysPyBinPath,
workingDir
Expand Down
38 changes: 37 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,32 @@ export async function appendIdfAndToolsToPath(curWorkspace: vscode.Uri) {
}
}

try {
const openOcdPath = await isBinInPath("openocd", modifiedEnv, [
"openocd-esp32",
]);
if (openOcdPath) {
const openOcdDir = path.dirname(openOcdPath);
const openOcdScriptsPath = path.join(
openOcdDir,
"..",
"share",
"openocd",
"scripts"
);
const scriptsExists = await pathExists(openOcdScriptsPath);
if (scriptsExists && modifiedEnv.OPENOCD_SCRIPTS !== openOcdScriptsPath) {
modifiedEnv.OPENOCD_SCRIPTS = openOcdScriptsPath;
}
}
} catch (error) {
Logger.error(
`Error processing OPENOCD_SCRIPTS path: ${error.message}`,
error,
"appendIdfAndToolsToPath OPENOCD_SCRIPTS"
);
}

if (
pathToGitDir &&
!modifiedEnv[pathNameInEnv].split(path.delimiter).includes(pathToGitDir)
Expand Down Expand Up @@ -1302,7 +1328,11 @@ export async function getAllBinPathInEnvPath(
return foundBinaries;
}

export async function isBinInPath(binaryName: string, env: NodeJS.ProcessEnv) {
export async function isBinInPath(
binaryName: string,
env: NodeJS.ProcessEnv,
containerDir?: string[]
) {
let pathNameInEnv: string = Object.keys(process.env).find(
(k) => k.toUpperCase() == "PATH"
);
Expand All @@ -1314,6 +1344,12 @@ export async function isBinInPath(binaryName: string, env: NodeJS.ProcessEnv) {
}
const doesPathExists = await pathExists(binaryPath);
if (doesPathExists) {
if (containerDir && containerDir.length) {
const resultContainerPath = containerDir.join(path.sep);
if (binaryPath.indexOf(resultContainerPath) === -1) {
return "";
}
}
const pathStats = await stat(binaryPath);
if (pathStats.isFile() && canAccessFile(binaryPath, fs.constants.X_OK)) {
return binaryPath;
Expand Down