Skip to content

Commit 2989948

Browse files
authored
Merge pull request #11 from github/ql_gen
Generate QL classes
2 parents 24b4586 + e03d5da commit 2989948

File tree

13 files changed

+3032
-99
lines changed

13 files changed

+3032
-99
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ jobs:
2828
run: cargo build --release
2929
- name: Generate dbscheme
3030
if: ${{ matrix.os == 'ubuntu-latest' }}
31-
run: target/release/generator
31+
run: target/release/ruby-generator
3232
- uses: actions/upload-artifact@v2
3333
if: ${{ matrix.os == 'ubuntu-latest' }}
3434
with:
3535
name: ruby.dbscheme
3636
path: ruby.dbscheme
37+
- uses: actions/upload-artifact@v2
38+
if: ${{ matrix.os == 'ubuntu-latest' }}
39+
with:
40+
name: ruby_ast.qll
41+
path: ruby_ast.qll
3742
- uses: actions/upload-artifact@v2
3843
with:
3944
name: extractor-${{ matrix.os }}

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
# Ruby analysis support for CodeQL
22

3-
Under development.
3+
Under development.
4+
5+
## Building the tools from source
6+
7+
[Install Rust](https://www.rust-lang.org/tools/install), then run:
8+
9+
```bash
10+
cargo build --release
11+
```
12+
13+
## Generating the database schema and QL library
14+
15+
The generated `ruby.dbscheme` and `ruby_ast.qll` files are included in the repository, but they can be re-generated as follows:
16+
17+
```bash
18+
# Run the generator
19+
cargo run --release -p ruby-generator
20+
# Then auto-format the QL library
21+
codeql query format -i ruby_ast.qll
22+
```

extractor/src/extractor.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ impl Visitor<'_> {
225225
"too many values"
226226
},
227227
node.kind(),
228-
match field.name.as_ref() {
229-
Some(x) => x,
230-
None => "child",
231-
}
228+
&field.get_name()
232229
)
233230
}
234231
}
@@ -237,10 +234,7 @@ impl Visitor<'_> {
237234
self.trap_output.push(TrapEntry::ChildOf(
238235
node_type_name(&field.parent.kind, field.parent.named),
239236
parent_id,
240-
match &field.name {
241-
Some(name) => name.to_owned(),
242-
None => "child".to_owned(),
243-
},
237+
field.get_name(),
244238
Index(index),
245239
*child_id,
246240
));

generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "generator"
2+
name = "ruby-generator"
33
version = "0.1.0"
44
authors = ["GitHub"]
55
edition = "2018"

generator/src/dbscheme.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::ql;
12
use std::fmt;
23

34
/// Represents a distinct entry in the database schema.
@@ -27,7 +28,7 @@ pub struct Column {
2728
pub db_type: DbColumnType,
2829
pub name: String,
2930
pub unique: bool,
30-
pub ql_type: QlColumnType,
31+
pub ql_type: ql::Type,
3132
pub ql_type_is_ref: bool,
3233
}
3334

@@ -37,18 +38,6 @@ pub enum DbColumnType {
3738
String,
3839
}
3940

40-
// The QL type of a column.
41-
pub enum QlColumnType {
42-
/// Primitive `int` type.
43-
Int,
44-
45-
/// Primitive `string` type.
46-
String,
47-
48-
/// A custom type, defined elsewhere by a table or union.
49-
Custom(String),
50-
}
51-
5241
impl fmt::Display for Table {
5342
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5443
if let Some(keyset) = &self.keysets {
@@ -76,12 +65,7 @@ impl fmt::Display for Table {
7665
DbColumnType::String => "string",
7766
}
7867
)?;
79-
write!(f, "{}: ", column.name)?;
80-
match &column.ql_type {
81-
QlColumnType::Int => write!(f, "int")?,
82-
QlColumnType::String => write!(f, "string")?,
83-
QlColumnType::Custom(name) => write!(f, "@{}", name)?,
84-
}
68+
write!(f, "{}: {}", column.name, column.ql_type)?;
8569
if column.ql_type_is_ref {
8670
write!(f, " ref")?;
8771
}

generator/src/language.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ pub struct Language {
44
pub name: String,
55
pub node_types: &'static str,
66
pub dbscheme_path: PathBuf,
7+
pub ql_library_path: PathBuf,
78
}

0 commit comments

Comments
 (0)