Skip to content

Commit

Permalink
Feature/doctor cmd (#255)
Browse files Browse the repository at this point in the history
* initial doctor function

* check settings fs access

* add idf tools validation

* add report file

* refactor ignore result files

* Delete result.json

* add system info

* launch cpp json files

* add ru i18n cmd title

* add cmd to readme
  • Loading branch information
brianignacio5 authored Jan 19, 2021
1 parent 1419c4c commit 8c55198
Show file tree
Hide file tree
Showing 30 changed files with 1,049 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ If applicable, add screenshots to help explain your problem.
- ESP-IDF Version: [e.g. v3.2.2]
- Python Version: [e.g. 2.7.10]

> **NOTE**: You can use the `ESP-IDF: Doctor command` to generate a report of your configuration.
**Logs**
If applicable, please share the log file which can be obtained from

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ testFiles/tools
bandit_output.txt
flake8_output.txt
results/
report.txt
report.json
2 changes: 2 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ package-lock.json
node_modules
gulpfile.js
.yarnrc
report.txt
report.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Click <kbd>F1</kbd> to show Visual studio code actions, then type **ESP-IDF** to
| Install ESP-IDF Python Packages | | |
| Open NVS Partition Editor | | |
| Select OpenOCD Board Configuration | | |
| Doctor command | | |

The **Add Arduino-ESP32 as ESP-IDF Component** command will add [Arduino-ESP32](https://github.com/espressif/arduino-esp32) as a ESP-IDF component in your current directory (`${CURRENT_DIRECTORY}/components/arduino`). You can also use the **Create ESP-IDF project** command with `arduino-as-component` template to create a new project directory that includes Arduino-esp32 as an ESP-IDF component.

Expand Down
9 changes: 8 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ languagesDirs.forEach((langDir) => {
});

function clean(done) {
del(["out/**", "package.nls.*.json", "*.vsix"]);
del([
"dist/**",
"out/**",
"package.nls.*.json",
"*.vsix",
"report.json",
"report.txt",
]);
done();
}

Expand Down
1 change: 1 addition & 0 deletions i18n/en/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"espIdf.getEspMdf.title": "ESP-IDF: Install ESP-MDF",
"espIdf.installPyReqs.title": "ESP-IDF: Install ESP-IDF extension Python Packages",
"espIdf.openDocUrl.title": "ESP-IDF: Open ESP-IDF Documentation...",
"espIdf.doctorCommand.title": "ESP-IDF: Doctor command",
"espIdf.clearDocsSearchResult.title": "ESP-IDF: Clear ESP-IDF Search results",
"espIdf.fullClean.title": "ESP-IDF: Full clean project",
"espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: Open NVS Partition Editor",
Expand Down
1 change: 1 addition & 0 deletions i18n/es/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"espIdf.getEspMdf.title": "ESP-IDF: Instalar ESP-MDF",
"espIdf.installPyReqs.title": "ESP-IDF: Instalar paquetes Python para extensión ESP-IDF",
"espIdf.openDocUrl.title": "ESP-IDF: Abrir documentación ESP-IDF...",
"espIdf.doctorCommand.title": "ESP-IDF: Comando Doctor",
"espIdf.clearDocsSearchResult.title": "ESP-IDF: Limpiar resultados de busqueda",
"espIdf.fullClean.title": "ESP-IDF: Limpiar el proyecto",
"espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: Abrir editor de particiones NVS",
Expand Down
1 change: 1 addition & 0 deletions i18n/ru/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"espIdf.getEspMdf.title": "ESP-IDF: Установить ESP-MDF",
"espIdf.installPyReqs.title": "ESP-IDF: Установите пакеты Python расширения ESP-IDF",
"espIdf.openDocUrl.title": "ESP-IDF: Открыть документацию ...",
"espIdf.doctorCommand.title": "ESP-IDF: Команда врача",
"espIdf.clearDocsSearchResult.title": "ESP-IDF: Очистить результаты поиска",
"espIdf.fullClean.title": "ESP-IDF: Полный чистый проект",
"espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: Откройте редактор разделов NVS",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"espIdf.getEspMdf.title": "ESP-ADF: 安装ESP-MDF",
"espIdf.installPyReqs.title": "ESP-IDF: 安装ESP-IDF扩展Python包",
"espIdf.openDocUrl.title": "ESP-IDF: 打开ESP-IDF文档...",
"espIdf.doctorCommand.title": "ESP-IDF: 医生指挥部",
"espIdf.clearDocsSearchResult.title": "ESP-IDF: 清除ESP-IDF搜索结果",
"espIdf.fullClean.title": "ESP-IDF: 全清洁工程",
"espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: 打开NVS分区编辑器",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"onCommand:esp.webview.open.partition-table",
"onCommand:espIdf.webview.nvsPartitionEditor",
"onCommand:espIdf.selectOpenOcdConfigFiles",
"onCommand:espIdf.doctorCommand",
"onView:idfAppTracer",
"onView:idfAppTraceArchive",
"onView:espRainmaker",
Expand Down Expand Up @@ -782,6 +783,10 @@
{
"command": "espIdf.selectOpenOcdConfigFiles",
"title": "%espIdf.selectOpenOcdConfigFiles.title%"
},
{
"command": "espIdf.doctorCommand",
"title": "%espIdf.doctorCommand.title%"
}
],
"breakpoints": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"espIdf.getEspMdf.title": "ESP-IDF: Install ESP-MDF",
"espIdf.installPyReqs.title": "ESP-IDF: Install ESP-IDF extension Python Packages",
"espIdf.openDocUrl.title": "ESP-IDF: Open ESP-IDF Documentation...",
"espIdf.doctorCommand.title": "ESP-IDF: Doctor command",
"espIdf.clearDocsSearchResult.title": "ESP-IDF: Clear ESP-IDF Search results",
"espIdf.fullClean.title": "ESP-IDF: Full clean project",
"espIdf.webview.nvsPartitionEditor.title": "ESP-IDF: Open NVS Partition Editor",
Expand Down
1 change: 1 addition & 0 deletions schema.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"espIdf.selectOpenOcdConfigFiles.title",
"espIdf.fullClean.title",
"espIdf.webview.nvsPartitionEditor.title",
"espIdf.doctorCommand.title",
"debug.initConfig.name",
"debug.initConfig.description",
"param.adapterTargetName",
Expand Down
37 changes: 37 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ import { release } from "os";
import del from "del";
import { NVSPartitionTable } from "./espIdf/nvs/partitionTable/panel";
import { getBoards } from "./espIdf/openOcd/boardConfiguration";
import { generateConfigurationReport } from "./support";
import { initializeReportObject } from "./support/initReportObj";
import { writeTextReport } from "./support/writeReport";

// Global variables shared by commands
let workspaceRoot: vscode.Uri;
Expand Down Expand Up @@ -1339,6 +1342,40 @@ export async function activate(context: vscode.ExtensionContext) {
});
});

