Skip to content

Commit 778de74

Browse files
committed
Merge remote-tracking branch 'origin/main' into cfg_cleanup
2 parents f3d831c + ad036f8 commit 778de74

88 files changed

Lines changed: 9538 additions & 3872 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.codeqlmanifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"provide": [
33
"ql/src/qlpack.yml",
4+
"ql/consistency-queries/qlpack.yml",
45
"ql/test/qlpack.yml",
56
"ql/examples/qlpack.yml",
67
"upgrades/qlpack.yml",
78
"extractor-pack/codeql-extractor.yml"
89
]
9-
}
10+
}

.devcontainer/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.162.0/containers/rust/.devcontainer/base.Dockerfile
2+
3+
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1
4+
5+
RUN apt-key --keyring /usr/share/keyrings/githubcli-archive-keyring.gpg adv \
6+
--keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 && \
7+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages $(lsb_release -cs) main" \
8+
| tee /etc/apt/sources.list.d/github-cli2.list > /dev/null
9+
10+
11+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
12+
&& apt-get -y install --no-install-recommends gh
13+
14+
COPY post_create.sh /bin/post_create.sh
15+
COPY post_attach.sh /bin/post_attach.sh

.devcontainer/devcontainer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.162.0/containers/rust
3+
{
4+
"name": "Rust",
5+
"build": {
6+
"dockerfile": "Dockerfile"
7+
},
8+
"runArgs": [
9+
"--cap-add=SYS_PTRACE",
10+
"--security-opt",
11+
"seccomp=unconfined"
12+
],
13+
// Set *default* container specific settings.json values on container create.
14+
"settings": {
15+
"terminal.integrated.shell.linux": "/bin/bash",
16+
"lldb.executable": "/usr/bin/lldb",
17+
// VS Code don't watch files under ./target
18+
"files.watcherExclude": {
19+
"**/target/**": true
20+
}
21+
},
22+
// Add the IDs of extensions you want installed when the container is created.
23+
"extensions": [
24+
"rust-lang.rust",
25+
"bungcip.better-toml",
26+
"vadimcn.vscode-lldb",
27+
"mutantdino.resourcemonitor",
28+
"ms-azuretools.vscode-docker",
29+
"github.vscode-codeql"
30+
],
31+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
32+
// "forwardPorts": [],
33+
// Use 'postCreateCommand' to run commands after the container is created.
34+
// "postCreateCommand": "rustc --version",
35+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
36+
"remoteUser": "vscode",
37+
"postCreateCommand": [ "/bin/post_create.sh" ],
38+
"postAttachCommand": [ "flock", "-E", "0", "-n", "/var/lock/post_attach.lock", "/bin/post_attach.sh" ]
39+
}

.devcontainer/post_attach.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#! /bin/bash
2+
set -xe
3+
4+
echo "Check installed CodeQL version"
5+
CURRENT_CODEQL_BIN=$(readlink -e /usr/local/bin/codeql || echo "")
6+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
7+
8+
BASE_DIR=/home/vscode/codeql-binaries
9+
mkdir -p "${BASE_DIR}"
10+
LATEST_CODEQL_DIR="${BASE_DIR}/codeql-${LATEST}"
11+
LATEST_CODEQL_BIN="${LATEST_CODEQL_DIR}/codeql/codeql"
12+
13+
if [ "${CURRENT_CODEQL_BIN}" != "${LATEST_CODEQL_BIN}" ]; then
14+
echo "Installing CodeQL ${LATEST}"
15+
TMPDIR=$(mktemp -d -p "$(dirname ${LATEST_CODEQL_DIR})")
16+
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip -D "${TMPDIR}" "$LATEST"
17+
unzip -oq "${TMPDIR}/codeql-linux64.zip" -d "${TMPDIR}"
18+
rm -f "${TMPDIR}/codeql-linux64.zip"
19+
mv "${TMPDIR}" "${LATEST_CODEQL_DIR}"
20+
test -x "${LATEST_CODEQL_BIN}" && sudo ln -sf "${LATEST_CODEQL_BIN}" /usr/local/bin/codeql
21+
if [[ "${CURRENT_CODEQL_BIN}" =~ .*/codeql/codeql ]]; then
22+
rm -rf "$(dirname $(dirname ${CURRENT_CODEQL_BIN}))"
23+
fi
24+
fi
25+
26+
echo "Build the Ruby extractor"
27+
28+
# clone the git dependencies using "git clone" because cargo's builtin git support is rather slow
29+
REPO_DIR="${CARGO_HOME:-/home/vscode/.cargo}/git/db"
30+
REPO_DIR_ERB="${REPO_DIR}/tree-sitter-embedded-template-4c796e3340c233b6"
31+
REPO_DIR_RUBY="${REPO_DIR}/tree-sitter-ruby-666a40ce046f8e7a"
32+
33+
mkdir -p "${REPO_DIR}"
34+
test -e "${REPO_DIR_ERB}" || git clone -q --bare https://github.com/tree-sitter/tree-sitter-embedded-template "${REPO_DIR_ERB}"
35+
test -e "${REPO_DIR_RUBY}" || git clone -q --bare https://github.com/tree-sitter/tree-sitter-ruby.git "${REPO_DIR_RUBY}"
36+
37+
./create-extractor-pack.sh

