diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index 40fb98675f3..2fc2098eede 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -76,8 +76,9 @@ import {IAsmParser} from './parsers/asm-parser.interfaces'; import {LlvmPassDumpParser} from './parsers/llvm-pass-dump-parser'; import {PropertyGetter} from './properties.interfaces'; import {getToolchainPath} from './toolchain-utils'; -import {Tool, ToolResult, ToolTypeKey} from './tooling/base-tool.interface'; +import {ITool, ToolResult} from './tooling/base-tool.interface'; import * as utils from './utils'; +import {Tool, ToolTypeKey} from '../types/tool.interfaces'; export class BaseCompiler implements ICompiler { protected compiler: CompilerInfo & Record; // TODO: Some missing types still present in Compiler type @@ -96,7 +97,7 @@ export class BaseCompiler implements ICompiler { protected llvmAst: LlvmAstParser; protected toolchainPath: any; public possibleArguments: CompilerArguments; - protected possibleTools: Tool[]; + protected possibleTools: ITool[]; protected demanglerClass: any; protected objdumperClass: any; public outputFilebase: string; @@ -147,7 +148,7 @@ export class BaseCompiler implements ICompiler { this.toolchainPath = getToolchainPath(this.compiler.exe, this.compiler.options); this.possibleArguments = new CompilerArguments(this.compiler.id); - this.possibleTools = _.values(compilerInfo.tools); + this.possibleTools = _.values(compilerInfo.tools) as ITool[]; const demanglerExe = this.compiler.demangler; if (demanglerExe && this.compiler.demanglerType) { this.demanglerClass = getDemanglerTypeByKey(this.compiler.demanglerType); @@ -1361,7 +1362,7 @@ export class BaseCompiler implements ICompiler { if (tools) { for (const tool of tools) { const matches = this.possibleTools.find(possibleTool => { - return possibleTool.getId() === tool.id && possibleTool.getType() === type; + return possibleTool.id === tool.id && possibleTool.type === type; }); if (matches) { diff --git a/lib/options-handler.ts b/lib/options-handler.ts index 02f34f1863b..354a2e35de7 100755 --- a/lib/options-handler.ts +++ b/lib/options-handler.ts @@ -36,8 +36,8 @@ import {CompilerProps} from './properties'; import {PropertyGetter, PropertyValue} from './properties.interfaces'; import {Source} from './sources'; import {BaseTool, getToolTypeByKey} from './tooling'; -import {ToolTypeKey} from './tooling/base-tool.interface'; import {asSafeVer, getHash, splitArguments, splitIntoArray} from './utils'; +import {ToolTypeKey} from '../types/tool.interfaces'; // TODO: There is surely a better name for this type. Used both here and in the compiler finder. export type OptionHandlerArguments = { diff --git a/lib/tooling/base-tool.interface.ts b/lib/tooling/base-tool.interface.ts index 1d690ef5a9c..6c92a618f4c 100755 --- a/lib/tooling/base-tool.interface.ts +++ b/lib/tooling/base-tool.interface.ts @@ -25,25 +25,7 @@ import {LanguageKey} from '../../types/languages.interfaces'; import {Library} from '../../types/libraries/libraries.interfaces'; import {ResultLine} from '../../types/resultline/resultline.interfaces'; - -export type ToolTypeKey = 'independent' | 'postcompilation'; - -export type ToolInfo = { - id: string; - name?: string; - type?: ToolTypeKey; - exe: string; - exclude: string[]; - includeKey?: string; - options: string[]; - args?: string; - languageId?: LanguageKey; - stdinHint?: string; - monacoStdin?: string; - icon?: string; - darkIcon?: string; - compilerLanguage: LanguageKey; -}; +import {Tool, ToolInfo} from '../../types/tool.interfaces'; export type ToolEnv = { ceProps: (key: string, defaultValue?: any) => string | boolean | number | undefined; @@ -67,13 +49,7 @@ export type ToolResult = { artifact?: Artifact; }; -export interface Tool { - readonly tool: ToolInfo; - - getId(): string; - - getType(): string; - +export interface ITool extends Tool { runTool( compilationInfo: Record, inputFilepath?: string, diff --git a/lib/tooling/base-tool.ts b/lib/tooling/base-tool.ts index e3f2e5ba9ca..dd2f1718ef3 100755 --- a/lib/tooling/base-tool.ts +++ b/lib/tooling/base-tool.ts @@ -35,7 +35,8 @@ import * as exec from '../exec'; import {logger} from '../logger'; import {parseOutput} from '../utils'; -import {Tool, ToolEnv, ToolInfo, ToolResult, ToolTypeKey} from './base-tool.interface'; +import {ITool, ToolEnv, ToolResult} from './base-tool.interface'; +import {ToolInfo, ToolTypeKey} from '../../types/tool.interfaces'; const toolCounter = new PromClient.Counter({ name: 'tool_invocations_total', @@ -43,23 +44,19 @@ const toolCounter = new PromClient.Counter({ labelNames: ['language', 'name'], }); -export class BaseTool implements Tool { +export class BaseTool implements ITool { public readonly tool: ToolInfo; private env: ToolEnv; protected addOptionsToToolArgs = true; + public readonly id: string; + public readonly type: string; constructor(toolInfo: ToolInfo, env: ToolEnv) { this.tool = toolInfo; this.env = env; this.addOptionsToToolArgs = true; - } - - getId() { - return this.tool.id; - } - - getType(): ToolTypeKey { - return this.tool.type || 'independent'; + this.id = toolInfo.id; + this.type = toolInfo.type || 'independent'; } getUniqueFilePrefix() { diff --git a/static/panes/compiler.ts b/static/panes/compiler.ts index 35b1c72aaa0..ca61403e8ef 100644 --- a/static/panes/compiler.ts +++ b/static/panes/compiler.ts @@ -52,7 +52,6 @@ import {ComponentConfig, ToolViewState} from '../components.interfaces'; import {FiledataPair} from '../multifile-service'; import {LanguageLibs} from '../options.interfaces'; import {GccDumpFiltersState, GccDumpViewSelectedPass} from './gccdump-view.interfaces'; -import {Tool} from '../../lib/tooling/base-tool.interface'; import {AssemblyInstructionInfo} from '../../lib/asm-docs/base'; import {PPOptions} from './pp-view.interfaces'; import {CompilationStatus} from '../compiler-service.interfaces'; @@ -64,6 +63,7 @@ import * as utils from '../utils'; import * as Sentry from '@sentry/browser'; import {editor} from 'monaco-editor'; import IEditorMouseEvent = editor.IEditorMouseEvent; +import {Tool} from '../../types/tool.interfaces'; const toolIcons = require.context('../../views/resources/logos', false, /\.(png|svg)$/); diff --git a/test/options-handler.js b/test/options-handler.js index 49f50745deb..ed394ed5bd8 100644 --- a/test/options-handler.js +++ b/test/options-handler.js @@ -515,6 +515,8 @@ describe('Options handler', () => { tools.should.deep.equal({ fake: { faketool: { + id: 'faketool', + type: 'independent', addOptionsToToolArgs: true, tool: { args: undefined, @@ -534,6 +536,8 @@ describe('Options handler', () => { }, }, someothertool: { + id: 'someothertool', + type: 'independent', addOptionsToToolArgs: true, tool: { args: undefined, diff --git a/types/compiler.interfaces.ts b/types/compiler.interfaces.ts index 78f072dd76c..9039d87e86b 100644 --- a/types/compiler.interfaces.ts +++ b/types/compiler.interfaces.ts @@ -23,10 +23,10 @@ // POSSIBILITY OF SUCH DAMAGE. import {CompilerArguments} from '../lib/compiler-arguments'; -import {Tool, ToolInfo} from '../lib/tooling/base-tool.interface'; import {Language} from './languages.interfaces'; import {Library} from './libraries/libraries.interfaces'; +import {Tool, ToolInfo} from './tool.interfaces'; export type CompilerInfo = { id: string; diff --git a/types/tool.interfaces.ts b/types/tool.interfaces.ts new file mode 100644 index 00000000000..70abeb3f9f5 --- /dev/null +++ b/types/tool.interfaces.ts @@ -0,0 +1,50 @@ +// Copyright (c) 2022, Compiler Explorer Authors +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import {LanguageKey} from './languages.interfaces'; + +export type ToolTypeKey = 'independent' | 'postcompilation'; + +export type ToolInfo = { + id: string; + name?: string; + type?: ToolTypeKey; + exe: string; + exclude: string[]; + includeKey?: string; + options: string[]; + args?: string; + languageId?: LanguageKey; + stdinHint?: string; + monacoStdin?: string; + icon?: string; + darkIcon?: string; + compilerLanguage: LanguageKey; +}; + +export type Tool = { + readonly tool: ToolInfo; + readonly id: string; + readonly type: string; +};