registerIDFCommand("espIdf.doctorCommand", async () => {
await vscode.window.withProgress(
{
cancellable: false,
location: vscode.ProgressLocation.Notification,
title: "ESP-IDF: Preparing ESP-IDF extension report",
},
async (
progress: vscode.Progress<{ message: string; increment: number }>
) => {
const reportedResult = initializeReportObject();
try {
await generateConfigurationReport(
context,
workspaceRoot,
reportedResult
);
} catch (error) {
reportedResult.latestError = error;
const errMsg = error.message
? error.message
: "Configuration report error";
Logger.error(errMsg, error);
Logger.warnNotify(
"Extension configuration report has been copied to clipboard with errors"
);
const reportOutput = await writeTextReport(reportedResult, context);
await vscode.env.clipboard.writeText(reportOutput);
return reportedResult;
}
}
);
});

registerIDFCommand(
"espIdf.apptrace.archive.showReport",
(trace: AppTraceArchiveItems) => {
Expand Down
60 changes: 60 additions & 0 deletions src/support/checkEspIdfRequirements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Project: ESP-IDF VSCode Extension
* File Created: Wednesday, 30th December 2020 4:45:23 pm
* Copyright 2020 Espressif Systems (Shanghai) CO LTD
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
* http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { join } from "path";
import * as vscode from "vscode";
import { execChildProcess } from "./execChildProcess";
import { reportObj } from "./types";

export async function checkEspIdfRequirements(
reportedResult: reportObj,
context: vscode.ExtensionContext
) {
const requirementsPath = join(
reportedResult.configurationSettings.espIdfPath,
"requirements.txt"
);
const result = await checkRequirements(
context,
reportedResult,
requirementsPath
);
reportedResult.idfCheckRequirements.output = result;
reportedResult.idfCheckRequirements.result = result;
}

export async function checkRequirements(
context: vscode.ExtensionContext,
reportedResult: reportObj,
requirementsPath: string
) {
const checkPythonDepsScript = join(
reportedResult.configurationSettings.espIdfPath,
"tools",
"check_python_dependencies.py"
);
const modifiedEnv: { [key: string]: string } = <{ [key: string]: string }>(
Object.assign({}, process.env)
);
modifiedEnv.IDF_PATH = reportedResult.configurationSettings.espIdfPath;
const requirementsResult = await execChildProcess(
`${reportedResult.configurationSettings.pythonBinPath} ${checkPythonDepsScript} -r "${requirementsPath}"`,
context.extensionPath,
{ env: modifiedEnv, cwd: context.extensionPath }
);
return requirementsResult.trim();
}
55 changes: 55 additions & 0 deletions src/support/checkEspIdfTools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Project: ESP-IDF VSCode Extension
* File Created: Wednesday, 30th December 2020 4:40:28 pm
* Copyright 2020 Espressif Systems (Shanghai) CO LTD
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
* http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { pathExists, readJSON } from "fs-extra";
import { join } from "path";
import * as vscode from "vscode";
import { IdfToolsManager } from "../idfToolsManager";
import { PlatformInformation } from "../PlatformInformation";
import { OutputChannel } from "../logger/outputChannel";
import { reportObj } from "./types";

export async function checkEspIdfTools(
reportedResult: reportObj,
context: vscode.ExtensionContext
) {
const platformInfo = await PlatformInformation.GetPlatformInformation();
let toolsJsonPath: string = join(
reportedResult.configurationSettings.espIdfPath,
"tools",
"tools.json"
);
const jsonExists = await pathExists(toolsJsonPath);
if (!jsonExists) {
const idfToolsJsonToUse =
reportedResult.espIdfVersion.result.localeCompare("4.0") < 0
? "fallback-tools.json"
: "tools.json";
toolsJsonPath = join(context.extensionPath, idfToolsJsonToUse);
}
const toolsJson = await readJSON(toolsJsonPath);
const idfToolsManager = new IdfToolsManager(
toolsJson,
platformInfo,
OutputChannel.init()
);
const verifiedPkgs = await idfToolsManager.getRequiredToolsInfo(
reportedResult.configurationSettings.toolsPath,
reportedResult.configurationSettings.customExtraPaths
);
reportedResult.espIdfToolsVersions = verifiedPkgs;
}
53 changes: 53 additions & 0 deletions src/support/checkExtensionRequirements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Project: ESP-IDF VSCode Extension
* File Created: Wednesday, 30th December 2020 4:47:28 pm
* Copyright 2020 Espressif Systems (Shanghai) CO LTD
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
* http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { join } from "path";
import * as vscode from "vscode";
import { reportObj } from "./types";
import { checkRequirements } from "./checkEspIdfRequirements";

export async function checkExtensionRequirements(
reportedResult: reportObj,
context: vscode.ExtensionContext
) {
const requirementsPath = join(context.extensionPath, "requirements.txt");
const result = await checkRequirements(
context,
reportedResult,
requirementsPath
);
reportedResult.extensionRequirements.output = result;
reportedResult.extensionRequirements.result = result;
}

export async function checkDebugAdapterRequirements(
reportedResult: reportObj,
context: vscode.ExtensionContext
) {
const requirementsPath = join(
context.extensionPath,
"esp_debug_adapter",
"requirements.txt"
);
const result = await checkRequirements(
context,
reportedResult,
requirementsPath
);
reportedResult.debugAdapterRequirements.output = result;
reportedResult.debugAdapterRequirements.result = result;
}
36 changes: 36 additions & 0 deletions src/support/checkSystemInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Project: ESP-IDF VSCode Extension
* File Created: Tuesday, 12th January 2021 7:43:50 pm
* Copyright 2021 Espressif Systems (Shanghai) CO LTD
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
* http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ESP } from "../config";
import { reportObj } from "./types";
import * as vscode from "vscode";
import * as os from "os";

export async function checkSystemInfo(reportedResult: reportObj) {
const extensionVersion = vscode.extensions.getExtension(ESP.extensionID);
reportedResult.systemInfo.architecture = os.arch();
reportedResult.systemInfo.envPath =
process.platform === "win32" ? process.env.Path : process.env.PATH;
reportedResult.systemInfo.extensionVersion = extensionVersion
? extensionVersion.packageJSON.version
: "ESP-IDF_VERSION_NOT_FOUND";
reportedResult.systemInfo.language = vscode.env.language;
reportedResult.systemInfo.platform = os.platform();
reportedResult.systemInfo.systemName = os.release();
reportedResult.systemInfo.shell = vscode.env.shell;
reportedResult.systemInfo.vscodeVersion = vscode.version;
}
Loading

0 comments on commit 8c55198

Please sign in to comment.