.devcontainer/post_create.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /bin/bash
2+
3+
mkdir -p /home/vscode/.config/codeql
4+
echo '--search-path /workspaces/codeql-ruby' >> /home/vscode/.config/codeql/config

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codeql

Submodule codeql updated 1111 files

extractor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2018"
1010
flate2 = "1.0"
1111
node-types = { path = "../node-types" }
1212
tree-sitter = "0.17"
13-
tree-sitter-embedded-template = { git = "https://github.com/aibaars/tree-sitter-embedded-template", rev = "d4aac29c08aa7c596633d00b5ec2dd2d247eafe4" }
13+
tree-sitter-embedded-template = { git = "https://github.com/tree-sitter/tree-sitter-embedded-template", rev = "d4aac29c08aa7c596633d00b5ec2dd2d247eafe4" }
1414
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "32cd5a04adb4accb0c121f037ab59df3c3488228" }
1515
clap = "2.33"
1616
tracing = "0.1"

extractor/src/extractor.rs

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,58 @@ struct Visitor<'a> {
305305
}
306306

307307
impl Visitor<'_> {
308+
fn record_parse_error(
309+
&mut self,
310+
error_message: String,
311+
full_error_message: String,
312+
loc: Label,
313+
) {
314+
error!("{}", full_error_message);
315+
let id = self.trap_writer.fresh_id();
316+
self.trap_writer.add_tuple(
317+
"diagnostics",
318+
vec![
319+
Arg::Label(id),
320+
Arg::Int(40), // severity 40 = error
321+
Arg::String("parse_error".to_string()),
322+
Arg::String(error_message),
323+
Arg::String(full_error_message),
324+
Arg::Label(loc),
325+
],
326+
);
327+
}
328+
329+
fn record_parse_error_for_node(
330+
&mut self,
331+
error_message: String,
332+
full_error_message: String,
333+
node: Node,
334+
) {
335+
let (start_line, start_column, end_line, end_column) = location_for(&self.source, node);
336+
let loc = self.trap_writer.location(
337+
self.file_label,
338+
start_line,
339+
start_column,
340+
end_line,
341+
end_column,
342+
);
343+
self.record_parse_error(error_message, full_error_message, loc);
344+
}
345+
308346
fn enter_node(&mut self, node: Node) -> bool {
309-
if node.is_error() {
310-
error!(
311-
"{}:{}: parse error",
312-
&self.path,
313-
node.start_position().row + 1
314-
);
315-
return false;
316-
}
317-
if node.is_missing() {
318-
error!(
319-
"{}:{}: parse error: expecting '{}'",
347+
if node.is_error() || node.is_missing() {
348+
let error_message = if node.is_missing() {
349+
format!("parse error: expecting '{}'", node.kind())
350+
} else {
351+
"parse error".to_string()
352+
};
353+
let full_error_message = format!(
354+
"{}:{}: {}",
320355
&self.path,
321356
node.start_position().row + 1,
322-
node.kind()
357+
error_message
323358
);
359+
self.record_parse_error_for_node(error_message, full_error_message, node);
324360
return false;
325361
}
326362

@@ -405,12 +441,15 @@ impl Visitor<'_> {
405441
}
406442
}
407443
_ => {
408-
error!(
409-
"{}:{}: unknown table type: '{}'",
444+
let error_message = format!("unknown table type: '{}'", node.kind());
445+
let full_error_message = format!(
446+
"{}:{}: {}",
410447
&self.path,
411448
node.start_position().row + 1,
412-
node.kind()
449+
error_message
413450
);
451+
self.record_parse_error(error_message, full_error_message, loc);
452+
414453
valid = false;
415454
}
416455
}
@@ -456,26 +495,36 @@ impl Visitor<'_> {
456495
values.push(Arg::Label(child_node.label));
457496
}
458497
} else if field.name.is_some() {
459-
error!(
460-
"{}:{}: type mismatch for field {}::{} with type {:?} != {:?}",
461-
&self.path,
462-
node.start_position().row + 1,
498+
let error_message = format!(
499+
"type mismatch for field {}::{} with type {:?} != {:?}",
463500
node.kind(),
464501
child_node.field_name.unwrap_or("child"),
465502
child_node.type_name,
466503
field.type_info
467-
)
504+
);
505+
let full_error_message = format!(
506+
"{}:{}: {}",
507+
&self.path,
508+
node.start_position().row + 1,
509+
error_message
510+
);
511+
self.record_parse_error_for_node(error_message, full_error_message, *node);
468512
}
469513
} else {
470514
if child_node.field_name.is_some() || child_node.type_name.named {
471-
error!(
472-
"{}:{}: value for unknown field: {}::{} and type {:?}",
473-
&self.path,
474-
node.start_position().row + 1,
515+
let error_message = format!(
516+
"value for unknown field: {}::{} and type {:?}",
475517
node.kind(),
476518
&child_node.field_name.unwrap_or("child"),
477519
&child_node.type_name
478520
);
521+
let full_error_message = format!(
522+
"{}:{}: {}",
523+
&self.path,
524+
node.start_position().row + 1,
525+
error_message
526+
);
527+
self.record_parse_error_for_node(error_message, full_error_message, *node);
479528
}
480529
}
481530
}
@@ -489,18 +538,23 @@ impl Visitor<'_> {
489538
args.push(child_values.first().unwrap().clone());
490539
} else {
491540
is_valid = false;
492-
error!(
493-
"{}:{}: {} for field: {}::{}",
494-
&self.path,
495-
node.start_position().row + 1,
541+
let error_message = format!(
542+
"{} for field: {}::{}",
496543
if child_values.is_empty() {
497544
"missing value"
498545
} else {
499546
"too many values"
500547
},
501548
node.kind(),
502549
column_name
503-
)
550+
);
551+
let full_error_message = format!(
552+
"{}:{}: {}",
553+
&self.path,
554+
node.start_position().row + 1,
555+
error_message
556+
);
557+
self.record_parse_error_for_node(error_message, full_error_message, *node);
504558
}
505559
}
506560
Storage::Table {

generator/src/main.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<dbscheme::Entry<
248248
entries.push(dbscheme::Entry::Table(token_table));
249249
entries.push(dbscheme::Entry::Case(token_case));
250250

251+
// Add the diagnostics table
252+
let (diagnostics_case, diagnostics_table) = create_diagnostics();
253+
entries.push(dbscheme::Entry::Table(diagnostics_table));
254+
entries.push(dbscheme::Entry::Case(diagnostics_case));
255+
251256
// Create a union of all database types.
252257
entries.push(dbscheme::Entry::Union(dbscheme::Union {
253258
name: "ast_node",
@@ -590,6 +595,69 @@ fn create_source_location_prefix_table<'a>() -> dbscheme::Entry<'a> {
590595
})
591596
}
592597

598+
fn create_diagnostics<'a>() -> (dbscheme::Case<'a>, dbscheme::Table<'a>) {
599+
let table = dbscheme::Table {
600+
name: "diagnostics",
601+
keysets: None,
602+
columns: vec![
603+
dbscheme::Column {
604+
unique: true,
605+
db_type: dbscheme::DbColumnType::Int,
606+
name: "id",
607+
ql_type: ql::Type::AtType("diagnostic"),
608+
ql_type_is_ref: false,
609+
},
610+
dbscheme::Column {
611+
unique: false,
612+
db_type: dbscheme::DbColumnType::Int,
613+
name: "severity",
614+
ql_type: ql::Type::Int,
615+
ql_type_is_ref: true,
616+
},
617+
dbscheme::Column {
618+
unique: false,
619+
db_type: dbscheme::DbColumnType::String,
620+
name: "error_tag",
621+
ql_type: ql::Type::String,
622+
ql_type_is_ref: true,
623+
},
624+
dbscheme::Column {
625+
unique: false,
626+
db_type: dbscheme::DbColumnType::String,
627+
name: "error_message",
628+
ql_type: ql::Type::String,
629+
ql_type_is_ref: true,
630+
},
631+
dbscheme::Column {
632+
unique: false,
633+
db_type: dbscheme::DbColumnType::String,
634+
name: "full_error_message",
635+
ql_type: ql::Type::String,
636+
ql_type_is_ref: true,
637+
},
638+
dbscheme::Column {
639+
unique: false,
640+
db_type: dbscheme::DbColumnType::Int,
641+
name: "location",
642+
ql_type: ql::Type::AtType("location_default"),
643+
ql_type_is_ref: true,
644+
},
645+
],
646+
};
647+
let severities: Vec<(usize, &str)> = vec![
648+
(10, "diagnostic_debug"),
649+
(20, "diagnostic_info"),
650+
(30, "diagnostic_warning"),
651+
(40, "diagnostic_error"),
652+
];
653+
let case = dbscheme::Case {
654+
name: "diagnostic",
655+
column: "severity",
656+
branches: severities,
657+
};
658+
(case, table)
659+
}
660+
593661
fn main() {
594662
tracing_subscriber::fmt()
595663
.with_target(false)

0 commit comments

Comments
 (0)