Skip to content

Commit 32253aa

Browse files
authored
Merge pull request #266 from github/dbartol/refactor-packs
Refactor Ruby into library and query packs
2 parents ee6c809 + 42629b9 commit 32253aa

File tree

149 files changed

+326
-294
lines changed

Some content is hidden

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

149 files changed

+326
-294
lines changed

.codeqlmanifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"provide": [
3+
"ql/lib/qlpack.yml",
34
"ql/src/qlpack.yml",
45
"ql/consistency-queries/qlpack.yml",
56
"ql/test/qlpack.yml",

.github/workflows/build.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ jobs:
4747
run: cargo build --release
4848
- name: Generate dbscheme
4949
if: ${{ matrix.os == 'ubuntu-latest' }}
50-
run: target/release/ruby-generator --dbscheme ql/src/ruby.dbscheme --library ql/src/codeql_ruby/ast/internal/TreeSitter.qll
50+
run: target/release/ruby-generator --dbscheme ql/lib/ruby.dbscheme --library ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
5151
- uses: actions/upload-artifact@v2
5252
if: ${{ matrix.os == 'ubuntu-latest' }}
5353
with:
5454
name: ruby.dbscheme
55-
path: ql/src/ruby.dbscheme
55+
path: ql/lib/ruby.dbscheme
5656
- uses: actions/upload-artifact@v2
5757
if: ${{ matrix.os == 'ubuntu-latest' }}
5858
with:
5959
name: TreeSitter.qll
60-
path: ql/src/codeql_ruby/ast/internal/TreeSitter.qll
60+
path: ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
6161
- uses: actions/upload-artifact@v2
6262
with:
6363
name: extractor-${{ matrix.os }}
@@ -82,8 +82,10 @@ jobs:
8282
GITHUB_TOKEN: ${{ github.token }}
8383
- name: Build Query Pack
8484
run: |
85+
codeql/codeql pack create ql/lib --output target/packs
86+
codeql/codeql pack install ql/src
8587
codeql/codeql pack create ql/src --output target/packs
86-
PACK_FOLDER=$(readlink -f target/packs/github/codeql-ruby/*)
88+
PACK_FOLDER=$(readlink -f target/packs/codeql/ruby-queries/*)
8789
codeql/codeql generate query-help --format=sarifv2.1.0 --output="${PACK_FOLDER}/rules.sarif" ql/src
8890
(cd ql/src; find queries \( -name '*.qhelp' -o -name '*.rb' -o -name '*.erb' \) -exec bash -c 'mkdir -p "'"${PACK_FOLDER}"'/$(dirname "{}")"' \; -exec cp "{}" "${PACK_FOLDER}/{}" \;)
8991
- name: Compile with previous CodeQL versions
@@ -126,7 +128,7 @@ jobs:
126128
path: osx64
127129
- run: |
128130
mkdir -p ruby
129-
cp -r codeql-extractor.yml tools ql/src/ruby.dbscheme.stats ruby/
131+
cp -r codeql-extractor.yml tools ql/lib/ruby.dbscheme.stats ruby/
130132
mkdir -p ruby/tools/{linux64,osx64,win64}
131133
cp linux64/ruby-autobuilder ruby/tools/linux64/autobuilder
132134
cp osx64/ruby-autobuilder ruby/tools/osx64/autobuilder
@@ -204,26 +206,20 @@ jobs:
204206
echo "| 2 |" > "test.expected"
205207
echo 'name: sample-tests
206208
version: 0.0.0
207-
libraryPathDependencies:
208-
- codeql-ruby
209+
dependencies:
210+
codeql/ruby-all: 0.0.1
209211
extractor: ruby
210212
tests: .
211213
' > qlpack.yml
212-
echo '- qlpack: codeql-ruby
213-
- include:
214-
kind:
215-
- problem
216-
- path-problem
217-
' > suite.qls
218214
- name: Run QL test
219215
shell: bash
220216
run: |
221-
"${{ runner.temp }}/codeql/codeql" test run --search-path "${{ runner.temp }}/ruby-bundle" .
217+
"${{ runner.temp }}/codeql/codeql" test run --search-path "${{ runner.temp }}/ruby-bundle" --additional-packs "${{ runner.temp }}/ruby-bundle" .
222218
- name: Create database
223219
shell: bash
224220
run: |
225221
"${{ runner.temp }}/codeql/codeql" database create --search-path "${{ runner.temp }}/ruby-bundle" --language ruby --source-root . ../database
226222
- name: Analyze database
227223
shell: bash
228224
run: |
229-
"${{ runner.temp }}/codeql/codeql" database analyze --search-path "${{ runner.temp }}/ruby-bundle" --format=sarifv2.1.0 --output=out.sarif ../database suite.qls
225+
"${{ runner.temp }}/codeql/codeql" database analyze --search-path "${{ runner.temp }}/ruby-bundle" --format=sarifv2.1.0 --output=out.sarif ../database ruby-code-scanning.qls

.github/workflows/dataset_measure.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ on:
44
push:
55
branches: [main]
66
paths:
7-
- ql/src/ruby.dbscheme
7+
- ql/lib/ruby.dbscheme
88
pull_request:
99
branches: [main]
1010
paths:
11-
- ql/src/ruby.dbscheme
11+
- ql/lib/ruby.dbscheme
1212
workflow_dispatch:
1313

1414
jobs:
@@ -73,8 +73,8 @@ jobs:
7373
path: stats
7474
- run: |
7575
python -m pip install --user lxml
76-
find stats -name 'stats.xml' | sort | xargs python scripts/merge_stats.py --output ql/src/ruby.dbscheme.stats --normalise ruby_tokeninfo
76+
find stats -name 'stats.xml' | sort | xargs python scripts/merge_stats.py --output ql/lib/ruby.dbscheme.stats --normalise ruby_tokeninfo
7777
- uses: actions/upload-artifact@v2
7878
with:
7979
name: ruby.dbscheme.stats
80-
path: ql/src/ruby.dbscheme.stats
80+
path: ql/lib/ruby.dbscheme.stats

.github/workflows/qltest.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ jobs:
3131
- name: Build Extractor
3232
run: env "PATH=$PATH:${{ github.workspace }}/codeql" scripts/create-extractor-pack.sh
3333
- name: Run QL tests
34-
run: codeql/codeql test run --check-databases --check-unused-labels --check-repeated-labels --check-redefined-labels --check-use-before-definition --search-path "${{ github.workspace }}" --consistency-queries ql/consistency-queries ql/test
34+
run: |
35+
codeql/codeql pack install ql/test
36+
codeql/codeql test run --check-databases --check-unused-labels --check-repeated-labels --check-redefined-labels --check-use-before-definition --search-path "${{ github.workspace }}" --additional-packs "${HOME}/.codeql/packages/codeql/suite-helpers/0.0.1" --consistency-queries ql/consistency-queries ql/test
3537
- name: Check QL formatting
3638
run: find ql "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 codeql/codeql query format --check-only
3739
- name: Check QL compilation
38-
run: codeql/codeql query compile --check-only --threads=4 --warnings=error --search-path "${{ github.workspace }}" "ql/src" "ql/examples"
40+
run: |
41+
codeql/codeql pack install ql/src
42+
codeql/codeql query compile --check-only --threads=4 --warnings=error --search-path "${{ github.workspace }}" "ql/src" "ql/examples"
3943
- name: Check DB upgrade scripts
4044
run: |
4145
echo >empty.trap
42-
codeql/codeql dataset import -S ql/src/upgrades/initial/ruby.dbscheme testdb empty.trap
43-
codeql/codeql dataset upgrade testdb --additional-packs ql/src/upgrades
44-
diff -q testdb/ruby.dbscheme ql/src/ruby.dbscheme
46+
codeql/codeql dataset import -S ql/lib/upgrades/initial/ruby.dbscheme testdb empty.trap
47+
codeql/codeql dataset upgrade testdb --additional-packs ql/lib/upgrades
48+
diff -q testdb/ruby.dbscheme ql/lib/ruby.dbscheme

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ extractor-pack
55
ql/test/**/*.testproj
66
ql/test/**/*.actual
77
ql/test/**/CONSISTENCY
8+
.codeql

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ FILES=codeql-extractor.yml\
2121
tools/autobuild.sh\
2222
tools/qltest.sh\
2323
tools/autobuild.cmd\
24-
ql/src/ruby.dbscheme.stats\
25-
ql/src/ruby.dbscheme
24+
ql/lib/ruby.dbscheme.stats\
25+
ql/lib/ruby.dbscheme
2626

2727
BIN_FILES=target/release/ruby-extractor$(EXE) target/release/ruby-autobuilder$(EXE)
2828

2929
extractor-common:
3030
rm -rf build
3131
mkdir build
3232
mkdir build/codeql-extractor-ruby
33-
cp codeql-extractor.yml ql/src/ruby.dbscheme ql/src/ruby.dbscheme.stats build/codeql-extractor-ruby
33+
cp codeql-extractor.yml ql/lib/ruby.dbscheme ql/lib/ruby.dbscheme.stats build/codeql-extractor-ruby
3434
cp -r tools build/codeql-extractor-ruby/
3535

3636
.PHONY: tools
@@ -45,8 +45,8 @@ target/release/%$(EXE):
4545

4646
dbscheme:
4747
cargo build --bin ruby-generator
48-
cargo run -p ruby-generator -- --dbscheme ql/src/ruby.dbscheme --library ql/src/codeql_ruby/ast/internal/TreeSitter.qll
49-
codeql query format -i ql/src/codeql_ruby/ast/internal/TreeSitter.qll
48+
cargo run -p ruby-generator -- --dbscheme ql/lib/ruby.dbscheme --library ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
49+
codeql query format -i ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
5050

5151
.PHONY: extractor
5252
extractor: $(FILES) $(BIN_FILES)
@@ -61,7 +61,7 @@ extractor: $(FILES) $(BIN_FILES)
6161
cp tools/autobuild.sh extractor-pack/tools/autobuild.sh
6262
cp tools/qltest.sh extractor-pack/tools/qltest.sh
6363
cp tools/autobuild.cmd extractor-pack/tools/autobuild.cmd
64-
cp ql/src/ruby.dbscheme.stats extractor-pack/ruby.dbscheme.stats
65-
cp ql/src/ruby.dbscheme extractor-pack/ruby.dbscheme
64+
cp ql/lib/ruby.dbscheme.stats extractor-pack/ruby.dbscheme.stats
65+
cp ql/lib/ruby.dbscheme extractor-pack/ruby.dbscheme
6666
cp target/release/ruby-extractor$(EXE) extractor-pack/tools/$(CODEQL_PLATFORM)/extractor$(EXE)
6767
cp target/release/ruby-autobuilder$(EXE) extractor-pack/tools/$(CODEQL_PLATFORM)/autobuilder$(EXE)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ cargo build --release
1212

1313
## Generating the database schema and QL library
1414

15-
The generated `ql/src/ruby.dbscheme` and `ql/src/codeql_ruby/ast/internal/TreeSitter.qll` files are included in the repository, but they can be re-generated as follows:
15+
The generated `ql/lib/ruby.dbscheme` and `ql/lib/codeql/ruby/ast/internal/TreeSitter.qll` files are included in the repository, but they can be re-generated as follows:
1616

1717
```bash
1818
# Run the generator
19-
cargo run --release -p ruby-generator -- --dbscheme ql/src/ruby.dbscheme --library ql/src/codeql_ruby/ast/internal/TreeSitter.qll
19+
cargo run --release -p ruby-generator -- --dbscheme ql/lib/ruby.dbscheme --library ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
2020
# Then auto-format the QL library
21-
codeql query format -i ql/src/codeql_ruby/ast/internal/TreeSitter.qll
21+
codeql query format -i ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
2222
```
2323

2424
## Building a CodeQL database for a Ruby program

doc/prepare-db-upgrade.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Upgrading the Ruby database schema
22

3-
The schema (`ql/src/ruby.dbscheme`) is automatically generated from tree-sitter's `node-types.json`. When the tree-sitter grammar changes, the database schema is likely to change as well, and we need to write an upgrade script. This document explains how to do that.
3+
The schema (`ql/lib/ruby.dbscheme`) is automatically generated from tree-sitter's `node-types.json`. When the tree-sitter grammar changes, the database schema is likely to change as well, and we need to write an upgrade script. This document explains how to do that.
44

55
## Process Overview
66

@@ -81,11 +81,11 @@ Upgrade scripts can be a little bit fiddly, so it's essential that you test them
8181

8282
To create the upgrade directory manually, without using `scripts/prepare-db-upgrade.sh`:
8383

84-
1. Get a hash of the old `.dbscheme` file, from just before your changes. You can do this by checking out the code prior to your changes and running `git hash-object ql/src/ruby.dbscheme`
84+
1. Get a hash of the old `.dbscheme` file, from just before your changes. You can do this by checking out the code prior to your changes and running `git hash-object ql/lib/ruby.dbscheme`
8585

86-
2. Go back to your branch and create an upgrade directory with that hash as its name, for example: `mkdir ql/src/upgrades/454f1e15151422355049dc4f1f0486a03baeffef`
86+
2. Go back to your branch and create an upgrade directory with that hash as its name, for example: `mkdir ql/lib/upgrades/454f1e15151422355049dc4f1f0486a03baeffef`
8787

8888
3. Copy the old `.dbscheme` file to that directory, using the name old.dbscheme.
89-
`cp ql/src/ruby.dbscheme ql/src/upgrades/454f1e15151422355049dc4f1f0486a03baeffef/old.dbscheme`
89+
`cp ql/lib/ruby.dbscheme ql/lib/upgrades/454f1e15151422355049dc4f1f0486a03baeffef/old.dbscheme`
9090

9191
4. Put a copy of your new `.dbscheme` file in that directory and create an `upgrade.properties` file (as described above).

ql/consistency-queries/AstConsistency.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import codeql_ruby.AST
2-
import codeql_ruby.ast.internal.Synthesis
1+
import codeql.ruby.AST
2+
import codeql.ruby.ast.internal.Synthesis
33

44
private string getAPrimaryQlClass(AstNode node) {
55
result = node.getAPrimaryQlClass()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import codeql_ruby.controlflow.internal.Consistency
1+
import codeql.ruby.controlflow.internal.Consistency

0 commit comments

Comments
 (0)