| 33 | import {BaseTool} from './base-tool.js'; |
| 34 | |
| 35 | export class CompilerDropinTool extends BaseTool { |
| 36 | static get key() { |
| 37 | return 'compiler-dropin-tool'; |
| 38 | } |
| 39 | |
| 40 | constructor(toolInfo: ToolInfo, env: ToolEnv) { |
| 41 | super(toolInfo, env); |
| 42 | |
| 43 | this.addOptionsToToolArgs = false; |
| 44 | } |
| 45 | |
| 46 | getToolchainPath(compilationInfo: CompilationInfo): string | undefined { |
| 47 | return getToolchainPath(compilationInfo.compiler.exe, compilationInfo.compiler.options); |
| 48 | } |
| 49 | |
| 50 | getOrderedArguments( |
| 51 | compilationInfo: CompilationInfo, |
| 52 | includeflags: string[], |
| 53 | libOptions: string[], |
| 54 | args?: string[], |
| 55 | sourcefile?: string, |
| 56 | ): string[] | false { |
| 57 | // order should be: |
| 58 | // 1) options from the compiler config (compilationInfo.compiler.options) |
| 59 | // 2) includes from the libraries (includeflags) |
| 60 | // 3) options from the tool config (this.tool.options) |
| 61 | // 4) options manually specified in the compiler tab (options) |
| 62 | // 5) flags from the clang-tidy tab |
| 63 | let compileFlags: string[] = []; |
| 64 | const argsToFilterOut = new Set([sourcefile, '-stdlib=libc++']); |
| 65 | |
| 66 | const toolchainPath = this.getToolchainPath(compilationInfo); |
| 67 | |
| 68 | let compilerOptions = compilationInfo.compiler.options ? splitArguments(compilationInfo.compiler.options) : []; |
| 69 | |
| 70 | if (toolchainPath) { |
| 71 | // note: needs toolchain argument twice as the first time its sometimes ignored |
| 72 | compileFlags = compileFlags.concat(['--gcc-toolchain=' + toolchainPath]); |
| 73 | compileFlags = compileFlags.concat(['--gcc-toolchain=' + toolchainPath]); |
| 74 | |
| 75 | compilerOptions = compilerOptions.filter(option => { |
| 76 | return !(option.indexOf('--gcc-toolchain=') === 0 || option.indexOf('--gxx-name=') === 0); |
| 77 | }); |
| 78 | } else { |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | compilerOptions = compilerOptions.filter(option => !argsToFilterOut.has(option)); |
| 83 | |
| 84 | compileFlags = compileFlags.concat(compilerOptions); |
| 85 | compileFlags = compileFlags.concat(includeflags); |
| 86 | |
| 87 | const manualCompileFlags = compilationInfo.options.filter((option: string) => !argsToFilterOut.has(option)); |
| 88 | compileFlags = compileFlags.concat(manualCompileFlags); |
| 89 | const toolOptions = this.tool.options || []; |
| 90 | compileFlags = compileFlags.concat(toolOptions); |
| 91 | compileFlags = compileFlags.concat(libOptions); |
| 92 | compileFlags = compileFlags.concat(args || []); |
nothing calls this directly
no outgoing calls
no test coverage detected