From b7a2046aef0c1951f04abb7826f4e4f13c459465 Mon Sep 17 00:00:00 2001 From: Chris Gavin Date: Mon, 28 Sep 2020 12:15:06 +0100 Subject: [PATCH] Always exclude the temporary directory from scanning. --- lib/analysis-paths.js | 21 ++++++++++++++++++--- lib/analysis-paths.js.map | 2 +- lib/analysis-paths.test.js | 25 +++++++++++++++++++++++-- lib/analysis-paths.test.js.map | 2 +- lib/analyze.js | 2 +- lib/analyze.js.map | 2 +- src/analysis-paths.test.ts | 26 ++++++++++++++++++++++++-- src/analysis-paths.ts | 16 +++++++++++----- src/analyze.ts | 2 +- 9 files changed, 81 insertions(+), 17 deletions(-) diff --git a/lib/analysis-paths.js b/lib/analysis-paths.js index 87e625ceb3..6099f9895a 100644 --- a/lib/analysis-paths.js +++ b/lib/analysis-paths.js @@ -1,5 +1,13 @@ "use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); +const path = __importStar(require("path")); function isInterpretedLanguage(language) { return language === "javascript" || language === "python"; } @@ -24,7 +32,7 @@ function printPathFiltersWarning(config, logger) { } } exports.printPathFiltersWarning = printPathFiltersWarning; -function includeAndExcludeAnalysisPaths(config) { +function includeAndExcludeAnalysisPaths(config, logger) { // The 'LGTM_INDEX_INCLUDE' and 'LGTM_INDEX_EXCLUDE' environment variables // control which files/directories are traversed when scanning. // This allows including files that otherwise would not be scanned, or @@ -35,8 +43,15 @@ function includeAndExcludeAnalysisPaths(config) { if (config.paths.length !== 0) { process.env["LGTM_INDEX_INCLUDE"] = buildIncludeExcludeEnvVar(config.paths); } - if (config.pathsIgnore.length !== 0) { - process.env["LGTM_INDEX_EXCLUDE"] = buildIncludeExcludeEnvVar(config.pathsIgnore); + // Always ignore the temporary directory. This is required if the runner has been downloaded to the checkout directory of the repository being analyzed. + const tempRelativeToWorking = path.relative(process.cwd(), config.tempDir); + let pathsIgnore = config.pathsIgnore; + if (!tempRelativeToWorking.startsWith("..")) { + logger.warning("Storing the CodeQL Runner in the directory being analyzed is not recommended."); + pathsIgnore = pathsIgnore.concat(config.tempDir); + } + if (pathsIgnore.length !== 0) { + process.env["LGTM_INDEX_EXCLUDE"] = buildIncludeExcludeEnvVar(pathsIgnore); } // The 'LGTM_INDEX_FILTERS' environment variable controls which files are // extracted or ignored. It does not control which directories are traversed. diff --git a/lib/analysis-paths.js.map b/lib/analysis-paths.js.map index f846d4c2e2..d934bf5ba1 100644 --- a/lib/analysis-paths.js.map +++ b/lib/analysis-paths.js.map @@ -1 +1 @@ -{"version":3,"file":"analysis-paths.js","sourceRoot":"","sources":["../src/analysis-paths.ts"],"names":[],"mappings":";;AAGA,SAAS,qBAAqB,CAAC,QAAQ;IACrC,OAAO,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,QAAQ,CAAC;AAC5D,CAAC;AAED,6FAA6F;AAChF,QAAA,+BAA+B,GAAG,cAAc,CAAC;AAE9D,uFAAuF;AACvF,SAAS,yBAAyB,CAAC,KAAe;IAChD,iCAAiC;IACjC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEnD,uDAAuD;IACvD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;QAChC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,uCAA+B,CAAC,CAAC,CAAC;KACvE;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,SAAgB,uBAAuB,CACrC,MAA0B,EAC1B,MAAc;IAEd,oEAAoE;IACpE,sEAAsE;IACtE,IACE,CAAC,MAAM,CAAC,KAAK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js index 1c52637380..3009d3fa01 100644 --- a/lib/analysis-paths.test.js +++ b/lib/analysis-paths.test.js @@ -11,7 +11,9 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const ava_1 = __importDefault(require("ava")); +const path = __importStar(require("path")); const analysisPaths = __importStar(require("./analysis-paths")); +const logging_1 = require("./logging"); const testing_utils_1 = require("./testing-utils"); const util = __importStar(require("./util")); testing_utils_1.setupTests(ava_1.default); @@ -27,7 +29,7 @@ ava_1.default("emptyPaths", async (t) => { toolCacheDir: tmpDir, codeQLCmd: "", }; - analysisPaths.includeAndExcludeAnalysisPaths(config); + analysisPaths.includeAndExcludeAnalysisPaths(config, logging_1.getRunnerLogger(true)); t.is(process.env["LGTM_INDEX_INCLUDE"], undefined); t.is(process.env["LGTM_INDEX_EXCLUDE"], undefined); t.is(process.env["LGTM_INDEX_FILTERS"], undefined); @@ -45,10 +47,29 @@ ava_1.default("nonEmptyPaths", async (t) => { toolCacheDir: tmpDir, codeQLCmd: "", }; - analysisPaths.includeAndExcludeAnalysisPaths(config); + analysisPaths.includeAndExcludeAnalysisPaths(config, logging_1.getRunnerLogger(true)); t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2"); t.is(process.env["LGTM_INDEX_EXCLUDE"], "path4\npath5"); t.is(process.env["LGTM_INDEX_FILTERS"], "include:path1\ninclude:path2\ninclude:**/path3\nexclude:path4\nexclude:path5\nexclude:path6/**"); }); }); +ava_1.default("exclude temp dir", async (t) => { + return await util.withTmpDir(async (toolCacheDir) => { + const tempDir = path.join(process.cwd(), "codeql-runner-temp"); + const config = { + languages: [], + queries: {}, + pathsIgnore: [], + paths: [], + originalUserInput: {}, + tempDir: tempDir, + toolCacheDir: toolCacheDir, + codeQLCmd: "", + }; + analysisPaths.includeAndExcludeAnalysisPaths(config, logging_1.getRunnerLogger(true)); + t.is(process.env["LGTM_INDEX_INCLUDE"], undefined); + t.is(process.env["LGTM_INDEX_EXCLUDE"], tempDir); + t.is(process.env["LGTM_INDEX_FILTERS"], undefined); + }); +}); //# sourceMappingURL=analysis-paths.test.js.map \ No newline at end of file diff --git a/lib/analysis-paths.test.js.map b/lib/analysis-paths.test.js.map index 5feb620b95..6fca4ca08e 100644 --- a/lib/analysis-paths.test.js.map +++ b/lib/analysis-paths.test.js.map @@ -1 +1 @@ -{"version":3,"file":"analysis-paths.test.js","sourceRoot":"","sources":["../src/analysis-paths.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuB;AAEvB,gEAAkD;AAClD,mDAA6C;AAC7C,6CAA+B;AAE/B,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC7B,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,EAAE;YACf,KAAK,EAAE,EAAE;YACT,iBAAiB,EAAE,EAAE;YACrB,OAAO,EAAE,MAAM;YACf,YAAY,EAAE,MAAM;YACpB,SAAS,EAAE,EAAE;SACd,CAAC;QACF,aAAa,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAChC,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC;YACrC,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC;YAC3C,iBAAiB,EAAE,EAAE;YACrB,OAAO,EAAE,MAAM;YACf,YAAY,EAAE,MAAM;YACpB,SAAS,EAAE,EAAE;SACd,CAAC;QACF,aAAa,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,cAAc,CAAC,CAAC;QACxD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,cAAc,CAAC,CAAC;QACxD,CAAC,CAAC,EAAE,CACF,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EACjC,gGAAgG,CACjG,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"analysis-paths.test.js","sourceRoot":"","sources":["../src/analysis-paths.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuB;AACvB,2CAA6B;AAE7B,gEAAkD;AAClD,uCAA4C;AAC5C,mDAA6C;AAC7C,6CAA+B;AAE/B,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC7B,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,EAAE;YACf,KAAK,EAAE,EAAE;YACT,iBAAiB,EAAE,EAAE;YACrB,OAAO,E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oB,CAAC,EACjC,gGAAgG,CACjG,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,kBAAkB,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IACnC,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,oBAAoB,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,EAAE;YACf,KAAK,EAAE,EAAE;YACT,iBAAiB,EAAE,EAAE;YACrB,OAAO,EAAE,OAAO;YAChB,YAAY,EAAE,YAAY;YAC1B,SAAS,EAAE,EAAE;SACd,CAAC;QACF,aAAa,CAAC,8BAA8B,CAAC,MAAM,EAAE,yBAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5E,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/analyze.js b/lib/analyze.js index a8b186514e..1f4d3cd5e5 100644 --- a/lib/analyze.js +++ b/lib/analyze.js @@ -18,7 +18,7 @@ const util = __importStar(require("./util")); async function createdDBForScannedLanguages(config, logger) { // Insert the LGTM_INDEX_X env vars at this point so they are set when // we extract any scanned languages. - analysisPaths.includeAndExcludeAnalysisPaths(config); + analysisPaths.includeAndExcludeAnalysisPaths(config, logger); const codeql = codeql_1.getCodeQL(config.codeQLCmd); for (const language of config.languages) { if (languages_1.isScannedLanguage(language)) { diff --git a/lib/analyze.js.map b/lib/analyze.js.map index 6dbfba9ce4..28c17462d6 100644 --- a/lib/analyze.js.map +++ b/lib/analyze.js.map @@ -1 +1 @@ -{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,gEAAkD;AAClD,qCAAqC;AAErC,2CAAgD;AAGhD,gEAAkD;AAClD,yDAA2C;AAC3C,6CAA+B;AAmC/B,KAAK,UAAU,4BAA4B,CACzC,MAA0B,EAC1B,MAAc;IAEd,sEAAsE;IACtE,oCAAoC;IACpC,aAAa,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;IAErD,MAAM,MAAM,GAAG,kBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,SAAS,EAAE;QACvC,IAAI,6BAAiB,CAAC,QAAQ,CAAC,EAAE;YAC/B,MAAM,CAAC,UAAU,CAAC,cAAc,QAAQ,EAAE,CAAC,CAAC;YAC5C,MAAM,MAAM,CAAC,sBAAsB,CACjC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,EACpD,QAAQ,CACT,CAAC;YACF,MAAM,CAAC,QAAQ,EAAE,CAAC;SACnB;KACF;AACH,CAAC;AAED,KAAK,UAAU,wBAAwB,CACrC,MAA0B,EAC1B,MAAc;IAEd,MAAM,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEnD,MAAM,MAAM,GAAG,kBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,SAAS,EAAE;QACvC,MAAM,CAAC,UAAU,CAAC,cAAc,QAAQ,EAAE,CAAC,CAAC;QAC5C,MAAM,MAAM,CAA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AuB,EACvB,WAAmB,EACnB,MAA0B,EAC1B,MAAc;IAEd,8DAA8D;IAC9D,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAEzD,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7C,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC5C,MAAM,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE/C,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,MAAM,YAAY,GAAG,MAAM,UAAU,CACnC,SAAS,EACT,UAAU,EACV,eAAe,EACf,WAAW,EACX,MAAM,EACN,MAAM,CACP,CAAC;IAEF,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACrC,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;KAC5B;IAED,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,MAAM,CACzC,SAAS,EACT,aAAa,EACb,SAAS,EACT,GAAG,EACH,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,IAAI,EACJ,MAAM,CACP,CAAC;IAEF,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,WAAW,EAAE,CAAC;AAC7C,CAAC;AA5DD,gCA4DC"} \ No newline at end of file +{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,gEAAkD;AAClD,qCAAqC;AAErC,2CAAgD;AAGhD,gEAAkD;AAClD,yDAA2C;AAC3C,6CAA+B;AAmC/B,KAAK,UAAU,4BAA4B,CACzC,MAA0B,EAC1B,MAAc;IAEd,sEAAsE;IACtE,oCAAoC;IACpC,aAAa,CAAC,8BAA8B,CAAC,M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EACN,MAAM,CACP,CAAC;IAEF,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACrC,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;KAC5B;IAED,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,MAAM,CACzC,SAAS,EACT,aAAa,EACb,SAAS,EACT,GAAG,EACH,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,IAAI,EACJ,MAAM,CACP,CAAC;IAEF,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,WAAW,EAAE,CAAC;AAC7C,CAAC;AA5DD,gCA4DC"} \ No newline at end of file diff --git a/src/analysis-paths.test.ts b/src/analysis-paths.test.ts index c84c343d86..2b015852d5 100644 --- a/src/analysis-paths.test.ts +++ b/src/analysis-paths.test.ts @@ -1,6 +1,8 @@ import test from "ava"; +import * as path from "path"; import * as analysisPaths from "./analysis-paths"; +import { getRunnerLogger } from "./logging"; import { setupTests } from "./testing-utils"; import * as util from "./util"; @@ -18,7 +20,7 @@ test("emptyPaths", async (t) => { toolCacheDir: tmpDir, codeQLCmd: "", }; - analysisPaths.includeAndExcludeAnalysisPaths(config); + analysisPaths.includeAndExcludeAnalysisPaths(config, getRunnerLogger(true)); t.is(process.env["LGTM_INDEX_INCLUDE"], undefined); t.is(process.env["LGTM_INDEX_EXCLUDE"], undefined); t.is(process.env["LGTM_INDEX_FILTERS"], undefined); @@ -37,7 +39,7 @@ test("nonEmptyPaths", async (t) => { toolCacheDir: tmpDir, codeQLCmd: "", }; - analysisPaths.includeAndExcludeAnalysisPaths(config); + analysisPaths.includeAndExcludeAnalysisPaths(config, getRunnerLogger(true)); t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2"); t.is(process.env["LGTM_INDEX_EXCLUDE"], "path4\npath5"); t.is( @@ -46,3 +48,23 @@ test("nonEmptyPaths", async (t) => { ); }); }); + +test("exclude temp dir", async (t) => { + return await util.withTmpDir(async (toolCacheDir) => { + const tempDir = path.join(process.cwd(), "codeql-runner-temp"); + const config = { + languages: [], + queries: {}, + pathsIgnore: [], + paths: [], + originalUserInput: {}, + tempDir: tempDir, + toolCacheDir: toolCacheDir, + codeQLCmd: "", + }; + analysisPaths.includeAndExcludeAnalysisPaths(config, getRunnerLogger(true)); + t.is(process.env["LGTM_INDEX_INCLUDE"], undefined); + t.is(process.env["LGTM_INDEX_EXCLUDE"], tempDir); + t.is(process.env["LGTM_INDEX_FILTERS"], undefined); + }); +}); diff --git a/src/analysis-paths.ts b/src/analysis-paths.ts index 084719b191..c9e9b9c157 100644 --- a/src/analysis-paths.ts +++ b/src/analysis-paths.ts @@ -1,3 +1,4 @@ +import * as path from "path"; import * as configUtils from "./config-utils"; import { Logger } from "./logging"; @@ -37,7 +38,7 @@ export function printPathFiltersWarning( } } -export function includeAndExcludeAnalysisPaths(config: configUtils.Config) { +export function includeAndExcludeAnalysisPaths(config: configUtils.Config, logger: Logger) { // The 'LGTM_INDEX_INCLUDE' and 'LGTM_INDEX_EXCLUDE' environment variables // control which files/directories are traversed when scanning. // This allows including files that otherwise would not be scanned, or @@ -48,10 +49,15 @@ export function includeAndExcludeAnalysisPaths(config: configUtils.Config) { if (config.paths.length !== 0) { process.env["LGTM_INDEX_INCLUDE"] = buildIncludeExcludeEnvVar(config.paths); } - if (config.pathsIgnore.length !== 0) { - process.env["LGTM_INDEX_EXCLUDE"] = buildIncludeExcludeEnvVar( - config.pathsIgnore - ); + // Always ignore the temporary directory. This is required if the runner has been downloaded to the checkout directory of the repository being analyzed. + const tempRelativeToWorking = path.relative(process.cwd(), config.tempDir); + let pathsIgnore = config.pathsIgnore; + if (!tempRelativeToWorking.startsWith("..")) { + logger.warning("Storing the CodeQL Runner in the directory being analyzed is not recommended."); + pathsIgnore = pathsIgnore.concat(config.tempDir); + } + if (pathsIgnore.length !== 0) { + process.env["LGTM_INDEX_EXCLUDE"] = buildIncludeExcludeEnvVar(pathsIgnore); } // The 'LGTM_INDEX_FILTERS' environment variable controls which files are diff --git a/src/analyze.ts b/src/analyze.ts index 8b9e80ab6b..07238caf73 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -50,7 +50,7 @@ async function createdDBForScannedLanguages( ) { // Insert the LGTM_INDEX_X env vars at this point so they are set when // we extract any scanned languages. - analysisPaths.includeAndExcludeAnalysisPaths(config); + analysisPaths.includeAndExcludeAnalysisPaths(config, logger); const codeql = getCodeQL(config.codeQLCmd); for (const language of config.languages) {