Merge pull request #1617 from pseyfert/2019-10-08-clang-tidy-includes

[WIP] pass include flags to clang-tidy
This commit is contained in:
Patrick Quist
2019-10-10 17:37:32 +02:00
committed by GitHub
2 changed files with 37 additions and 5 deletions
+22
View File
@@ -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);
+15 -5
View File
@@ -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")