From ad4c8f3fe9fde4b3f9071e2f4193dca217856a04 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 3 May 2023 18:22:09 +0900 Subject: [PATCH 1/2] Support tv2-show This commit is a draft version. ONE-vscode-DCO-1.0-Signed-off-by: Jiyoung Yun --- package.json | 44 ++++- src/Backend/Compiler.ts | 6 +- src/Backend/Executor.ts | 11 +- src/Backend/One/OneToolchain.ts | 1 - src/Backend/Toolchain.ts | 60 +++++- src/Backend/ToolchainImpl/DebianToolchain.ts | 42 ++--- src/Job/Job.ts | 1 + src/Job/JobCommand.ts | 1 + src/Job/JobRunner.ts | 1 + src/Job/ToolRunner.ts | 7 +- src/MetadataViewer/MetadataViewerProvider.ts | 27 +++ src/Tests/Backend/Toolchain.test.ts | 6 +- .../ToolchainImpl/DebianToolchain.test.ts | 40 ++-- src/Toolchain/ToolchainEnv.ts | 52 +++++- src/Toolchain/ToolchainProvider.ts | 171 ++++++++++++++++-- src/View/InstallQuickInput.ts | 8 +- 16 files changed, 394 insertions(+), 84 deletions(-) diff --git a/package.json b/package.json index 5abd22cc..166f15f7 100644 --- a/package.json +++ b/package.json @@ -262,6 +262,21 @@ "title": "ONE: Show Metadata", "category": "ONE" }, + { + "command": "one.viewer.metadata.inference", + "title": "Inference", + "category": "ONE" + }, + { + "command": "one.viewer.metadata.profile", + "title": "Profile", + "category": "ONE" + }, + { + "command": "one.viewer.metadata.showModelInfo", + "title": "Show Model information", + "category": "ONE" + }, { "command": "one.editor.cfg.setDefaultValues", "title": "ONE: Set Default Values", @@ -378,6 +393,21 @@ "command": "one.viewer.metadata.showFromOneExplorer", "when": "view == OneExplorerView && viewItem =~ /baseModel|product/", "group": "7_metadata@1" + }, + { + "command": "one.viewer.metadata.inference", + "when": "view == OneExplorerView && viewItem =~ /product/", + "group": "7_metadata@1" + }, + { + "command": "one.viewer.metadata.profile", + "when": "view == OneExplorerView && viewItem =~ /product/", + "group": "7_metadata@1" + }, + { + "command": "one.viewer.metadata.showModelInfo", + "when": "view == OneExplorerView && viewItem =~ /product/", + "group": "7_metadata@1" } ], "explorer/context": [ @@ -473,6 +503,18 @@ "command": "one.viewer.metadata.showFromOneExplorer", "when": "false" }, + { + "command": "one.viewer.metadata.inference", + "when": "false" + }, + { + "command": "one.viewer.metadata.profile", + "when": "false" + }, + { + "command": "one.viewer.metadata.showModelInfo", + "when": "false" + }, { "command": "one.editor.mpq.createFromDefaultExplorer", "when": "false" @@ -502,7 +544,7 @@ "linthtml": "htmlhint media src", "unittest": "node ./out/Tests/runTest.js", "test": "npm run unittest", - "test-no-screen": "DISPLAY=:44 xvfb-run --server-num 44 npm run test", + "test-no-screen": "DISPLAY=:46 xvfb-run -a --server-num 46 npm run test", "coverage": "npm run test coverage", "clean": "rm -rf out" }, diff --git a/src/Backend/Compiler.ts b/src/Backend/Compiler.ts index 38b99d37..ac3483f4 100644 --- a/src/Backend/Compiler.ts +++ b/src/Backend/Compiler.ts @@ -98,4 +98,8 @@ class CompilerBase implements Compiler { } } -export { Compiler, CompilerBase }; +interface ICompilerCommand { + run(cfg: string): Command; +} + +export { Compiler, CompilerBase, ICompilerCommand }; diff --git a/src/Backend/Executor.ts b/src/Backend/Executor.ts index f556a564..ba4a7e39 100644 --- a/src/Backend/Executor.ts +++ b/src/Backend/Executor.ts @@ -59,4 +59,13 @@ class ExecutorBase implements Executor { } } -export { Executor, ExecutorBase }; +interface IExecutorCommand { + // TODO: use cfg path to run onecc after one-infer landed + runInference(model: string, options?: Map): Command; + + runProfile(model: string, options?: Map): Command; + + runShow(model: string, option: string): Command; +} + +export { Executor, ExecutorBase, IExecutorCommand }; diff --git a/src/Backend/One/OneToolchain.ts b/src/Backend/One/OneToolchain.ts index 29393e6d..fc99a32f 100644 --- a/src/Backend/One/OneToolchain.ts +++ b/src/Backend/One/OneToolchain.ts @@ -32,7 +32,6 @@ import { Version } from "../Version"; class OneDebianToolchain extends DebianToolchain { run(cfg: string): Command { - this.prepare(); let cmd = new Command("onecc-docker"); cmd.push("-C"); cmd.push(cfg); diff --git a/src/Backend/Toolchain.ts b/src/Backend/Toolchain.ts index f67e5092..8b5f2d6b 100644 --- a/src/Backend/Toolchain.ts +++ b/src/Backend/Toolchain.ts @@ -15,6 +15,8 @@ */ import { Command } from "./Command"; +import { ICompilerCommand } from "./Compiler"; +import { IExecutorCommand } from "./Executor"; import { Version } from "./Version"; class PackageInfo { @@ -46,25 +48,57 @@ class ToolchainInfo { } } -// TODO: Support `DockerToolchain` so multiple toolchains can be installed -// Toolchain: Debian(...) OR Docker(...) -// A toolchain has a package or multiple packages -class Toolchain { +interface IToolCommand { + info: ToolchainInfo; + install(): Command; + uninstall(): Command; + installed(): Command; +} + +class ToolCommand implements IToolCommand { info: ToolchainInfo; constructor(info: ToolchainInfo) { this.info = info; } install(): Command { - throw Error("Invalid install call"); + throw Error("Method not implemented."); } uninstall(): Command { - throw Error("Invalid uninstall call"); + throw Error("Method not implemented."); } installed(): Command { - throw Error("Invalid installed call"); + throw Error("Method not implemented."); + } +} + +interface IToolchain + extends ICompilerCommand, + IExecutorCommand { + tool: T; + info: ToolchainInfo | undefined; +} + +// TODO: Support `DockerToolchain` so multiple toolchains can be installed +// Toolchain: Debian(...) OR Docker(...) +// A toolchain has a package or multiple packages +class Toolchain implements IToolchain { + tool: ToolCommand; + info: ToolchainInfo; + constructor(info: ToolchainInfo) { + this.tool = new ToolCommand(info); + this.info = info; } run(_cfg: string): Command { - throw Error("Invalid run call"); + throw new Error("Method not implemented."); + } + runInference(_model: string, _options?: Map): Command { + throw new Error("Method not implemented."); + } + runProfile(_model: string, _options?: Map): Command { + throw new Error("Method not implemented."); + } + runShow(_model: string, _option: string): Command { + throw new Error("Method not implemented."); } } @@ -77,4 +111,12 @@ class Toolchain { // TODO: Support filter(), where(), filter(regex) or orderBy() class Toolchains extends Array {} -export { PackageInfo, ToolchainInfo, Toolchain, Toolchains }; +export { + PackageInfo, + ToolchainInfo, + Toolchain, + Toolchains, + ToolCommand, + IToolCommand, + IToolchain, +}; diff --git a/src/Backend/ToolchainImpl/DebianToolchain.ts b/src/Backend/ToolchainImpl/DebianToolchain.ts index aa329683..cbd5bf76 100644 --- a/src/Backend/ToolchainImpl/DebianToolchain.ts +++ b/src/Backend/ToolchainImpl/DebianToolchain.ts @@ -14,10 +14,8 @@ * limitations under the License. */ -import assert from "assert"; - import { Command } from "../Command"; -import { Toolchain, ToolchainInfo } from "../Toolchain"; +import { IToolchain, IToolCommand, ToolchainInfo } from "../Toolchain"; class DebianRepo { uri: string; @@ -35,9 +33,7 @@ enum DebianArch { undefined = "undefined", } -class DebianToolchain implements Toolchain { - ready: boolean = false; - +class DebianTool implements IToolCommand { info: ToolchainInfo; repo?: DebianRepo; arch?: DebianArch = DebianArch.undefined; @@ -48,16 +44,6 @@ class DebianToolchain implements Toolchain { this.arch = arch; } - prepare() { - if (this.ready === false) { - // TODO: make listfile and verify with it - // /etc/apt/source.list.d/ONE-vscode.list - // deb ${this.repo.uri} ${this.repo.foscal} ${this.repo.component} - this.ready = true; - } - assert.ok(this.ready === true); - } - // impl of Toolchain install(): Command { // NOTE (Issue #30) @@ -74,7 +60,6 @@ class DebianToolchain implements Toolchain { // * Aptitude::ProblemResolver::SolutionCost // : Describes how to determine the cost of a solution. // ref: https://tools.ietf.org/doc/aptitude/html/en/ch02s03s04.html - this.prepare(); let cmd = new Command("aptitude"); cmd.push("install"); cmd.push("-o"); @@ -102,7 +87,6 @@ class DebianToolchain implements Toolchain { // According to man(8) apt-get // -q: Quiet; produces output suitable for logging, omitting progress indicators. // -y: Automatic yes to prompts - this.prepare(); let cmd = new Command("aptitude"); cmd.push("purge"); cmd.push(this.info.name); @@ -112,7 +96,6 @@ class DebianToolchain implements Toolchain { return cmd; } installed(): Command { - this.prepare(); let cmd = new Command("dpkg-query"); cmd.push("--show"); let pkg: string = this.info.name; @@ -124,13 +107,30 @@ class DebianToolchain implements Toolchain { cmd.push("echo $?"); return cmd; } +} + +class DebianToolchain implements IToolchain { + tool: DebianTool; + info: ToolchainInfo; + constructor(info: ToolchainInfo, repo?: DebianRepo, arch?: DebianArch) { + this.tool = new DebianTool(info, repo, arch); + this.info = info; + } run(cfg: string): Command { - this.prepare(); let cmd = new Command("onecc"); cmd.push("--config"); cmd.push(cfg); return cmd; } + runInference(_model: string, _options?: Map): Command { + throw new Error("Method not implemented."); + } + runProfile(_model: string, _options?: Map): Command { + throw new Error("Method not implemented."); + } + runShow(_model: string, _option: string): Command { + throw new Error("Method not implemented."); + } } -export { DebianRepo, DebianArch, DebianToolchain }; +export { DebianRepo, DebianArch, DebianTool, DebianToolchain }; diff --git a/src/Job/Job.ts b/src/Job/Job.ts index 67ea1e3e..90f5e198 100644 --- a/src/Job/Job.ts +++ b/src/Job/Job.ts @@ -30,6 +30,7 @@ export interface Job { root: boolean; workDir: string; isCancelable: boolean; + result?: string; successCallback?: JobCallback; failureCallback?: JobCallback; } diff --git a/src/Job/JobCommand.ts b/src/Job/JobCommand.ts index fed24a74..0f66fc46 100644 --- a/src/Job/JobCommand.ts +++ b/src/Job/JobCommand.ts @@ -32,6 +32,7 @@ class JobCommand implements Job { root: boolean; workDir: string; isCancelable: boolean; + result?: string; successCallback?: JobCallback; failureCallback?: JobCallback; diff --git a/src/Job/JobRunner.ts b/src/Job/JobRunner.ts index 14cff9b9..fd717610 100644 --- a/src/Job/JobRunner.ts +++ b/src/Job/JobRunner.ts @@ -91,6 +91,7 @@ export class JobRunner extends EventEmitter { } if (success !== undefined) { + job.result = value.output; success(); } // Move on to next job diff --git a/src/Job/ToolRunner.ts b/src/Job/ToolRunner.ts index 9445525c..3756b6a9 100644 --- a/src/Job/ToolRunner.ts +++ b/src/Job/ToolRunner.ts @@ -33,6 +33,8 @@ const K_ERROR: string = "error"; export interface SuccessResult { // When successful exit, exit code must be 0 exitCode?: number; + // When successful exit, result data contains the stdout data. + output?: string; // When this process was intentionally killed by user, this must be true. intentionallyKilled?: boolean; } @@ -59,6 +61,8 @@ export class ToolRunner { // This value must be set to false when starting a process private killedByMe = false; + private output: string = ""; + private handlePromise( resolve: (value: SuccessResult | PromiseLike) => void, reject: (value: ErrorResult | PromiseLike) => void, @@ -66,6 +70,7 @@ export class ToolRunner { ) { // stdout this.child!.stdout.on(K_DATA, (data: any) => { + this.output = this.output.concat(data.toString()); Logger.append(data.toString()); }); // stderr @@ -141,7 +146,7 @@ export class ToolRunner { if (code === 0) { Logger.info(this.tag, "Build Success."); Logger.appendLine(""); - resolve({ exitCode: 0 }); + resolve({ exitCode: 0, output: this.output }); } else { Logger.info(this.tag, "Build Failed:", code); Logger.appendLine(""); diff --git a/src/MetadataViewer/MetadataViewerProvider.ts b/src/MetadataViewer/MetadataViewerProvider.ts index dd2d763c..19a1494a 100644 --- a/src/MetadataViewer/MetadataViewerProvider.ts +++ b/src/MetadataViewer/MetadataViewerProvider.ts @@ -127,6 +127,33 @@ export class MetadataViewerProvider ); } ), + vscode.commands.registerCommand( + "one.viewer.metadata.inference", + async (uri) => { + // If the method is executed in the ONE Explorer, change the uri instance. + const filePath = uri.uri.fsPath; + vscode.commands.executeCommand("one.toolchain.inference", filePath); + } + ), + vscode.commands.registerCommand( + "one.viewer.metadata.profile", + async (uri) => { + // If the method is executed in the ONE Explorer, change the uri instance. + const filePath = uri.uri.fsPath; + vscode.commands.executeCommand("one.toolchain.profile", filePath); + } + ), + vscode.commands.registerCommand( + "one.viewer.metadata.showModelInfo", + async (uri) => { + // If the method is executed in the ONE Explorer, change the uri instance. + const filePath = uri.uri.fsPath; + vscode.commands.executeCommand( + "one.toolchain.getModelInfo", + filePath + ); + } + ), // Add command registration here ]; diff --git a/src/Tests/Backend/Toolchain.test.ts b/src/Tests/Backend/Toolchain.test.ts index 3596f35e..f2ce79d5 100644 --- a/src/Tests/Backend/Toolchain.test.ts +++ b/src/Tests/Backend/Toolchain.test.ts @@ -45,14 +45,14 @@ suite("Backend", function () { suite("#install()", function () { test("NEG: throws by dummy toolchain by install", function () { const toolchain = new Toolchain(toolchainInfo); - assert.throw(() => toolchain.install()); + assert.throw(() => toolchain.tool.install()); }); }); suite("#installed()", function () { test("NEG: throws in dummy toolchain by installed", function () { const toolchain = new Toolchain(toolchainInfo); - assert.throw(() => toolchain.installed()); + assert.throw(() => toolchain.tool.installed()); }); }); @@ -66,7 +66,7 @@ suite("Backend", function () { suite("#uninstall()", function () { test("NEG: throws in dummy toolchain by uninstall", function () { const toolchain = new Toolchain(toolchainInfo); - assert.throw(() => toolchain.uninstall()); + assert.throw(() => toolchain.tool.uninstall()); }); }); }); diff --git a/src/Tests/Backend/ToolchainImpl/DebianToolchain.test.ts b/src/Tests/Backend/ToolchainImpl/DebianToolchain.test.ts index c26d650b..318f5a69 100644 --- a/src/Tests/Backend/ToolchainImpl/DebianToolchain.test.ts +++ b/src/Tests/Backend/ToolchainImpl/DebianToolchain.test.ts @@ -19,6 +19,7 @@ import { ToolchainInfo } from "../../../Backend/Toolchain"; import { DebianArch, DebianRepo, + DebianTool, DebianToolchain, } from "../../../Backend/ToolchainImpl/DebianToolchain"; import { Version } from "../../../Backend/Version"; @@ -28,14 +29,13 @@ import { Version } from "../../../Backend/Version"; // The tests are fitting its env suite("Backend", function () { suite("ToolchainImpl", function () { - suite("DebianToolchain", function () { - // for Toolchain - // Let's use `npm` - const name = "npm"; - const desc = "npm toolchain"; - const version = new Version(6, 14, 4, "+ds-1ubuntu2"); - const info = new ToolchainInfo(name, desc, version); - + // for Toolchain + // Let's use `npm` + const name = "npm"; + const desc = "npm toolchain"; + const version = new Version(6, 14, 4, "+ds-1ubuntu2"); + const info = new ToolchainInfo(name, desc, version); + suite("DebianTool", function () { suite("#constructor()", function () { test("is contructed with values", function () { const uri = "http://archive.ubuntu.com/ubuntu"; @@ -43,24 +43,16 @@ suite("Backend", function () { const comp = "universe"; const repo = new DebianRepo(uri, dist, comp); const arch = DebianArch.amd64; - let dt = new DebianToolchain(info, repo, arch); + let dt = new DebianTool(info, repo, arch); assert.strictEqual(dt.info, info); assert.strictEqual(dt.repo, repo); assert.strictEqual(dt.arch, arch); }); }); - suite("#prepare()", function () { - test("prepare DebianToolchain", function () { - let dt = new DebianToolchain(info); - dt.prepare(); - assert.strictEqual(dt.ready, true); - }); - }); - suite("#install()", function () { - test("install DebianToolchain", function () { - let dt = new DebianToolchain(info); + test("install DebianTool", function () { + let dt = new DebianTool(info); let cmd = dt.install(); const expectedStr = `sudo aptitude install -o Aptitude::ProblemResolver::SolutionCost=100*canceled-actions,200*removals ${name}=${version.str()} -q -y`; assert.strictEqual(cmd.str(), expectedStr); @@ -68,8 +60,8 @@ suite("Backend", function () { }); suite("#uninstall()", function () { - test("uninstall DebianToolchain", function () { - let dt = new DebianToolchain(info); + test("uninstall DebianTool", function () { + let dt = new DebianTool(info); let cmd = dt.uninstall(); const expectedStr = `sudo aptitude purge ${name} -q -y`; assert.strictEqual(cmd.str(), expectedStr); @@ -77,14 +69,16 @@ suite("Backend", function () { }); suite("#installed()", function () { - test("check DebianToolchain installed", function () { - let dt = new DebianToolchain(info); + test("check DebianTool installed", function () { + let dt = new DebianTool(info); let cmd = dt.installed(); const expectedStr = `dpkg-query --show ${name}=${version.str()} && echo $?`; assert.strictEqual(cmd.str(), expectedStr); }); }); + }); + suite("DebianToolchain", function () { suite("#run()", function () { test("returns Commend with cfg", function () { let dt = new DebianToolchain(info); diff --git a/src/Toolchain/ToolchainEnv.ts b/src/Toolchain/ToolchainEnv.ts index d9e31860..3bdb5a1c 100644 --- a/src/Toolchain/ToolchainEnv.ts +++ b/src/Toolchain/ToolchainEnv.ts @@ -158,7 +158,7 @@ class ToolchainEnv extends Env { public install(toolchain: Toolchain): Promise { return new Promise((resolve, reject) => { const jobs: Array = []; - const job = new JobInstall(toolchain.install()); + const job = new JobInstall(toolchain.tool.install()); job.successCallback = () => resolve(true); job.failureCallback = () => reject(); jobs.push(job); @@ -169,7 +169,7 @@ class ToolchainEnv extends Env { public uninstall(toolchain: Toolchain): Promise { return new Promise((resolve, reject) => { const jobs: Array = []; - const job = new JobUninstall(toolchain.uninstall()); + const job = new JobUninstall(toolchain.tool.uninstall()); job.successCallback = () => resolve(true); job.failureCallback = () => reject(); jobs.push(job); @@ -188,6 +188,54 @@ class ToolchainEnv extends Env { this.executeEnv(jobs); }); } + + public inference( + model: string, + options: Map | undefined, + toolchain: Toolchain + ): Promise { + return new Promise((resolve, reject) => { + const jobs: Array = []; + const job = new JobConfig(toolchain.runInference(model, options)); + job.workDir = path.dirname(model); + job.successCallback = () => resolve(job.result ? job.result : ""); + job.failureCallback = () => reject(); + jobs.push(job); + this.executeEnv(jobs); + }); + } + + public profile( + model: string, + options: Map | undefined, + toolchain: Toolchain + ): Promise { + return new Promise((resolve, reject) => { + const jobs: Array = []; + const job = new JobConfig(toolchain.runProfile(model, options)); + job.workDir = path.dirname(model); + job.successCallback = () => resolve(true); + job.failureCallback = () => reject(); + jobs.push(job); + this.executeEnv(jobs); + }); + } + + public getModelInfo( + model: string, + type: string, + toolchain: Toolchain + ): Promise { + return new Promise((resolve, reject) => { + const jobs: Array = []; + const job = new JobConfig(toolchain.runShow(model, type)); + job.workDir = path.dirname(model); + job.successCallback = () => resolve(job.result ? job.result : ""); + job.failureCallback = () => reject(); + jobs.push(job); + this.executeEnv(jobs); + }); + } } /** diff --git a/src/Toolchain/ToolchainProvider.ts b/src/Toolchain/ToolchainProvider.ts index 697e7864..6baf51e0 100644 --- a/src/Toolchain/ToolchainProvider.ts +++ b/src/Toolchain/ToolchainProvider.ts @@ -44,7 +44,8 @@ export class BaseNode extends vscode.TreeItem { export class BackendNode extends BaseNode { constructor(public readonly label: string) { super(label, vscode.TreeItemCollapsibleState.Expanded); - this.iconPath = new vscode.ThemeIcon("bracket"); + const chartsThemeColor = new vscode.ThemeColor("charts.yellow"); + this.iconPath = new vscode.ThemeIcon("symbol-function", chartsThemeColor); this.contextValue = "backend"; } } @@ -61,10 +62,12 @@ export class ToolchainNode extends BaseNode { ) { super(label, vscode.TreeItemCollapsibleState.None); if (DefaultToolchain.getInstance().isEqual(toolchain)) { - this.iconPath = new vscode.ThemeIcon("layers-active"); + const backendThemeColor = new vscode.ThemeColor("charts.green"); + this.iconPath = new vscode.ThemeIcon("layers", backendThemeColor); this.contextValue = "toolchain-default"; } else { - this.iconPath = new vscode.ThemeIcon("layers"); + const chartsThemeColor = new vscode.ThemeColor("charts.blue"); + this.iconPath = new vscode.ThemeIcon("layers", chartsThemeColor); this.contextValue = "toolchain"; } this.description = toolchain.info.version?.str(); @@ -138,6 +141,15 @@ export class ToolchainProvider implements vscode.TreeDataProvider { vscode.commands.registerCommand("one.toolchain.runCfg", (cfg) => provider.run(cfg) ), + vscode.commands.registerCommand("one.toolchain.inference", (model) => + provider.inference(model) + ), + vscode.commands.registerCommand("one.toolchain.profile", (model) => + provider.profile(model) + ), + vscode.commands.registerCommand("one.toolchain.getModelInfo", (model) => + provider.getModelInfo(model, "target-arch") + ), vscode.commands.registerCommand( "one.toolchain.setDefaultToolchain", (toolchain) => provider.setDefaultToolchain(toolchain) @@ -224,8 +236,8 @@ export class ToolchainProvider implements vscode.TreeDataProvider { .then((answer) => { if (answer === "Yes") { const jobs: Array = []; - jobs.push(new JobUninstall(installed[0].uninstall())); - jobs.push(new JobInstall(toolchain.install())); + jobs.push(new JobUninstall(installed[0].tool.uninstall())); + jobs.push(new JobInstall(toolchain.tool.install())); toolchainEnv.request(jobs).then( () => this._notifyInstalled(toolchainEnv, toolchain), () => this._notifyInstallationError() @@ -276,12 +288,10 @@ export class ToolchainProvider implements vscode.TreeDataProvider { return true; } - public _run(cfg: string): boolean { - /* istanbul ignore next */ - const notifySuccess = () => { - vscode.window.showInformationMessage("Onecc has run successfully."); - }; - + private checkAvailableToolchain(): [ + ToolchainEnv | undefined, + Toolchain | undefined + ] { /* istanbul ignore next */ const notifyGuideline = () => { this.error( @@ -296,26 +306,40 @@ export class ToolchainProvider implements vscode.TreeDataProvider { }); }; - /* istanbul ignore next */ - const notifyError = () => { - this.error("Running onecc has failed."); - }; - const activeToolchainEnv = DefaultToolchain.getInstance().getToolchainEnv(); const activeToolchain = DefaultToolchain.getInstance().getToolchain(); if (!activeToolchainEnv || !activeToolchain) { notifyGuideline(); + return [undefined, undefined]; + } + + return [activeToolchainEnv, activeToolchain]; + } + + public _run(cfg: string): boolean { + /* istanbul ignore next */ + const notifySuccess = () => { + vscode.window.showInformationMessage("Onecc has run successfully."); + }; + + /* istanbul ignore next */ + const notifyError = () => { + this.error("Running onecc has failed."); + }; + + const [toolchainEnv, toolchain] = this.checkAvailableToolchain(); + if (toolchainEnv === undefined || toolchain === undefined) { return false; } Logger.info( this.tag, `Run onecc with ${cfg} cfg and ${ - activeToolchain.info.name - }-${activeToolchain.info.version?.str()} toolchain.` + toolchain.info.name + }-${toolchain.info.version?.str()} toolchain.` ); - activeToolchainEnv.run(cfg, activeToolchain).then( + toolchainEnv.run(cfg, toolchain).then( () => notifySuccess(), () => notifyError() ); @@ -331,6 +355,115 @@ export class ToolchainProvider implements vscode.TreeDataProvider { return false; } + public inference( + model: string, + options?: Map + ): string | undefined { + /* istanbul ignore next */ + const notifySuccess = () => { + vscode.window.showInformationMessage("Inference successfully."); + }; + /* istanbul ignore next */ + const notifyError = () => { + this.error("Inference has failed."); + }; + + const [toolchainEnv, toolchain] = this.checkAvailableToolchain(); + if (toolchainEnv === undefined || toolchain === undefined) { + return; + } + + Logger.info( + this.tag, + `Inference ${model} file using ${ + toolchain.info.name + }-${toolchain.info.version?.str()} toolchain.` + ); + + toolchainEnv.inference(model, options, toolchain).then( + (result: string) => { + notifySuccess(); + return result; + }, + () => { + notifyError(); + } + ); + return; + } + + public profile( + model: string, + options?: Map + ): string | undefined { + /* istanbul ignore next */ + const notifySuccess = () => { + vscode.window.showInformationMessage("Profile successfully."); + }; + /* istanbul ignore next */ + const notifyError = () => { + this.error("Profile has failed."); + }; + + const [toolchainEnv, toolchain] = this.checkAvailableToolchain(); + if (toolchainEnv === undefined || toolchain === undefined) { + return; + } + + Logger.info( + this.tag, + `Profile ${model} file using ${ + toolchain.info.name + }-${toolchain.info.version?.str()} toolchain.` + ); + + toolchainEnv.profile(model, options, toolchain).then( + () => { + notifySuccess(); + }, + () => { + notifyError(); + } + ); + return; + } + + public getModelInfo(model: string, type: string): string | undefined { + /* istanbul ignore next */ + const notifySuccess = () => { + vscode.window.showInformationMessage( + "Get model information successfully." + ); + }; + /* istanbul ignore next */ + const notifyError = () => { + this.error("Running show has failed."); + }; + + const [toolchainEnv, toolchain] = this.checkAvailableToolchain(); + if (toolchainEnv === undefined || toolchain === undefined) { + return; + } + + Logger.info( + this.tag, + `Run show with ${model} file using ${ + toolchain.info.name + }-${toolchain.info.version?.str()} toolchain.` + ); + + toolchainEnv.getModelInfo(model, type, toolchain).then( + (result: string) => { + notifySuccess(); + return result; + }, + () => { + notifyError(); + } + ); + return; + } + public setDefaultToolchain(tnode: ToolchainNode): boolean { const backendName = tnode.backendName; if (!Object.keys(gToolchainEnvMap).includes(backendName)) { diff --git a/src/View/InstallQuickInput.ts b/src/View/InstallQuickInput.ts index 2307848d..7c54a402 100644 --- a/src/View/InstallQuickInput.ts +++ b/src/View/InstallQuickInput.ts @@ -261,8 +261,12 @@ class InstallQuickInput { let finished = true; if (answer === "Yes") { - if (await toolchainEnv.prerequisites()) { - finished = false; + try { + if (await toolchainEnv.prerequisites()) { + finished = false; + } + } catch (err: any) { + vscode.window.showErrorMessage(err.message); } } From 4a5cc6d50dd158beca27b1b93432c22ca89c23ed Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 10 May 2023 17:16:29 +0900 Subject: [PATCH 2/2] draft code for compiler and simulator node Signed-off-by: Jiyoung Yun --- src/Tests/Toolchain/ToolchainProvider.test.ts | 6 ++-- src/Toolchain/ToolchainProvider.ts | 34 +++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Tests/Toolchain/ToolchainProvider.test.ts b/src/Tests/Toolchain/ToolchainProvider.test.ts index 6ffccac5..97f57c57 100644 --- a/src/Tests/Toolchain/ToolchainProvider.test.ts +++ b/src/Tests/Toolchain/ToolchainProvider.test.ts @@ -82,7 +82,7 @@ suite("Toolchain", function () { const toolchain = new DebianToolchain( new ToolchainInfo("npm", "package manager for Node.js") ); - const collapsibleState = vscode.TreeItemCollapsibleState.None; + const collapsibleState = vscode.TreeItemCollapsibleState.Expanded; let node = new ToolchainNode(label, backendName, toolchain); assert.strictEqual(node.label, label); assert.strictEqual(node.collapsibleState, collapsibleState); @@ -102,7 +102,7 @@ suite("Toolchain", function () { [dependencyInfo] ) ); - const collapsibleState = vscode.TreeItemCollapsibleState.None; + const collapsibleState = vscode.TreeItemCollapsibleState.Expanded; let node = new ToolchainNode(label, backendName, toolchain); assert.strictEqual(node.label, label); assert.strictEqual(node.collapsibleState, collapsibleState); @@ -184,7 +184,7 @@ suite("Toolchain", function () { const toolchain = new DebianToolchain( new ToolchainInfo("npm", "package manager for Node.js") ); - const collapsibleState = vscode.TreeItemCollapsibleState.None; + const collapsibleState = vscode.TreeItemCollapsibleState.Expanded; let node = new ToolchainNode(label, backend, toolchain); let provider = new ToolchainProvider(); let treeItem = provider.getTreeItem(node); diff --git a/src/Toolchain/ToolchainProvider.ts b/src/Toolchain/ToolchainProvider.ts index 6baf51e0..2293244d 100644 --- a/src/Toolchain/ToolchainProvider.ts +++ b/src/Toolchain/ToolchainProvider.ts @@ -60,7 +60,7 @@ export class ToolchainNode extends BaseNode { public readonly backend: string, public readonly toolchain: Toolchain ) { - super(label, vscode.TreeItemCollapsibleState.None); + super(label, vscode.TreeItemCollapsibleState.Expanded); if (DefaultToolchain.getInstance().isEqual(toolchain)) { const backendThemeColor = new vscode.ThemeColor("charts.green"); this.iconPath = new vscode.ThemeIcon("layers", backendThemeColor); @@ -80,6 +80,24 @@ export class ToolchainNode extends BaseNode { } } +export class CompilerNode extends BaseNode { + constructor() { + super("compiler", vscode.TreeItemCollapsibleState.None); + const chartsThemeColor = new vscode.ThemeColor("charts.blue"); + this.iconPath = new vscode.ThemeIcon("circuit-board", chartsThemeColor); + this.contextValue = "compiler"; + } +} + +export class SimulatorNode extends BaseNode { + constructor() { + super("simulator", vscode.TreeItemCollapsibleState.None); + const chartsThemeColor = new vscode.ThemeColor("charts.blue"); + this.iconPath = new vscode.ThemeIcon("inspect", chartsThemeColor); + this.contextValue = "simulator"; + } +} + // NodeBuilder creates BackendNodes or ToolchainNodes export class NodeBuilder { static createBackendNodes(): BackendNode[] { @@ -112,6 +130,16 @@ export class NodeBuilder { return tnode; }); } + + static createChildNodes(bnode: BaseNode): BaseNode[] { + if (bnode instanceof ToolchainNode === false) { + return []; + } + + const cnode = new CompilerNode(); + const snode = new SimulatorNode(); + return [cnode, snode]; + } } // ToolchainProvider provides TreeData @@ -168,8 +196,10 @@ export class ToolchainProvider implements vscode.TreeDataProvider { public getChildren(element?: BaseNode): Thenable { if (element === undefined) { return Promise.resolve(NodeBuilder.createBackendNodes()); - } else { + } else if (element instanceof BackendNode === true) { return Promise.resolve(NodeBuilder.createToolchainNodes(element)); + } else { + return Promise.resolve(NodeBuilder.createChildNodes(element)); } }