Skip to content

Commit

Permalink
use workspace folder as readParameter scope
Browse files Browse the repository at this point in the history
  • Loading branch information
brianignacio5 committed Feb 11, 2022
1 parent 2c41a4c commit 81818ca
Show file tree
Hide file tree
Showing 41 changed files with 314 additions and 236 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
"idf.showOnboardingOnInit": {
"type": "boolean",
"default": true,
"scope": "resource",
"scope": "window",
"description": "%param.showOnboardingOnInit%"
},
"trace.poll_period": {
Expand Down Expand Up @@ -682,7 +682,7 @@
"idf.enableUpdateSrcsToCMakeListsFile": {
"type": "boolean",
"description": "%param.enableUpdateSrcsToCMakeListsFile%",
"scope": "resource",
"scope": "window",
"default": true
},
"idf.qemuTcpPort": {
Expand Down
8 changes: 4 additions & 4 deletions src/build/buildCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export async function buildCommand(
buildType: string
) {
let continueFlag = true;
const buildTask = new BuildTask(workspace.fsPath);
const sizeTask = new IdfSizeTask(workspace.fsPath);
const customTask = new CustomTask(workspace.fsPath);
const buildTask = new BuildTask(workspace);
const sizeTask = new IdfSizeTask(workspace);
const customTask = new CustomTask(workspace);
if (BuildTask.isBuilding || FlashTask.isFlashing) {
const waitProcessIsFinishedMsg = locDic.localize(
"build.waitProcessIsFinishedMessage",
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function buildCommand(
"flasher_args.json file is missing from the build directory, can't proceed, please build properly!!"
);
}
const adapterTargetName = readParameter("idf.adapterTargetName");
const adapterTargetName = readParameter("idf.adapterTargetName", workspace);
if (adapterTargetName !== "esp32s2" && adapterTargetName !== "esp32s3") {
return Logger.warnNotify(
`The selected device target "${adapterTargetName}" is not compatible for DFU, as a result the DFU.bin was not created.`
Expand Down
70 changes: 44 additions & 26 deletions src/build/buildTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@ import { join, dirname } from "path";
import { Logger } from "../logger/logger";
import * as vscode from "vscode";
import * as idfConf from "../idfConfiguration";
import {
appendIdfAndToolsToPath,
isBinInPath,
} from "../utils";
import { appendIdfAndToolsToPath, isBinInPath } from "../utils";
import { TaskManager } from "../taskManager";
import { selectedDFUAdapterId } from "../flash/dfu";

export class BuildTask {
public static isBuilding: boolean;
private curWorkspace: string;
private curWorkspace: vscode.Uri;
private idfPathDir: string;
private adapterTargetName: string;

constructor(workspace: string) {
this.curWorkspace = join(workspace, "build");
this.idfPathDir = idfConf.readParameter("idf.espIdfPath") as string;
constructor(workspace: vscode.Uri) {
this.curWorkspace = workspace;
this.idfPathDir = idfConf.readParameter(
"idf.espIdfPath",
workspace
) as string;
this.adapterTargetName = idfConf.readParameter(
"idf.adapterTargetName"
"idf.adapterTargetName",
workspace
) as string;
}

Expand All @@ -47,7 +48,10 @@ export class BuildTask {
}

private async saveBeforeBuild() {
const shallSaveBeforeBuild = idfConf.readParameter("idf.saveBeforeBuild");
const shallSaveBeforeBuild = idfConf.readParameter(
"idf.saveBeforeBuild",
this.curWorkspace
);
if (shallSaveBeforeBuild) {
await vscode.workspace.saveAll();
}
Expand All @@ -70,10 +74,10 @@ export class BuildTask {
public dfuShellExecution(options?: vscode.ShellExecutionOptions) {
return new vscode.ShellExecution(
`${join(this.idfPathDir, "tools", "mkdfu.py")} write -o ${join(
this.curWorkspace,
join(this.curWorkspace.fsPath, "build"),
"dfu.bin"
)} --json ${join(
this.curWorkspace,
join(this.curWorkspace.fsPath, "build"),
"flasher_args.json"
)} --pid ${selectedDFUAdapterId(this.adapterTargetName)}`,
options
Expand All @@ -93,48 +97,57 @@ export class BuildTask {
throw new Error("ALREADY_BUILDING");
}
this.building(true);
const modifiedEnv = appendIdfAndToolsToPath();
await ensureDir(this.curWorkspace);
const modifiedEnv = appendIdfAndToolsToPath(this.curWorkspace);
await ensureDir(join(this.curWorkspace.fsPath, "build"));
const canAccessCMake = await isBinInPath(
"cmake",
this.curWorkspace,
this.curWorkspace.fsPath,
modifiedEnv
);
const canAccessNinja = await isBinInPath(
"ninja",
this.curWorkspace,
this.curWorkspace.fsPath,
modifiedEnv
);

const cmakeCachePath = join(this.curWorkspace, "CMakeCache.txt");
const cmakeCachePath = join(
this.curWorkspace.fsPath,
"build",
"CMakeCache.txt"
);
const cmakeCacheExists = await pathExists(cmakeCachePath);

if (canAccessCMake === "" || canAccessNinja === "") {
throw new Error("CMake or Ninja executables not found");
}

const options: vscode.ShellExecutionOptions = {
cwd: this.curWorkspace,
cwd: join(this.curWorkspace.fsPath, "build"),
env: modifiedEnv,
};
const isSilentMode = idfConf.readParameter(
"idf.notificationSilentMode"
"idf.notificationSilentMode",
this.curWorkspace
) as boolean;
const showTaskOutput = isSilentMode
? vscode.TaskRevealKind.Always
: vscode.TaskRevealKind.Silent;

if (!cmakeCacheExists) {
const compilerArgs = (idfConf.readParameter(
"idf.cmakeCompilerArgs"
"idf.cmakeCompilerArgs",
this.curWorkspace
) as Array<string>) || [
"-G",
"Ninja",
"-DPYTHON_DEPS_CHECKED=1",
"-DESP_PLATFORM=1",
"..",
];
const enableCCache = idfConf.readParameter("idf.enableCCache") as boolean;
const enableCCache = idfConf.readParameter(
"idf.enableCCache",
this.curWorkspace
) as boolean;
if (enableCCache && compilerArgs && compilerArgs.length) {
const indexOfCCache = compilerArgs.indexOf("-DCCACHE_ENABLE=1");
if (indexOfCCache === -1) {
Expand All @@ -157,7 +170,9 @@ export class BuildTask {
}

const buildArgs =
(idfConf.readParameter("idf.ninjaArgs") as Array<string>) || [];
(idfConf.readParameter("idf.ninjaArgs", this.curWorkspace) as Array<
string
>) || [];
const buildExecution = this.getNinjaShellExecution(buildArgs, options);
TaskManager.addTask(
{ type: "esp-idf", command: "ESP-IDF Build", taskId: "idf-build-task" },
Expand All @@ -171,15 +186,18 @@ export class BuildTask {

public async buildDfu() {
this.building(true);
const modifiedEnv = appendIdfAndToolsToPath();
await ensureDir(this.curWorkspace);
const modifiedEnv = appendIdfAndToolsToPath(this.curWorkspace);
await ensureDir(join(this.curWorkspace.fsPath, "build"));

const options: vscode.ShellExecutionOptions = {
cwd: dirname(this.curWorkspace),
cwd: this.curWorkspace.fsPath,
env: modifiedEnv,
};

const isSilentMode = idfConf.readParameter("idf.notificationSilentMode");
const isSilentMode = idfConf.readParameter(
"idf.notificationSilentMode",
this.curWorkspace
);
const showTaskOutput = isSilentMode
? vscode.TaskRevealKind.Always
: vscode.TaskRevealKind.Silent;
Expand Down
21 changes: 15 additions & 6 deletions src/common/abstractCloning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ import treeKill from "tree-kill";
import { Logger } from "../logger/logger";
import { checkGitExists, dirExistPromise } from "../utils";
import { OutputChannel } from "../logger/outputChannel";
import { CancellationToken, Progress, ProgressLocation, window } from "vscode";
import {
CancellationToken,
Progress,
ProgressLocation,
Uri,
window,
} from "vscode";
import * as idfConf from "../idfConfiguration";
import { PackageProgress } from "../PackageProgress";

export class AbstractCloning {
private cloneProcess: ChildProcess;
private readonly GITHUB_REPO: string;

constructor(
githubRepository: string,
private name: string,
Expand All @@ -45,7 +51,7 @@ export class AbstractCloning {
public downloadByCloning(
installDir: string,
pkgProgress?: PackageProgress,
progress?: Progress<{ message?: string; increment?: number }>,
progress?: Progress<{ message?: string; increment?: number }>
) {
return new Promise<void>((resolve, reject) => {
this.cloneProcess = spawn(
Expand Down Expand Up @@ -130,8 +136,8 @@ export class AbstractCloning {
});
}

public async getRepository(configurationId: string) {
const toolsDir = await idfConf.readParameter("idf.toolsPath");
public async getRepository(configurationId: string, workspace?: Uri) {
const toolsDir = await idfConf.readParameter("idf.toolsPath", workspace);
const installDir = await window.showQuickPick(
[
{
Expand Down Expand Up @@ -182,7 +188,10 @@ export class AbstractCloning {
cancelToken: CancellationToken
) => {
try {
const gitVersion = await checkGitExists(installDirPath, this.gitBinPath);
const gitVersion = await checkGitExists(
installDirPath,
this.gitBinPath
);
if (!gitVersion || gitVersion === "Not found") {
throw new Error("Git is not found in idf.gitPath or PATH");
}
Expand Down
2 changes: 1 addition & 1 deletion src/component-manager/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ComponentManagerUIPanel {
if (!!ComponentManagerUIPanel.instance) {
ComponentManagerUIPanel.instance.panel.reveal(column);
}
const url = readParameter("esp.component-manager.url");
const url = readParameter("esp.component-manager.url", workspaceRoot);
if (!url) {
throw new Error("esp.component-manager.url is not set");
}
Expand Down
6 changes: 3 additions & 3 deletions src/component-manager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export async function addDependency(
component: string
) {
try {
const idfPathDir = readParameter("idf.espIdfPath");
const idfPathDir = readParameter("idf.espIdfPath", workspace);
const idfPy = join(idfPathDir, "tools", "idf.py");
const modifiedEnv = appendIdfAndToolsToPath();
const pythonBinPath = readParameter("idf.pythonBinPath") as string;
const modifiedEnv = appendIdfAndToolsToPath(workspace);
const pythonBinPath = readParameter("idf.pythonBinPath", workspace) as string;
const addDependencyResult = await spawn(
pythonBinPath,
[idfPy, "add-dependency", `--component=${component}`, dependency],
Expand Down
12 changes: 6 additions & 6 deletions src/coverage/configureProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ export async function configureProjectWithGcov(workspacePath: Uri) {
const gcovEnableRequest = `{"version": 2, "set": { "APPTRACE_DEST_TRAX": true, "APPTRACE_GCOV_ENABLE": true }}\n`;
ConfserverProcess.sendUpdatedValue(gcovEnableRequest);
ConfserverProcess.saveGuiConfigValues();
await openCoverageUrl();
await openCoverageUrl(workspacePath);
}

export async function openCoverageUrl() {
export async function openCoverageUrl(workspacePath: Uri) {
const docsVersions = await getDocsVersion();
const idfPath =
readParameter("idf.espIdfPath") || process.env.IDF_PATH;
const gitPath = readParameter("idf.gitPath") || "git";
readParameter("idf.espIdfPath", workspacePath) || process.env.IDF_PATH;
const gitPath = readParameter("idf.gitPath", workspacePath) || "git";
let idfVersion = "v" + (await getEspIdfVersion(idfPath, gitPath));
let idfTarget = readParameter("idf.adapterTargetName");
let idfTarget = readParameter("idf.adapterTargetName", workspacePath);
if (idfTarget === "custom") {
idfTarget = readParameter("idf.customAdapterTargetName");
idfTarget = readParameter("idf.customAdapterTargetName", workspacePath);
}
let docVersion = docsVersions.find(
(docVer) => docVer.name === idfVersion
Expand Down
28 changes: 14 additions & 14 deletions src/coverage/coverageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export function getGcovExecutable(idfTarget: string) {
: `xtensa-${idfTarget}-elf-gcov`;
}

export async function getGcovFilterPaths() {
export async function getGcovFilterPaths(workspacePath: vscode.Uri) {
const espAdfPath =
idfConf.readParameter("idf.espAdfPath") || process.env.ADF_PATH;
idfConf.readParameter("idf.espAdfPath", workspacePath) || process.env.ADF_PATH;
const espIdfPath =
idfConf.readParameter("idf.espIdfPath") || process.env.IDF_PATH;
idfConf.readParameter("idf.espIdfPath", workspacePath) || process.env.IDF_PATH;
const espMdfPath =
idfConf.readParameter("idf.espMdfPath") || process.env.MDF_PATH;
idfConf.readParameter("idf.espMdfPath", workspacePath) || process.env.MDF_PATH;

const pathsToFilter: string[] = [];

Expand Down Expand Up @@ -83,9 +83,9 @@ export async function getGcovFilterPaths() {
return pathsToFilter;
}

export async function buildJson(dirPath: string) {
const componentsDir = await getGcovFilterPaths();
const idfTarget = idfConf.readParameter("idf.adapterTargetName") || "esp32";
export async function buildJson(dirPath: vscode.Uri) {
const componentsDir = await getGcovFilterPaths(dirPath);
const idfTarget = idfConf.readParameter("idf.adapterTargetName", dirPath) || "esp32";
const gcovTool = getGcovExecutable(idfTarget);

const result = await _runCmd(
Expand All @@ -98,14 +98,14 @@ export async function buildJson(dirPath: string) {
gcovTool,
"--json",
],
dirPath.replace(/\\/g, "/")
dirPath.fsPath.replace(/\\/g, "/")
);
return JSON.parse(result);
}

export async function buildHtml(dirPath: string) {
const componentsDir = await getGcovFilterPaths();
const idfTarget = idfConf.readParameter("idf.adapterTargetName") || "esp32";
export async function buildHtml(dirPath: vscode.Uri) {
const componentsDir = await getGcovFilterPaths(dirPath);
const idfTarget = idfConf.readParameter("idf.adapterTargetName", dirPath) || "esp32";
const gcovTool = getGcovExecutable(idfTarget);
const result = await _runCmd(
"gcovr",
Expand All @@ -117,13 +117,13 @@ export async function buildHtml(dirPath: string) {
gcovTool,
"--html",
],
dirPath
dirPath.fsPath
);
return result;
}

function _runCmd(cmd: string, args: string[], dirPath: string) {
const modifiedEnv = appendIdfAndToolsToPath();
const modifiedEnv = appendIdfAndToolsToPath(vscode.Uri.file(dirPath));
return spawn(cmd, args, { env: modifiedEnv, cwd: dirPath })
.then((resultBuffer) => resultBuffer.toString())
.catch((e) => {
Expand Down Expand Up @@ -234,7 +234,7 @@ export async function generateCoverageForEditors(
}

let gcovHtmlPanel: vscode.WebviewPanel;
export async function previewReport(dirPath: string) {
export async function previewReport(dirPath: vscode.Uri) {
try {
const column = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
Expand Down
2 changes: 1 addition & 1 deletion src/coverage/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class CoverageRenderer {

public async renderCoverage() {
const editors = vscode.window.visibleTextEditors;
this.gcovObj = await buildJson(this.workspaceFolder.fsPath);
this.gcovObj = await buildJson(this.workspaceFolder);
if (editors && editors.length > 0 && this.cache.length < 1) {
const editorsWithCoverage = await generateCoverageForEditors(
this.workspaceFolder.fsPath,
Expand Down
Loading

0 comments on commit 81818ca

Please sign in to comment.