Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,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 +1318,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