diff --git a/lib/tooling/base-tool.js b/lib/tooling/base-tool.js index 349c92074..6543defae 100644 --- a/lib/tooling/base-tool.js +++ b/lib/tooling/base-tool.js @@ -26,6 +26,7 @@ const exec = require('../exec'), utils = require('../utils'), + _ = require('underscore'), logger = require('../logger').logger, path = require('path'); @@ -70,6 +71,27 @@ class BaseTool { }; } + // mostly copy&paste from base-compiler.js + findLibVersion(selectedLib, compiler) { + const foundLib = _.find(compiler.libs, (o, libId) => libId === selectedLib.id); + if (!foundLib) return false; + + const foundVersion = _.find(foundLib.versions, (o, versionId) => versionId === selectedLib.version); + return foundVersion; + } + + // mostly copy&paste from base-compiler.js + getIncludeArguments(libraries, compiler) { + const includeFlag = "-I"; + + return _.flatten(_.map(libraries, (selectedLib) => { + const foundVersion = this.findLibVersion(selectedLib, compiler); + if (!foundVersion) return false; + + return _.map(foundVersion.path, (path) => includeFlag + path); + })); + } + runTool(compilationInfo, inputFilepath, args, stdin) { let execOptions = this.getDefaultExecOptions(); if (inputFilepath) execOptions.customCwd = path.dirname(inputFilepath); diff --git a/lib/tooling/clang-tidy-tool.js b/lib/tooling/clang-tidy-tool.js index 56e8ab5f3..4d6f96361 100644 --- a/lib/tooling/clang-tidy-tool.js +++ b/lib/tooling/clang-tidy-tool.js @@ -35,9 +35,9 @@ class ClangTidyTool extends BaseTool { runTool(compilationInfo, inputFilepath, args) { const sourcefile = inputFilepath; - const compilerExe = compilationInfo.compiler.exe; const options = compilationInfo.options; const dir = path.dirname(sourcefile); + const includeflags = super.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler); let source; const wantsFix = args.find(option => option.includes("-fix")); @@ -48,11 +48,21 @@ class ClangTidyTool extends BaseTool { source = data.toString(); } - const compileFlags = options.filter(option => (option !== sourcefile)); - if (!compilerExe.includes("clang++")) { - compileFlags.push(this.tool.options); - } + // order should be: + // 1) options from the compiler config (compilationInfo.compiler.options) + // 2) includes from the libraries (includeflags) + // ?) options from the tool config (this.tool.options) + // -> before my patchup this was done only for non-clang compilers + // 3) options manually specified in the compiler tab (options) + // *) indepenent are `args` from the clang-tidy tab + let compileFlags = compilationInfo.compiler.options.split(" "); + compileFlags = compileFlags.concat(includeflags); + const manualCompileFlags = options.filter(option => (option !== sourcefile)); + compileFlags = compileFlags.concat(manualCompileFlags); + compileFlags = compileFlags.concat(this.tool.options); + + // TODO: do we want compile_flags.txt rather than prefixing everything with -extra-arg= return fs.writeFile( path.join(dir, "compile_flags.txt"), compileFlags.join("\n")