Skip to content

Commit

Permalink
Merge pull request #236 from github/ignore-temp-dir
Browse files Browse the repository at this point in the history
Exclude the temporary directory from scanning.
  • Loading branch information
chrisgavin authored Oct 5, 2020
2 parents d0afe92 + 11c1460 commit 5cdfcab
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 11 deletions.
22 changes: 20 additions & 2 deletions lib/analysis-paths.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analysis-paths.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions lib/analysis-paths.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analysis-paths.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/analysis-paths.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as path from "path";

import test from "ava";

import * as analysisPaths from "./analysis-paths";
Expand Down Expand Up @@ -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,
toolCacheDir,
codeQLCmd: "",
};
analysisPaths.includeAndExcludeAnalysisPaths(config);
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
t.is(process.env["LGTM_INDEX_EXCLUDE"], "codeql-runner-temp");
t.is(process.env["LGTM_INDEX_FILTERS"], undefined);
});
});
21 changes: 17 additions & 4 deletions src/analysis-paths.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as path from "path";

import * as configUtils from "./config-utils";
import { Logger } from "./logging";

Expand Down Expand Up @@ -48,10 +50,21 @@ 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
);
// If the temporary or tools directory is in the working directory ignore that too.
const tempRelativeToWorking = path.relative(process.cwd(), config.tempDir);
const toolsRelativeToWorking = path.relative(
process.cwd(),
config.toolCacheDir
);
let pathsIgnore = config.pathsIgnore;
if (!tempRelativeToWorking.startsWith("..")) {
pathsIgnore = pathsIgnore.concat(tempRelativeToWorking);
}
if (!toolsRelativeToWorking.startsWith("..")) {
pathsIgnore = pathsIgnore.concat(toolsRelativeToWorking);
}
if (pathsIgnore.length !== 0) {
process.env["LGTM_INDEX_EXCLUDE"] = buildIncludeExcludeEnvVar(pathsIgnore);
}

// The 'LGTM_INDEX_FILTERS' environment variable controls which files are
Expand Down

0 comments on commit 5cdfcab

Please sign in to comment.