Skip to content

Commit b2bdcdb

Browse files
authored
Merge pull request #3210 from github/koesie10/no-cycle
Remove all dependency cycles
2 parents 37c3b03 + f21ee51 commit b2bdcdb

37 files changed

+285
-278
lines changed

extensions/ql-vscode/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const baseConfig = {
6363
"github/array-foreach": "off",
6464
"github/no-then": "off",
6565
"react/jsx-key": ["error", { checkFragmentShorthand: true }],
66-
"import/no-cycle": "off",
66+
"import/no-cycle": "error",
6767
// Never allow extensions in import paths, except for JSON files where they are required.
6868
"import/extensions": ["error", "never", { json: "always" }],
6969
},
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { execFile } from "child_process";
2+
import { promisify } from "util";
3+
4+
import type { BaseLogger } from "../common/logging";
5+
import type { ProgressReporter } from "../common/logging/vscode";
6+
import { getChildProcessErrorMessage } from "../common/helpers-pure";
7+
8+
/**
9+
* Flags to pass to all cli commands.
10+
*/
11+
export const LOGGING_FLAGS = ["-v", "--log-to-stderr"];
12+
13+
/**
14+
* Runs a CodeQL CLI command without invoking the CLI server, returning the output as a string.
15+
* @param codeQlPath The path to the CLI.
16+
* @param command The `codeql` command to be run, provided as an array of command/subcommand names.
17+
* @param commandArgs The arguments to pass to the `codeql` command.
18+
* @param description Description of the action being run, to be shown in log and error messages.
19+
* @param logger Logger to write command log messages, e.g. to an output channel.
20+
* @param progressReporter Used to output progress messages, e.g. to the status bar.
21+
* @returns The contents of the command's stdout, if the command succeeded.
22+
*/
23+
export async function runCodeQlCliCommand(
24+
codeQlPath: string,
25+
command: string[],
26+
commandArgs: string[],
27+
description: string,
28+
logger: BaseLogger,
29+
progressReporter?: ProgressReporter,
30+
): Promise<string> {
31+
// Add logging arguments first, in case commandArgs contains positional parameters.
32+
const args = command.concat(LOGGING_FLAGS).concat(commandArgs);
33+
const argsString = args.join(" ");
34+
try {
35+
if (progressReporter !== undefined) {
36+
progressReporter.report({ message: description });
37+
}
38+
void logger.log(
39+
`${description} using CodeQL CLI: ${codeQlPath} ${argsString}...`,
40+
);
41+
const result = await promisify(execFile)(codeQlPath, args);
42+
void logger.log(result.stderr);
43+
void logger.log("CLI command succeeded.");
44+
return result.stdout;
45+
} catch (err) {
46+
throw new Error(
47+
`${description} failed: ${getChildProcessErrorMessage(err)}`,
48+
);
49+
}
50+
}

extensions/ql-vscode/src/codeql-cli/cli-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { SemVer } from "semver";
22
import { parse } from "semver";
3-
import { runCodeQlCliCommand } from "./cli";
3+
import { runCodeQlCliCommand } from "./cli-command";
44
import type { Logger } from "../common/logging";
55
import { getErrorMessage } from "../common/helpers-pure";
66

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { EOL } from "os";
22
import { spawn } from "child-process-promise";
33
import type { ChildProcessWithoutNullStreams } from "child_process";
4-
import { execFile, spawn as spawnChildProcess } from "child_process";
4+
import { spawn as spawnChildProcess } from "child_process";
55
import { readFile } from "fs-extra";
66
import { delimiter, dirname, join } from "path";
77
import type { Log } from "sarif";
88
import { SemVer } from "semver";
99
import type { Readable } from "stream";
1010
import tk from "tree-kill";
11-
import { promisify } from "util";
1211
import type { CancellationToken, Disposable, Uri } from "vscode";
1312

