Skip to content

Commit 15d2b7b

Browse files
Merge branch 'main' into fix-large-sarif-handling
2 parents 82e78ed + 38e5d8b commit 15d2b7b

23 files changed

Lines changed: 741 additions & 126 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ jobs:
7474
strategy:
7575
matrix:
7676
os: [ubuntu-latest, windows-latest]
77-
version: [stable, nightly]
7877
steps:
7978
- name: Checkout
8079
uses: actions/checkout@v2
@@ -104,31 +103,16 @@ jobs:
104103
run: |
105104
npm run lint
106105
107-
- name: Install CodeQL
108-
run: |
109-
mkdir codeql-home
110-
if [ ${{ matrix.version }} = "stable" ]
111-
then
112-
curl -L --silent https://github.com/github/codeql-cli-binaries/releases/latest/download/codeql.zip -o codeql-home/codeql.zip
113-
else
114-
curl -L --silent ${{ needs.find-nightly.outputs.url }}/codeql.zip -o codeql-home/codeql.zip
115-
fi
116-
unzip -q -o codeql-home/codeql.zip -d codeql-home
117-
unzip -q -o codeql-home/codeql.zip codeql/codeql.exe -d codeql-home
118-
rm codeql-home/codeql.zip
119-
shell: bash
120-
121106
- name: Run unit tests (Linux)
122107
working-directory: extensions/ql-vscode
123108
if: matrix.os == 'ubuntu-latest'
124109
run: |
125-
CODEQL_PATH=$GITHUB_WORKSPACE/codeql-home/codeql/codeql npm run test
110+
npm run test
126111
127112
- name: Run unit tests (Windows)
128113
if: matrix.os == 'windows-latest'
129114
working-directory: extensions/ql-vscode
130115
run: |
131-
$env:CODEQL_PATH=$(Join-Path $env:GITHUB_WORKSPACE -ChildPath 'codeql-home/codeql/codeql.exe')
132116
npm run test
133117
134118
- name: Run integration tests (Linux)
@@ -151,7 +135,7 @@ jobs:
151135
strategy:
152136
matrix:
153137
os: [ubuntu-latest, windows-latest]
154-
version: ['v2.3.3', 'v2.4.6', 'v2.5.9', 'v2.6.3', 'nightly']
138+
version: ['v2.3.3', 'v2.4.6', 'v2.5.9', 'v2.6.3', 'v2.7.0', 'nightly']
155139
env:
156140
CLI_VERSION: ${{ matrix.version }}
157141
NIGHTLY_URL: ${{ needs.find-nightly.outputs.url }}

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
44
// List of extensions which should be recommended for users of this workspace.
55
"recommendations": [
6-
"eamodio.tsl-problem-matcher",
6+
"amodio.tsl-problem-matcher",
77
"dbaeumer.vscode-eslint",
88
"eternalphane.tsfmt-vscode"
99
],

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
// change to 'true' debug the IDE or Query servers
2222
"IDE_SERVER_JAVA_DEBUG": "false",
2323
"QUERY_SERVER_JAVA_DEBUG": "false",
24+
"CLI_SERVER_JAVA_DEBUG": "false",
25+
// Uncomment to set the JAVA_HOME for the codeql instance to use
26+
// "CODEQL_JAVA_HOME": "/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home"
2427
}
2528
},
2629
{
@@ -93,6 +96,19 @@
9396
// available in the workspace for the tests.
9497
// "${workspaceRoot}/../codeql"
9598
],
99+
"env": {
100+
// Optionally, set the version to use for the integration tests.
101+
// Use "nightly" to use the latest nightly build.
102+
// "CLI_VERSION": "2.7.0",
103+
104+
// If CLI_VERSION is set to nightly, set this to the url of the nightly build.
105+
// "NIGHTLY_URL": "some url to grab the nightly build",
106+
107+
// Optionally, add a path to the codeql executable to be used during these tests.
108+
// If not specified, one will be downloaded automatically.
109+
// This option overrides the CLI_VERSION option.
110+
// "CLI_PATH": "${workspaceRoot}/../semmle-code/target/intree/codeql/codeql",
111+
},
96112
"stopOnEntry": false,
97113
"sourceMaps": true,
98114
"outFiles": [

CONTRIBUTING.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ $ vscode/scripts/code-cli.sh --install-extension dist/vscode-codeql-*.vsix # if
7777

7878
You can use VS Code to debug the extension without explicitly installing it. Just open this directory as a workspace in VS Code, and hit `F5` to start a debugging session.
7979

80-
### Running the unit/integration tests
80+
### Running the unit tests and integration tests that do not require a CLI instance
8181

82-
Ensure the `CODEQL_PATH` environment variable is set to point to the `codeql` cli executable.
82+
Unit tests and many integration tests do not require a copy of the CodeQL CLI.
8383

8484
Outside of vscode, run:
8585

@@ -89,6 +89,16 @@ npm run test && npm run integration
8989

9090
Alternatively, you can run the tests inside of vscode. There are several vscode launch configurations defined that run the unit and integration tests. They can all be found in the debug view.
9191

92+
Only the _With CLI_ tests require a CLI instance to run. See below on how to do that.
93+
94+
Running from a terminal, you _must_ set the `TEST_CODEQL_PATH` variable to point to a checkout of the `github/codeql` repository. The appropriate CLI version will be downloaded as part of the test.
95+
96+
### Running the integration tests
97+
98+
The _Launch Integration Tests - With CLI_ tests require a CLI instance in order to run. There are several environment variables you can use to configure this.
99+
100+
From inside of VSCode, open the `launch.json` file and in the _Launch Integration Tests - With CLI_ uncomment and change the environment variables appropriate for your purpose.
101+
92102
## Releasing (write access required)
93103

94104
1. Double-check the `CHANGELOG.md` contains all desired change comments and has the version to be released with date at the top.

extensions/ql-vscode/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
## [UNRELEASED]
44

55
- Fix a bug that causes VSCode to crash when handling large SARIF files (>4GB) [#1004](https://github.com/github/vscode-codeql/pull/1004)
6+
- Fix the _CodeQL: Open Referenced File_ command for Windows systems. [#979](https://github.com/github/vscode-codeql/pull/979)
67
- Fix a bug that shows 'Set current database' when hovering over the currently selected database in the databases view. [#976](https://github.com/github/vscode-codeql/pull/976)
78
- Fix a bug with importing large databases. Databases over 4GB can now be imported directly from LGTM or from a zip file. This functionality is only available when using CodeQL CLI version 2.6.0 or later. [#971](https://github.com/github/vscode-codeql/pull/971)
89
- Replace certain control codes (`U+0000` - `U+001F`) with their corresponding control labels (`U+2400` - `U+241F`) in the results view. [#963](https://github.com/github/vscode-codeql/pull/963)
10+
- Allow case-insensitive project slugs for GitHub repositories when adding a CodeQL database from LGTM. [#978](https://github.com/github/vscode-codeql/pull/961)
11+
- Make "Open Referenced File" command accessible from the active editor menu. [#989](https://github.com/github/vscode-codeql/pull/989)
912

1013
## 1.5.6 - 07 October 2021
1114

extensions/ql-vscode/src/cli.ts

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { assertNever } from './pure/helpers-pure';
2222
import { QueryMetadata, SortDirection } from './pure/interface-types';
2323
import { Logger, ProgressReporter } from './logging';
2424
import { CompilationMessage } from './pure/messages';
25+
import { dbSchemeToLanguage } from './helpers';
2526

2627
/**
2728
* The version of the SARIF format that we are using.
@@ -164,6 +165,11 @@ export class CodeQLCliServer implements Disposable {
164165
/** Version of current cli, lazily computed by the `getVersion()` method */
165166
private _version: SemVer | undefined;
166167

168+
/**
169+
* The languages supported by the current version of the CLI, computed by `getSupportedLanguages()`.
170+
*/
171+
private _supportedLanguages: string[] | undefined;
172+
167173
/** Path to current codeQL executable, or undefined if not running yet. */
168174
codeQlPath: string | undefined;
169175

@@ -186,12 +192,14 @@ export class CodeQLCliServer implements Disposable {
186192
this.distributionProvider.onDidChangeDistribution(() => {
187193
this.restartCliServer();
188194
this._version = undefined;
195+
this._supportedLanguages = undefined;
189196
});
190197
}
191198
if (this.cliConfig.onDidChangeConfiguration) {
192199
this.cliConfig.onDidChangeConfiguration(() => {
193200
this.restartCliServer();
194201
this._version = undefined;
202+
this._supportedLanguages = undefined;
195203
});
196204
}
197205
}
@@ -262,11 +270,16 @@ export class CodeQLCliServer implements Disposable {
262270
*/
263271
private async launchProcess(): Promise<child_process.ChildProcessWithoutNullStreams> {
264272
const codeQlPath = await this.getCodeQlPath();
273+
const args = [];
274+
if (shouldDebugCliServer()) {
275+
args.push('-J=-agentlib:jdwp=transport=dt_socket,address=localhost:9012,server=n,suspend=y,quiet=y');
276+
}
277+
265278
return await spawnServer(
266279
codeQlPath,
267280
'CodeQL CLI Server',
268281
['execute', 'cli-server'],
269-
[],
282+
args,
270283
this.logger,
271284
_data => { /**/ }
272285
);
@@ -610,7 +623,7 @@ export class CodeQLCliServer implements Disposable {
610623
if (target) subcommandArgs.push('--target', target);
611624
if (name) subcommandArgs.push('--name', name);
612625
subcommandArgs.push(archivePath);
613-
626+
614627
return await this.runCodeQlCliCommand(['database', 'unbundle'], subcommandArgs, `Extracting ${archivePath} to directory ${target}`);
615628
}
616629

@@ -818,6 +831,23 @@ export class CodeQLCliServer implements Disposable {
818831
return await this.runJsonCodeQlCliCommand<LanguagesInfo>(['resolve', 'languages'], [], 'Resolving languages');
819832
}
820833

834+
/**
835+
* Gets the list of available languages. Refines the result of `resolveLanguages()`, by excluding
836+
* extra things like "xml" and "properties".
837+
*
838+
* @returns An array of languages that are supported by the current version of the CodeQL CLI.
839+
*/
840+
public async getSupportedLanguages(): Promise<string[]> {
841+
if (!this._supportedLanguages) {
842+
// Get the intersection of resolveLanguages with the list of hardcoded languages in dbSchemeToLanguage.
843+
const resolvedLanguages = Object.keys(await this.resolveLanguages());
844+
const hardcodedLanguages = Object.values(dbSchemeToLanguage);
845+
846+
this._supportedLanguages = resolvedLanguages.filter(lang => hardcodedLanguages.includes(lang));
847+
}
848+
return this._supportedLanguages;
849+
}
850+
821851
/**
822852
* Gets information about queries in a query suite.
823853
* @param suite The suite to resolve.
@@ -843,6 +873,39 @@ export class CodeQLCliServer implements Disposable {
843873
);
844874
}
845875

876+
async packInstall(dir: string) {
877+
return this.runJsonCodeQlCliCommand(['pack', 'install'], [dir], 'Installing pack dependencies');
878+
}
879+
880+
async packBundle(dir: string, workspaceFolders: string[], outputPath: string, precompile = true): Promise<void> {
881+
const args = [
882+
'-o',
883+
outputPath,
884+
dir,
885+
'--additional-packs',
886+
workspaceFolders.join(path.delimiter)
887+
];
888+
if (!precompile && await this.cliConstraints.supportsNoPrecompile()) {
889+
args.push('--no-precompile');
890+
}
891+
892+
return this.runJsonCodeQlCliCommand(['pack', 'bundle'], args, 'Bundling pack');
893+
}
894+
895+
async packPacklist(dir: string, includeQueries: boolean): Promise<string[]> {
896+
const args = includeQueries ? [dir] : ['--no-include-queries', dir];
897+
// since 2.7.1, packlist returns an object with a "paths" property that is a list of packs.
898+
// previous versions return a list of packs.
899+
const results: { paths: string[] } | string[] = await this.runJsonCodeQlCliCommand(['pack', 'packlist'], args, 'Generating the pack list');
900+
901+
// Once we no longer need to support 2.7.0 or earlier, we can remove this and assume all versions return an object.
902+
if ('paths' in results) {
903+
return results.paths;
904+
} else {
905+
return results;
906+
}
907+
}
908+
846909
async generateDil(qloFile: string, outFile: string): Promise<void> {
847910
const extraArgs = await this.cliConstraints.supportsDecompileDil()
848911
? ['--kind', 'dil', '-o', outFile, qloFile]
@@ -1091,6 +1154,12 @@ export function shouldDebugQueryServer() {
10911154
&& process.env.QUERY_SERVER_JAVA_DEBUG?.toLocaleLowerCase() !== 'false';
10921155
}
10931156

1157+
export function shouldDebugCliServer() {
1158+
return 'CLI_SERVER_JAVA_DEBUG' in process.env
1159+
&& process.env.CLI_SERVER_JAVA_DEBUG !== '0'
1160+
&& process.env.CLI_SERVER_JAVA_DEBUG?.toLocaleLowerCase() !== 'false';
1161+
}
1162+
10941163
export class CliVersionConstraint {
10951164

10961165
/**
@@ -1130,6 +1199,16 @@ export class CliVersionConstraint {
11301199
*/
11311200
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer('2.6.0');
11321201

1202+
/**
1203+
* CLI version where the `--no-precompile` option for pack creation was introduced.
1204+
*/
1205+
public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer('2.7.1');
1206+
1207+
/**
1208+
* CLI version where remote queries are supported.
1209+
*/
1210+
public static CLI_VERSION_REMOTE_QUERIES = new SemVer('2.6.3');
1211+
11331212
constructor(private readonly cli: CodeQLCliServer) {
11341213
/**/
11351214
}
@@ -1166,4 +1245,12 @@ export class CliVersionConstraint {
11661245
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE);
11671246
}
11681247

1248+
async supportsNoPrecompile() {
1249+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NO_PRECOMPILE);
1250+
}
1251+
1252+
async supportsRemoteQueries() {
1253+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES);
1254+
}
1255+
11691256
}

extensions/ql-vscode/src/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ const REMOTE_QUERIES_SETTING = new Setting('remoteQueries', ROOT_SETTING);
304304
/**
305305
* Lists of GitHub repositories that you want to query remotely via the "Run Remote query" command.
306306
* Note: This command is only available for internal users.
307-
*
307+
*
308308
* This setting should be a JSON object where each key is a user-specified name (string),
309309
* and the value is an array of GitHub repositories (of the form `<owner>/<repo>`).
310310
*/
@@ -314,6 +314,10 @@ export function getRemoteRepositoryLists(): Record<string, string[]> | undefined
314314
return REMOTE_REPO_LISTS.getValue<Record<string, string[]>>() || undefined;
315315
}
316316

317+
export async function setRemoteRepositoryLists(lists: Record<string, string[]> | undefined) {
318+
await REMOTE_REPO_LISTS.updateValue(lists, ConfigurationTarget.Global);
319+
}
320+
317321
/**
318322
* The name of the "controller" repository that you want to use with the "Run Remote query" command.
319323
* Note: This command is only available for internal users.

0 commit comments

Comments
 (0)