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

[Backend] Remove executors #1636

Merged
merged 2 commits into from
Sep 14, 2023
Merged
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
27 changes: 1 addition & 26 deletions src/Backend/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const assert = require("assert");
import { Backend } from "./Backend";
import { gToolchainEnvMap, ToolchainEnv } from "../Toolchain/ToolchainEnv";
import { Logger } from "../Utils/Logger";
import { Executor } from "./Executor";

/**
* Interface of backend map
Expand All @@ -32,8 +31,6 @@ interface BackendMap {
// TODO Move outside API.ts
// List of backend extensions registered
let globalBackendMap: BackendMap = {};
// List of Executor extensions registered
let globalExecutorArray: Executor[] = [];

const logTag = "API";

Expand All @@ -57,10 +54,6 @@ const registerBackend = (backend: Backend) => {
"enabled"
);
}
const executor = backend.executor();
if (executor) {
globalExecutorArray.push(executor);
}

Logger.info(
logTag,
Expand All @@ -76,26 +69,8 @@ const registerBackend = (backend: Backend) => {
vscode.commands.executeCommand("one.device.refresh");
};

const registerExecutor = (executor: Executor) => {
globalExecutorArray.push(executor);
Logger.info(
"API",
"Executor",
executor.name(),
"was registered into ONE-vscode."
);

// NOTE: This might not 100% guaratee the activating extension has been done.
// - link: https://github.com/Samsung/ONE-vscode/pull/1101#issuecomment-1195099002
// TODO: Consider better way to refresh toolchainView after backend's registration.
vscode.commands.executeCommand("one.device.refresh");
};

// TODO Add removeBackend

export const API = {
registerBackend,
registerExecutor,
};

export { globalBackendMap, globalExecutorArray };
export { globalBackendMap };
31 changes: 1 addition & 30 deletions src/Tests/Backend/Backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { assert } from "chai";

import { API, globalBackendMap, globalExecutorArray } from "../../Backend/API";
import { API, globalBackendMap } from "../../Backend/API";
import { Backend } from "../../Backend/Backend";
import { Compiler, CompilerBase } from "../../Backend/Compiler";
import { Executor, ExecutorBase } from "../../Backend/Executor";
Expand Down Expand Up @@ -47,19 +47,11 @@ class BackendMockup implements Backend {
}
}

const executorName = "Mockup";
class ExecutorMockup extends ExecutorBase {
name(): string {
return executorName;
}
}

suite("Backend", function () {
suite("backendAPI", function () {
test("registers a OneToolchain", function () {
let oneBackend = new OneToolchain();
assert.strictEqual(Object.entries(globalBackendMap).length, 1);
assert.strictEqual(globalExecutorArray.length, 0);

const entries = Object.entries(globalBackendMap);
assert.strictEqual(entries.length, 1);
Expand All @@ -71,7 +63,6 @@ suite("Backend", function () {
});
test("registers a backend", function () {
assert.strictEqual(Object.entries(globalBackendMap).length, 1);
assert.strictEqual(globalExecutorArray.length, 0);

let backend = new BackendMockup();
API.registerBackend(backend);
Expand All @@ -86,23 +77,6 @@ suite("Backend", function () {
assert.deepStrictEqual(value, backend);
}
}

assert.strictEqual(globalExecutorArray.length, 1);
for (const executor of globalExecutorArray) {
assert.deepStrictEqual(executor, backend.executor());
}
assert.deepStrictEqual(backend.executors(), globalExecutorArray);
});
test("registers a executor", function () {
assert.strictEqual(globalExecutorArray.length, 0);
let executorMockup = new ExecutorMockup();
API.registerExecutor(executorMockup);

assert.strictEqual(globalExecutorArray.length, 1);

for (const executor of globalExecutorArray) {
assert.deepStrictEqual(executor, executorMockup);
}
});
});

Expand All @@ -113,8 +87,5 @@ suite("Backend", function () {
if (gToolchainEnvMap[backendName] !== undefined) {
delete gToolchainEnvMap[backendName];
}
while (globalExecutorArray.length > 0) {
globalExecutorArray.pop();
}
});
});