Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Support tv2-show #1552

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 43 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
},
Expand Down
6 changes: 5 additions & 1 deletion src/Backend/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ class CompilerBase implements Compiler {
}
}

export { Compiler, CompilerBase };
interface ICompilerCommand {
run(cfg: string): Command;
}

export { Compiler, CompilerBase, ICompilerCommand };
11 changes: 10 additions & 1 deletion src/Backend/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>): Command;

runProfile(model: string, options?: Map<string, string>): Command;

runShow(model: string, option: string): Command;
}

export { Executor, ExecutorBase, IExecutorCommand };
1 change: 0 additions & 1 deletion src/Backend/One/OneToolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
60 changes: 51 additions & 9 deletions src/Backend/Toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

import { Command } from "./Command";
import { ICompilerCommand } from "./Compiler";
import { IExecutorCommand } from "./Executor";
import { Version } from "./Version";

class PackageInfo {
Expand Down Expand Up @@ -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<T extends IToolCommand>
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<ToolCommand> {
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<string, string>): Command {
throw new Error("Method not implemented.");
}
runProfile(_model: string, _options?: Map<string, string>): Command {
throw new Error("Method not implemented.");
}
runShow(_model: string, _option: string): Command {
throw new Error("Method not implemented.");
}
}

Expand All @@ -77,4 +111,12 @@ class Toolchain {
// TODO: Support filter(), where(), filter(regex) or orderBy()
class Toolchains extends Array<Toolchain> {}

export { PackageInfo, ToolchainInfo, Toolchain, Toolchains };
export {
PackageInfo,
ToolchainInfo,
Toolchain,
Toolchains,
ToolCommand,
IToolCommand,
IToolchain,
};
42 changes: 21 additions & 21 deletions src/Backend/ToolchainImpl/DebianToolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -124,13 +107,30 @@ class DebianToolchain implements Toolchain {
cmd.push("echo $?");
return cmd;
}
}

class DebianToolchain implements IToolchain<DebianTool> {
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<string, string>): Command {
throw new Error("Method not implemented.");
}
runProfile(_model: string, _options?: Map<string, string>): 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 };
1 change: 1 addition & 0 deletions src/Job/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Job {
root: boolean;
workDir: string;
isCancelable: boolean;
result?: string;
successCallback?: JobCallback;
failureCallback?: JobCallback;
}
Expand Down
1 change: 1 addition & 0 deletions src/Job/JobCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class JobCommand implements Job {
root: boolean;
workDir: string;
isCancelable: boolean;
result?: string;
successCallback?: JobCallback;
failureCallback?: JobCallback;

Expand Down
1 change: 1 addition & 0 deletions src/Job/JobRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class JobRunner extends EventEmitter {
}

if (success !== undefined) {
job.result = value.output;
success();
}
// Move on to next job
Expand Down
7 changes: 6 additions & 1 deletion src/Job/ToolRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -59,13 +61,16 @@ 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<SuccessResult>) => void,
reject: (value: ErrorResult | PromiseLike<ErrorResult>) => void,
root: boolean
) {
// stdout
this.child!.stdout.on(K_DATA, (data: any) => {
this.output = this.output.concat(data.toString());
Logger.append(data.toString());
});
// stderr
Expand Down Expand Up @@ -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("");
Expand Down
27 changes: 27 additions & 0 deletions src/MetadataViewer/MetadataViewerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
];

Expand Down
Loading