Skip to content

Commit bfd33e3

Browse files
Clang and OpenOCD binaries in PATH (#1666)
* make sure esp clang and openocd esp32 in binaries path fix query driver compile dir * make sure OPENOCD_SCRIPTS is same as binary, rm pip venv in setup validation
1 parent 92fec02 commit bfd33e3

File tree

7 files changed

+54
-85
lines changed

7 files changed

+54
-85
lines changed

src/clang/index.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
*/
1818

1919
import { l10n, Uri, workspace } from "vscode";
20-
import {
21-
appendIdfAndToolsToPath,
22-
getToolchainPath,
23-
isBinInPath,
24-
} from "../utils";
20+
import { appendIdfAndToolsToPath, isBinInPath } from "../utils";
2521
import { pathExists, writeJSON, writeFile } from "fs-extra";
2622
import { readParameter } from "../idfConfiguration";
2723
import { join } from "path";
@@ -32,10 +28,7 @@ import { EOL } from "os";
3228
export async function validateEspClangExists(workspaceFolder: Uri) {
3329
const modifiedEnv = await appendIdfAndToolsToPath(workspaceFolder);
3430

35-
const espClangdPath = await isBinInPath(
36-
"clangd",
37-
modifiedEnv
38-
);
31+
const espClangdPath = await isBinInPath("clangd", modifiedEnv, ["esp-clang"]);
3932
if (espClangdPath && espClangdPath.includes("esp-clang")) {
4033
return espClangdPath;
4134
}
@@ -62,11 +55,10 @@ export async function setClangSettings(
6255
return;
6356
}
6457
const buildPath = readParameter("idf.buildPath", workspaceFolder);
65-
const gccPath = await getToolchainPath(workspaceFolder, "gcc");
6658
settingsJson["clangd.path"] = espClangPath;
6759
settingsJson["clangd.arguments"] = [
6860
"--background-index",
69-
`--query-driver=${gccPath}`,
61+
`--query-driver=**`,
7062
`--compile-commands-dir=${buildPath}`,
7163
];
7264
}

src/espIdf/openOcd/openOcdManager.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ export class OpenOCDManager extends EventEmitter {
6161

6262
public async version(): Promise<string> {
6363
const modifiedEnv = await appendIdfAndToolsToPath(this.workspace);
64-
if (!isBinInPath("openocd", modifiedEnv)) {
64+
const openOcdPath = await isBinInPath("openocd", modifiedEnv, [
65+
"openocd-esp32",
66+
]);
67+
if (!openOcdPath) {
6568
return "";
6669
}
67-
const resp = await sspawn("openocd", ["--version"], {
70+
const resp = await sspawn(openOcdPath, ["--version"], {
6871
cwd: this.workspace.fsPath,
6972
env: modifiedEnv,
7073
});
@@ -157,7 +160,10 @@ export class OpenOCDManager extends EventEmitter {
157160
return;
158161
}
159162
const modifiedEnv = await appendIdfAndToolsToPath(this.workspace);
160-
if (!isBinInPath("openocd", modifiedEnv)) {
163+
const openOcdPath = await isBinInPath("openocd", modifiedEnv, [
164+
"openocd-esp32",
165+
]);
166+
if (!openOcdPath) {
161167
throw new Error(
162168
"Invalid OpenOCD bin path or access is denied for the user"
163169
);
@@ -208,7 +214,7 @@ export class OpenOCDManager extends EventEmitter {
208214
});
209215
}
210216

211-
this.server = spawn("openocd", openOcdArgs, {
217+
this.server = spawn(openOcdPath, openOcdArgs, {
212218
cwd: this.workspace.fsPath,
213219
env: modifiedEnv,
214220
});
@@ -263,7 +269,7 @@ export class OpenOCDManager extends EventEmitter {
263269
}
264270
this.stop();
265271
});
266-
this.updateStatusText("❇️ OpenOCD Server (Running)");
272+
this.updateStatusText("❇️ OpenOCD Server (Running)");
267273
OutputChannel.show();
268274
}
269275

src/newProject/newProjectPanel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export class NewProjectPanel {
305305
port,
306306
selectedIdfTarget,
307307
openOcdConfigs,
308-
workspaceFolder || vscode.Uri.file(newProjectPath)
308+
vscode.Uri.file(newProjectPath)
309309
);
310310
await createClangdFile(vscode.Uri.file(newProjectPath));
311311
await writeJSON(settingsJsonPath, settingsJson, {

src/pythonManager.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -451,44 +451,6 @@ export async function checkPythonExists(pythonBin: string, workingDir: string) {
451451
return false;
452452
}
453453

454-
export async function checkPipExists(pyBinPath: string, workingDir: string) {
455-
try {
456-
const args = ["-m", "pip", "--version"];
457-
const pipResult = await utils.execChildProcess(pyBinPath, args, workingDir);
458-
if (pipResult) {
459-
const match = pipResult.match(/pip\s\d+(.\d+)?(.\d+)?/g);
460-
if (match && match.length > 0) {
461-
return true;
462-
}
463-
}
464-
} catch (error) {
465-
const newErr =
466-
error && error.message
467-
? error
468-
: new Error("Pip is not found in current environment");
469-
Logger.error(newErr.message, newErr, "pythonManager checkPipExists");
470-
}
471-
return false;
472-
}
473-
474-
export async function checkVenvExists(pyBinPath: string, workingDir: string) {
475-
try {
476-
const pipResult = await utils.execChildProcess(
477-
pyBinPath,
478-
["-c", "import venv"],
479-
workingDir
480-
);
481-
return true;
482-
} catch (error) {
483-
const newErr =
484-
error && error.message
485-
? error
486-
: new Error("Venv is not found in current environment");
487-
Logger.error(newErr.message, newErr, "pythonManager checkVenvExists");
488-
}
489-
return false;
490-
}
491-
492454
export async function getPythonBinList(workingDir: string) {
493455
if (process.platform === "win32") {
494456
return [];

src/setup/espIdfDownloadStep.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
import { pathExists } from "fs-extra";
1616
import * as vscode from "vscode";
1717
import { ESP } from "../config";
18-
import { checkPythonExists, checkPipExists, checkVenvExists } from "../pythonManager";
18+
import { checkPythonExists } from "../pythonManager";
1919
import { SetupPanel } from "./SetupPanel";
2020
import * as utils from "../utils";
21-
import {
22-
IEspIdfLink,
23-
SetupMode,
24-
StatusType,
25-
} from "../views/setup/types";
21+
import { IEspIdfLink, SetupMode, StatusType } from "../views/setup/types";
2622
import { downloadInstallIdfVersion } from "./espIdfDownload";
2723
import { Logger } from "../logger/logger";
2824
import { downloadIdfTools } from "./toolsDownloadStep";
@@ -53,18 +49,6 @@ export async function expressInstall(
5349
Logger.infoNotify(containerNotFoundMsg);
5450
throw new Error(containerNotFoundMsg);
5551
}
56-
const doesPipExists = await checkPipExists(pyPath, __dirname);
57-
if (!doesPipExists) {
58-
const containerNotFoundMsg = `"${pyPath} -m pip" is not valid. (ERROR_INVALID_PIP)`;
59-
Logger.infoNotify(containerNotFoundMsg);
60-
throw new Error(containerNotFoundMsg);
61-
}
62-
const doesVenvExists = await checkVenvExists(pyPath, __dirname);
63-
if (!doesVenvExists) {
64-
const containerNotFoundMsg = `"${pyPath} -m venv" is not valid. (ERROR_INVALID_VENV)`;
65-
Logger.infoNotify(containerNotFoundMsg);
66-
throw new Error(containerNotFoundMsg);
67-
}
6852
let idfPath: string;
6953
if (selectedIdfVersion.filename === "manual") {
7054
idfPath = espIdfPath;

src/setup/installPyReqs.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ export async function installPyReqs(
4545
Logger.info(msg);
4646
return;
4747
}
48-
const doesPipExists = await pythonManager.checkPipExists(
49-
sysPyBinPath,
50-
workingDir
51-
);
52-
if (!doesPipExists) {
53-
const msg = "Pip have not been found in your environment.";
54-
sendPyReqLog(msg);
55-
OutputChannel.appendLine(msg);
56-
Logger.info(msg);
57-
return;
58-
}
5948
const isNotVirtualEnv = await pythonManager.checkIfNotVirtualEnv(
6049
sysPyBinPath,
6150
workingDir

src/utils.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,32 @@ export async function appendIdfAndToolsToPath(curWorkspace: vscode.Uri) {
12011201
}
12021202
}
12031203

1204+
try {
1205+
const openOcdPath = await isBinInPath("openocd", modifiedEnv, [
1206+
"openocd-esp32",
1207+
]);
1208+
if (openOcdPath) {
1209+
const openOcdDir = path.dirname(openOcdPath);
1210+
const openOcdScriptsPath = path.join(
1211+
openOcdDir,
1212+
"..",
1213+
"share",
1214+
"openocd",
1215+
"scripts"
1216+
);
1217+
const scriptsExists = await pathExists(openOcdScriptsPath);
1218+
if (scriptsExists && modifiedEnv.OPENOCD_SCRIPTS !== openOcdScriptsPath) {
1219+
modifiedEnv.OPENOCD_SCRIPTS = openOcdScriptsPath;
1220+
}
1221+
}
1222+
} catch (error) {
1223+
Logger.error(
1224+
`Error processing OPENOCD_SCRIPTS path: ${error.message}`,
1225+
error,
1226+
"appendIdfAndToolsToPath OPENOCD_SCRIPTS"
1227+
);
1228+
}
1229+
12041230
if (
12051231
pathToGitDir &&
12061232
!modifiedEnv[pathNameInEnv].split(path.delimiter).includes(pathToGitDir)
@@ -1302,7 +1328,11 @@ export async function getAllBinPathInEnvPath(
13021328
return foundBinaries;
13031329
}
13041330

1305-
export async function isBinInPath(binaryName: string, env: NodeJS.ProcessEnv) {
1331+
export async function isBinInPath(
1332+
binaryName: string,
1333+
env: NodeJS.ProcessEnv,
1334+
containerDir?: string[]
1335+
) {
13061336
let pathNameInEnv: string = Object.keys(process.env).find(
13071337
(k) => k.toUpperCase() == "PATH"
13081338
);
@@ -1314,6 +1344,12 @@ export async function isBinInPath(binaryName: string, env: NodeJS.ProcessEnv) {
13141344
}
13151345
const doesPathExists = await pathExists(binaryPath);
13161346
if (doesPathExists) {
1347+
if (containerDir && containerDir.length) {
1348+
const resultContainerPath = containerDir.join(path.sep);
1349+
if (binaryPath.indexOf(resultContainerPath) === -1) {
1350+
return "";
1351+
}
1352+
}
13171353
const pathStats = await stat(binaryPath);
13181354
if (pathStats.isFile() && canAccessFile(binaryPath, fs.constants.X_OK)) {
13191355
return binaryPath;

0 commit comments

Comments
 (0)