1413
import type {
@@ -21,7 +20,6 @@ import type { DistributionProvider } from "./distribution";
2120
import { FindDistributionResultKind } from "./distribution";
2221
import {
2322
assertNever,
24-
getChildProcessErrorMessage,
2523
getErrorMessage,
2624
getErrorStack,
2725
} from "../common/helpers-pure";
@@ -35,6 +33,7 @@ import type { App } from "../common/app";
3533
import { QueryLanguage } from "../common/query-language";
3634
import { LINE_ENDINGS, splitStreamAtSeparators } from "../common/split-stream";
3735
import type { Position } from "../query-server/messages";
36+
import { LOGGING_FLAGS } from "./cli-command";
3837

3938
/**
4039
* The version of the SARIF format that we are using.
@@ -46,11 +45,6 @@ const SARIF_FORMAT = "sarifv2.1.0";
4645
*/
4746
const CSV_FORMAT = "csv";
4847

49-
/**
50-
* Flags to pass to all cli commands.
51-
*/
52-
const LOGGING_FLAGS = ["-v", "--log-to-stderr"];
53-
5448
/**
5549
* The expected output of `codeql resolve queries --format bylanguage`.
5650
*/
@@ -1632,45 +1626,6 @@ export function spawnServer(
16321626
return child;
16331627
}
16341628

1635-
/**
1636-
* Runs a CodeQL CLI command without invoking the CLI server, returning the output as a string.
1637-
* @param codeQlPath The path to the CLI.
1638-
* @param command The `codeql` command to be run, provided as an array of command/subcommand names.
1639-
* @param commandArgs The arguments to pass to the `codeql` command.
1640-
* @param description Description of the action being run, to be shown in log and error messages.
1641-
* @param logger Logger to write command log messages, e.g. to an output channel.
1642-
* @param progressReporter Used to output progress messages, e.g. to the status bar.
1643-
* @returns The contents of the command's stdout, if the command succeeded.
1644-
*/
1645-
export async function runCodeQlCliCommand(
1646-
codeQlPath: string,
1647-
command: string[],
1648-
commandArgs: string[],
1649-
description: string,
1650-
logger: Logger,
1651-
progressReporter?: ProgressReporter,
1652-
): Promise<string> {
1653-
// Add logging arguments first, in case commandArgs contains positional parameters.
1654-
const args = command.concat(LOGGING_FLAGS).concat(commandArgs);
1655-
const argsString = args.join(" ");
1656-
try {
1657-
if (progressReporter !== undefined) {
1658-
progressReporter.report({ message: description });
1659-
}
1660-
void logger.log(
1661-
`${description} using CodeQL CLI: ${codeQlPath} ${argsString}...`,
1662-
);
1663-
const result = await promisify(execFile)(codeQlPath, args);
1664-
void logger.log(result.stderr);
1665-
void logger.log("CLI command succeeded.");
1666-
return result.stdout;
1667-
} catch (err) {
1668-
throw new Error(
1669-
`${description} failed: ${getChildProcessErrorMessage(err)}`,
1670-
);
1671-
}
1672-
}
1673-
16741629
/**
16751630
* Log a text stream to a `Logger` interface.
16761631
* @param stream The stream to log.

extensions/ql-vscode/src/debugger/debugger-ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { DisposableObject } from "../common/disposable-object";
1111
import type { CoreQueryResults } from "../query-server";
1212
import {
1313
getQuickEvalContext,
14-
QueryOutputDir,
1514
saveBeforeStart,
1615
validateQueryUri,
1716
} from "../run-queries-shared";
17+
import { QueryOutputDir } from "../local-queries/query-output-dir";
1818
import type { QLResolvedDebugConfiguration } from "./debug-configuration";
1919
import type {
2020
AnyProtocolMessage,

extensions/ql-vscode/src/language-support/ast-viewer/ast-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
import type { DatabaseItem } from "../../databases/local-databases";
88
import type { ChildAstItem, AstItem } from "./ast-viewer";
99
import type { Uri } from "vscode";
10-
import type { QueryOutputDir } from "../../run-queries-shared";
10+
import type { QueryOutputDir } from "../../local-queries/query-output-dir";
1111
import { fileRangeFromURI } from "../contextual/file-range-from-uri";
1212
import { mapUrlValue } from "../../common/bqrs-raw-results-mapper";
1313

extensions/ql-vscode/src/language-support/contextual/location-finder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from "./query-resolver";
2222
import type { CancellationToken, LocationLink } from "vscode";
2323
import { Uri } from "vscode";
24-
import type { QueryOutputDir } from "../../run-queries-shared";
24+
import type { QueryOutputDir } from "../../local-queries/query-output-dir";
2525
import type { QueryRunner } from "../../query-server";
2626
import { QueryResultType } from "../../query-server/messages";
2727
import { fileRangeFromURI } from "./file-range-from-uri";

extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import type {
2929
DatabaseItem,
3030
DatabaseManager,
3131
} from "../databases/local-databases";
32-
import type { QueryOutputDir, SelectedQuery } from "../run-queries-shared";
32+
import type { SelectedQuery } from "../run-queries-shared";
33+
import type { QueryOutputDir } from "./query-output-dir";
3334
import {
3435
createInitialQueryInfo,
3536
createTimestampFile,

extensions/ql-vscode/src/local-queries/local-query-run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import type { QueryHistoryManager } from "../query-history/query-history-manager
99
import type { DatabaseItem } from "../databases/local-databases";
1010
import type {
1111
EvaluatorLogPaths,
12-
QueryOutputDir,
1312
QueryWithResults,
1413
} from "../run-queries-shared";
14+
import type { QueryOutputDir } from "./query-output-dir";
1515
import {
1616
generateEvalLogSummaries,
1717
logEndSummary,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { join } from "path";
2+
3+
function findQueryLogFile(resultPath: string): string {
4+
return join(resultPath, "query.log");
5+
}
6+
7+
function findQueryEvalLogFile(resultPath: string): string {
8+
return join(resultPath, "evaluator-log.jsonl");
9+
}
10+
11+
function findQueryEvalLogSummaryFile(resultPath: string): string {
12+
return join(resultPath, "evaluator-log.summary");
13+
}
14+
15+
function findJsonQueryEvalLogSummaryFile(resultPath: string): string {
16+
return join(resultPath, "evaluator-log.summary.jsonl");
17+
}
18+
19+
function findQueryEvalLogSummarySymbolsFile(resultPath: string): string {
20+
return join(resultPath, "evaluator-log.summary.symbols.json");
21+
}
22+
23+
function findQueryEvalLogEndSummaryFile(resultPath: string): string {
24+
return join(resultPath, "evaluator-log-end.summary");
25+
}
26+
27+
/**
28+
* Provides paths to the files that can be generated in the output directory for a query evaluation.
29+
*/
30+
export class QueryOutputDir {
31+
constructor(public readonly querySaveDir: string) {}
32+
33+
get dilPath() {
34+
return join(this.querySaveDir, "results.dil");
35+
}
36+
37+
/**
38+
* Get the path that the compiled query is if it exists. Note that it only exists when using the legacy query server.
39+
*/
40+
get compileQueryPath() {
41+
return join(this.querySaveDir, "compiledQuery.qlo");
42+
}
43+
44+
get csvPath() {
45+
return join(this.querySaveDir, "results.csv");
46+
}
47+
48+
get logPath() {
49+
return findQueryLogFile(this.querySaveDir);
50+
}
51+
52+
get evalLogPath() {
53+
return findQueryEvalLogFile(this.querySaveDir);
54+
}
55+
56+
get evalLogSummaryPath() {
57+
return findQueryEvalLogSummaryFile(this.querySaveDir);
58+
}
59+
60+
get jsonEvalLogSummaryPath() {
61+
return findJsonQueryEvalLogSummaryFile(this.querySaveDir);
62+
}
63+
64+
get evalLogSummarySymbolsPath() {
65+
return findQueryEvalLogSummarySymbolsFile(this.querySaveDir);
66+
}
67+
68+
get evalLogEndSummaryPath() {
69+
return findQueryEvalLogEndSummaryFile(this.querySaveDir);
70+
}
71+
72+
get bqrsPath() {
73+
return join(this.querySaveDir, "results.bqrs");
74+
}
75+
}

0 commit comments

Comments
 (0)