From dd57fe328acca9060e1591a1f69c8be96749dc05 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Wed, 2 Oct 2019 00:03:51 +0200 Subject: [PATCH 1/5] clang-tidy include paths bodgeup --- lib/tooling/clang-tidy-tool.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/tooling/clang-tidy-tool.js b/lib/tooling/clang-tidy-tool.js index 56e8ab5f3..e9dca636c 100644 --- a/lib/tooling/clang-tidy-tool.js +++ b/lib/tooling/clang-tidy-tool.js @@ -26,6 +26,8 @@ const fs = require('fs-extra'), path = require('path'), + _ = require('underscore'), + logger = require('../logger').logger, BaseTool = require('./base-tool'); class ClangTidyTool extends BaseTool { @@ -33,12 +35,35 @@ class ClangTidyTool extends BaseTool { super(toolInfo, env); } + // mostly copy&paste from bse-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 bse-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) { const sourcefile = inputFilepath; const compilerExe = compilationInfo.compiler.exe; const options = compilationInfo.options; const dir = path.dirname(sourcefile); + const includeflags = this.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler); + let source; const wantsFix = args.find(option => option.includes("-fix")); if (wantsFix) { @@ -52,7 +77,10 @@ class ClangTidyTool extends BaseTool { if (!compilerExe.includes("clang++")) { compileFlags.push(this.tool.options); } + // FIXME: map is surely the wrong tool here, but pseyfert is very unfamiliar with js so copy&pasted it together like that + _.map(includeflags, (flag) => compileFlags.push(flag)); + // 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") From ecb1e0e0de6df2693fba8a27f230c94356acfb85 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Mon, 7 Oct 2019 16:17:16 +0200 Subject: [PATCH 2/5] updated clang-tidy handling --- lib/tooling/clang-tidy-tool.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/tooling/clang-tidy-tool.js b/lib/tooling/clang-tidy-tool.js index e9dca636c..4a1f43b56 100644 --- a/lib/tooling/clang-tidy-tool.js +++ b/lib/tooling/clang-tidy-tool.js @@ -63,6 +63,7 @@ class ClangTidyTool extends BaseTool { const dir = path.dirname(sourcefile); const includeflags = this.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler); + // logger.warn(`compiler options ${compilationInfo.compiler.options}`) let source; const wantsFix = args.find(option => option.includes("-fix")); @@ -73,14 +74,34 @@ class ClangTidyTool extends BaseTool { source = data.toString(); } - const compileFlags = options.filter(option => (option !== sourcefile)); - if (!compilerExe.includes("clang++")) { - compileFlags.push(this.tool.options); - } - // FIXME: map is surely the wrong tool here, but pseyfert is very unfamiliar with js so copy&pasted it together like that - _.map(includeflags, (flag) => compileFlags.push(flag)); + // 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) + // 3) options manually specified in the compiler tab (options) + // *) indepenent are `args` from the clang-tidy tab + // let compileFlags = [compilationInfo.compiler.options]; + 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); + + + // var toType = function(obj) { + // return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() + // } + // + // logger.warn(`compileFlags[0] is a ${toType(compileFlags[0])} while manualCompileFlags[0] is a ${toType(manualCompileFlags[0])}`) + + // FIXME: this does not do the job in my setup + // if (!compilerExe.includes("clang++")) { + // compileFlags.push(this.tool.options); + // } // TODO: do we want compile_flags.txt rather than prefixing everything with -extra-arg= + // logger.warn(`compile_flags.txt contains ${compileFlags.join("\n")}`); return fs.writeFile( path.join(dir, "compile_flags.txt"), compileFlags.join("\n") From 6bdff246660e1e0bb8d1807c87165cc2715fd556 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Tue, 8 Oct 2019 20:41:43 +0200 Subject: [PATCH 3/5] cleanup for pull request --- lib/tooling/clang-tidy-tool.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/lib/tooling/clang-tidy-tool.js b/lib/tooling/clang-tidy-tool.js index 4a1f43b56..6b268ab0c 100644 --- a/lib/tooling/clang-tidy-tool.js +++ b/lib/tooling/clang-tidy-tool.js @@ -27,7 +27,6 @@ const fs = require('fs-extra'), path = require('path'), _ = require('underscore'), - logger = require('../logger').logger, BaseTool = require('./base-tool'); class ClangTidyTool extends BaseTool { @@ -61,9 +60,7 @@ class ClangTidyTool extends BaseTool { const compilerExe = compilationInfo.compiler.exe; const options = compilationInfo.options; const dir = path.dirname(sourcefile); - const includeflags = this.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler); - // logger.warn(`compiler options ${compilationInfo.compiler.options}`) let source; const wantsFix = args.find(option => option.includes("-fix")); @@ -78,9 +75,9 @@ class ClangTidyTool extends BaseTool { // 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]; let compileFlags = compilationInfo.compiler.options.split(" "); compileFlags = compileFlags.concat(includeflags); @@ -88,20 +85,7 @@ class ClangTidyTool extends BaseTool { compileFlags = compileFlags.concat(manualCompileFlags); compileFlags = compileFlags.concat(this.tool.options); - - // var toType = function(obj) { - // return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() - // } - // - // logger.warn(`compileFlags[0] is a ${toType(compileFlags[0])} while manualCompileFlags[0] is a ${toType(manualCompileFlags[0])}`) - - // FIXME: this does not do the job in my setup - // if (!compilerExe.includes("clang++")) { - // compileFlags.push(this.tool.options); - // } - // TODO: do we want compile_flags.txt rather than prefixing everything with -extra-arg= - // logger.warn(`compile_flags.txt contains ${compileFlags.join("\n")}`); return fs.writeFile( path.join(dir, "compile_flags.txt"), compileFlags.join("\n") From 82a424ead904867f7923f9e9069be10276f57260 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Tue, 8 Oct 2019 20:54:57 +0200 Subject: [PATCH 4/5] linter --- lib/tooling/clang-tidy-tool.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tooling/clang-tidy-tool.js b/lib/tooling/clang-tidy-tool.js index 6b268ab0c..85ef8fb12 100644 --- a/lib/tooling/clang-tidy-tool.js +++ b/lib/tooling/clang-tidy-tool.js @@ -57,7 +57,6 @@ 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 = this.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler); From 6252b352135b028cb268006291a91a2a57714621 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Wed, 9 Oct 2019 18:28:52 +0200 Subject: [PATCH 5/5] review comment --- lib/tooling/base-tool.js | 22 ++++++++++++++++++++++ lib/tooling/clang-tidy-tool.js | 24 +----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/tooling/base-tool.js b/lib/tooling/base-tool.js index d51c2e7f0..55110c92c 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 85ef8fb12..4d6f96361 100644 --- a/lib/tooling/clang-tidy-tool.js +++ b/lib/tooling/clang-tidy-tool.js @@ -26,7 +26,6 @@ const fs = require('fs-extra'), path = require('path'), - _ = require('underscore'), BaseTool = require('./base-tool'); class ClangTidyTool extends BaseTool { @@ -34,32 +33,11 @@ class ClangTidyTool extends BaseTool { super(toolInfo, env); } - // mostly copy&paste from bse-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 bse-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) { const sourcefile = inputFilepath; const options = compilationInfo.options; const dir = path.dirname(sourcefile); - const includeflags = this.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler); + const includeflags = super.getIncludeArguments(compilationInfo.libraries, compilationInfo.compiler); let source; const wantsFix = args.find(option => option.includes("-fix"));