Skip to content

Commit 3c05101

Browse files
authored
Merge pull request #290 from github/extract_gemfile
Automatically extract Gemfiles
2 parents 3d23575 + 961674e commit 3c05101

File tree

11 files changed

+221
-1
lines changed

11 files changed

+221
-1
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ jobs:
203203
shell: bash
204204
run: |
205205
echo "import ruby select count(File f)" > "test.ql"
206-
echo "| 2 |" > "test.expected"
206+
echo "| 3 |" > "test.expected"
207207
echo 'name: sample-tests
208208
version: 0.0.0
209209
dependencies:

autobuilder/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ fn main() -> std::io::Result<()> {
1717
.arg("index-files")
1818
.arg("--include-extension=.rb")
1919
.arg("--include-extension=.erb")
20+
.arg("--include-extension=.gemspec")
21+
.arg("--include=**/Gemfile")
2022
.arg("--size-limit=5m")
2123
.arg("--language=ruby")
2224
.arg("--working-dir=.")

ql/test/library-tests/ast/Ast.expected

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
gems/Gemfile:
2+
# 1| [Toplevel] Gemfile
3+
# 1| getStmt: [MethodCall] call to source
4+
# 1| getReceiver: [Self] self
5+
# 1| getArgument: [StringLiteral] "https://rubygems.org"
6+
# 1| getComponent: [StringTextComponent] https://rubygems.org
7+
# 3| getStmt: [MethodCall] call to gem
8+
# 3| getReceiver: [Self] self
9+
# 3| getArgument: [StringLiteral] "foo_gem"
10+
# 3| getComponent: [StringTextComponent] foo_gem
11+
# 3| getArgument: [StringLiteral] "~> 2.0"
12+
# 3| getComponent: [StringTextComponent] ~> 2.0
13+
# 5| getStmt: [MethodCall] call to source
14+
# 5| getReceiver: [Self] self
15+
# 5| getArgument: [StringLiteral] "https://gems.example.com"
16+
# 5| getComponent: [StringTextComponent] https://gems.example.com
17+
# 5| getBlock: [DoBlock] do ... end
18+
# 6| getStmt: [MethodCall] call to gem
19+
# 6| getReceiver: [Self] self
20+
# 6| getArgument: [StringLiteral] "my_gem"
21+
# 6| getComponent: [StringTextComponent] my_gem
22+
# 6| getArgument: [StringLiteral] "1.0"
23+
# 6| getComponent: [StringTextComponent] 1.0
24+
# 7| getStmt: [MethodCall] call to gem
25+
# 7| getReceiver: [Self] self
26+
# 7| getArgument: [StringLiteral] "another_gem"
27+
# 7| getComponent: [StringTextComponent] another_gem
28+
# 7| getArgument: [StringLiteral] "3.1.4"
29+
# 7| getComponent: [StringTextComponent] 3.1.4
130
calls/calls.rb:
231
# 1| [Toplevel] calls.rb
332
# 2| getStmt: [MethodCall] call to foo
@@ -2080,6 +2109,65 @@ erb/template.html.erb:
20802109
# 28| getAnOperand/getLeftOperand: [LocalVariableAccess] xs
20812110
# 28| getAnOperand/getRightOperand: [LocalVariableAccess] x
20822111
# 29| getStmt: [LocalVariableAccess] xs
2112+
gems/test.gemspec:
2113+
# 1| [Toplevel] test.gemspec
2114+
# 1| getStmt: [MethodCall] call to new
2115+
# 1| getReceiver: [ConstantReadAccess] Specification
2116+
# 1| getScopeExpr: [ConstantReadAccess] Gem
2117+
# 1| getBlock: [DoBlock] do ... end
2118+
# 1| getParameter: [SimpleParameter] s
2119+
# 1| getDefiningAccess: [LocalVariableAccess] s
2120+
# 2| getStmt: [AssignExpr] ... = ...
2121+
# 2| getAnOperand/getLeftOperand: [MethodCall] call to name
2122+
# 2| getReceiver: [LocalVariableAccess] s
2123+
# 2| getAnOperand/getRightOperand: [StringLiteral] "test"
2124+
# 2| getComponent: [StringTextComponent] test
2125+
# 3| getStmt: [AssignExpr] ... = ...
2126+
# 3| getAnOperand/getLeftOperand: [MethodCall] call to version
2127+
# 3| getReceiver: [LocalVariableAccess] s
2128+
# 3| getAnOperand/getRightOperand: [StringLiteral] "0.0.0"
2129+
# 3| getComponent: [StringTextComponent] 0.0.0
2130+
# 4| getStmt: [AssignExpr] ... = ...
2131+
# 4| getAnOperand/getLeftOperand: [MethodCall] call to summary
2132+
# 4| getReceiver: [LocalVariableAccess] s
2133+
# 4| getAnOperand/getRightOperand: [StringLiteral] "foo!"
2134+
# 4| getComponent: [StringTextComponent] foo!
2135+
# 5| getStmt: [AssignExpr] ... = ...
2136+
# 5| getAnOperand/getLeftOperand: [MethodCall] call to description
2137+
# 5| getReceiver: [LocalVariableAccess] s
2138+
# 5| getAnOperand/getRightOperand: [StringLiteral] "A test"
2139+
# 5| getComponent: [StringTextComponent] A test
2140+
# 6| getStmt: [AssignExpr] ... = ...
2141+
# 6| getAnOperand/getLeftOperand: [MethodCall] call to authors
2142+
# 6| getReceiver: [LocalVariableAccess] s
2143+
# 6| getAnOperand/getRightOperand: [ArrayLiteral] [...]
2144+
# 6| getElement: [StringLiteral] "Mona Lisa"
2145+
# 6| getComponent: [StringTextComponent] Mona Lisa
2146+
# 7| getStmt: [AssignExpr] ... = ...
2147+
# 7| getAnOperand/getLeftOperand: [MethodCall] call to email
2148+
# 7| getReceiver: [LocalVariableAccess] s
2149+
# 7| getAnOperand/getRightOperand: [StringLiteral] "[email protected]"
2150+
# 7| getComponent: [StringTextComponent] [email protected]
2151+
# 8| getStmt: [AssignExpr] ... = ...
2152+
# 8| getAnOperand/getLeftOperand: [MethodCall] call to files
2153+
# 8| getReceiver: [LocalVariableAccess] s
2154+
# 8| getAnOperand/getRightOperand: [ArrayLiteral] [...]
2155+
# 8| getElement: [StringLiteral] "lib/test.rb"
2156+
# 8| getComponent: [StringTextComponent] lib/test.rb
2157+
# 9| getStmt: [AssignExpr] ... = ...
2158+
# 9| getAnOperand/getLeftOperand: [MethodCall] call to homepage
2159+
# 9| getReceiver: [LocalVariableAccess] s
2160+
# 9| getAnOperand/getRightOperand: [StringLiteral] "https://github.com/github/cod..."
2161+
# 9| getComponent: [StringTextComponent] https://github.com/github/codeql-ruby
2162+
gems/lib/test.rb:
2163+
# 1| [Toplevel] test.rb
2164+
# 1| getStmt: [ClassDeclaration] Foo
2165+
# 2| getStmt: [SingletonMethod] greet
2166+
# 2| getObject: [Self] self
2167+
# 3| getStmt: [MethodCall] call to puts
2168+
# 3| getReceiver: [Self] self
2169+
# 3| getArgument: [StringLiteral] "Hello"
2170+
# 3| getComponent: [StringTextComponent] Hello
20832171
modules/toplevel.rb:
20842172
# 1| [Toplevel] toplevel.rb
20852173
# 1| getStmt: [MethodCall] call to puts

ql/test/library-tests/ast/AstDesugar.expected

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,78 @@ erb/template.html.erb:
388388
# 28| getAnOperand/getRightOperand: [AddExpr] ... + ...
389389
# 28| getAnOperand/getLeftOperand: [LocalVariableAccess] xs
390390
# 28| getAnOperand/getRightOperand: [LocalVariableAccess] x
391+
gems/test.gemspec:
392+
# 2| [AssignExpr] ... = ...
393+
# 2| getDesugared: [StmtSequence] ...
394+
# 2| getStmt: [SetterMethodCall] call to name=
395+
# 2| getReceiver: [LocalVariableAccess] s
396+
# 2| getArgument: [AssignExpr] ... = ...
397+
# 2| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
398+
# 2| getAnOperand/getRightOperand: [StringLiteral] "test"
399+
# 2| getComponent: [StringTextComponent] test
400+
# 2| getStmt: [LocalVariableAccess] __synth__0
401+
# 3| [AssignExpr] ... = ...
402+
# 3| getDesugared: [StmtSequence] ...
403+
# 3| getStmt: [SetterMethodCall] call to version=
404+
# 3| getReceiver: [LocalVariableAccess] s
405+
# 3| getArgument: [AssignExpr] ... = ...
406+
# 3| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
407+
# 3| getAnOperand/getRightOperand: [StringLiteral] "0.0.0"
408+
# 3| getComponent: [StringTextComponent] 0.0.0
409+
# 3| getStmt: [LocalVariableAccess] __synth__0
410+
# 4| [AssignExpr] ... = ...
411+
# 4| getDesugared: [StmtSequence] ...
412+
# 4| getStmt: [SetterMethodCall] call to summary=
413+
# 4| getReceiver: [LocalVariableAccess] s
414+
# 4| getArgument: [AssignExpr] ... = ...
415+
# 4| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
416+
# 4| getAnOperand/getRightOperand: [StringLiteral] "foo!"
417+
# 4| getComponent: [StringTextComponent] foo!
418+
# 4| getStmt: [LocalVariableAccess] __synth__0
419+
# 5| [AssignExpr] ... = ...
420+
# 5| getDesugared: [StmtSequence] ...
421+
# 5| getStmt: [SetterMethodCall] call to description=
422+
# 5| getReceiver: [LocalVariableAccess] s
423+
# 5| getArgument: [AssignExpr] ... = ...
424+
# 5| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
425+
# 5| getAnOperand/getRightOperand: [StringLiteral] "A test"
426+
# 5| getComponent: [StringTextComponent] A test
427+
# 5| getStmt: [LocalVariableAccess] __synth__0
428+
# 6| [AssignExpr] ... = ...
429+
# 6| getDesugared: [StmtSequence] ...
430+
# 6| getStmt: [SetterMethodCall] call to authors=
431+
# 6| getReceiver: [LocalVariableAccess] s
432+
# 6| getArgument: [AssignExpr] ... = ...
433+
# 6| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
434+
# 6| getAnOperand/getRightOperand: [ArrayLiteral] [...]
435+
# 6| getElement: [StringLiteral] "Mona Lisa"
436+
# 6| getComponent: [StringTextComponent] Mona Lisa
437+
# 6| getStmt: [LocalVariableAccess] __synth__0
438+
# 7| [AssignExpr] ... = ...
439+
# 7| getDesugared: [StmtSequence] ...
440+
# 7| getStmt: [SetterMethodCall] call to email=
441+
# 7| getReceiver: [LocalVariableAccess] s
442+
# 7| getArgument: [AssignExpr] ... = ...
443+
# 7| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
444+
# 7| getAnOperand/getRightOperand: [StringLiteral] "[email protected]"
445+
# 7| getComponent: [StringTextComponent] [email protected]
446+
# 7| getStmt: [LocalVariableAccess] __synth__0
447+
# 8| [AssignExpr] ... = ...
448+
# 8| getDesugared: [StmtSequence] ...
449+
# 8| getStmt: [SetterMethodCall] call to files=
450+
# 8| getReceiver: [LocalVariableAccess] s
451+
# 8| getArgument: [AssignExpr] ... = ...
452+
# 8| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
453+
# 8| getAnOperand/getRightOperand: [ArrayLiteral] [...]
454+
# 8| getElement: [StringLiteral] "lib/test.rb"
455+
# 8| getComponent: [StringTextComponent] lib/test.rb
456+
# 8| getStmt: [LocalVariableAccess] __synth__0
457+
# 9| [AssignExpr] ... = ...
458+
# 9| getDesugared: [StmtSequence] ...
459+
# 9| getStmt: [SetterMethodCall] call to homepage=
460+
# 9| getReceiver: [LocalVariableAccess] s
461+
# 9| getArgument: [AssignExpr] ... = ...
462+
# 9| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
463+
# 9| getAnOperand/getRightOperand: [StringLiteral] "https://github.com/github/cod..."
464+
# 9| getComponent: [StringTextComponent] https://github.com/github/codeql-ruby
465+
# 9| getStmt: [LocalVariableAccess] __synth__0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'foo_gem', '~> 2.0'
4+
5+
source 'https://gems.example.com' do
6+
gem 'my_gem', '1.0'
7+
gem 'another_gem', '3.1.4'
8+
end
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foo
2+
def self.greet
3+
puts "Hello"
4+
end
5+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
| Gemfile:1:1:1:29 | call to source |
2+
| Gemfile:3:1:3:23 | call to gem |
3+
| Gemfile:5:1:8:3 | call to source |
4+
| Gemfile:6:3:6:21 | call to gem |
5+
| Gemfile:7:3:7:28 | call to gem |
6+
| lib/test.rb:3:5:3:16 | call to puts |
7+
| test.gemspec:1:1:10:3 | call to new |
8+
| test.gemspec:2:3:2:8 | call to name |
9+
| test.gemspec:2:3:2:8 | call to name= |
10+
| test.gemspec:3:3:3:11 | call to version |
11+
| test.gemspec:3:3:3:11 | call to version= |
12+
| test.gemspec:4:3:4:11 | call to summary |
13+
| test.gemspec:4:3:4:11 | call to summary= |
14+
| test.gemspec:5:3:5:15 | call to description |
15+
| test.gemspec:5:3:5:15 | call to description= |
16+
| test.gemspec:6:3:6:11 | call to authors |
17+
| test.gemspec:6:3:6:11 | call to authors= |
18+
| test.gemspec:7:3:7:9 | call to email |
19+
| test.gemspec:7:3:7:9 | call to email= |
20+
| test.gemspec:8:3:8:9 | call to files |
21+
| test.gemspec:8:3:8:9 | call to files= |
22+
| test.gemspec:9:3:9:12 | call to homepage |
23+
| test.gemspec:9:3:9:12 | call to homepage= |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Gem::Specification.new do |s|
2+
s.name = 'test'
3+
s.version = '0.0.0'
4+
s.summary = "foo!"
5+
s.description = "A test"
6+
s.authors = ["Mona Lisa"]
7+
s.email = '[email protected]'
8+
s.files = ["lib/test.rb"]
9+
s.homepage = 'https://github.com/github/codeql-ruby'
10+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import ruby
2+
3+
// Just enough to test that we extracted the Gemfile and the .gemspec file.
4+
select any(Call c)

tools/qltest.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
44
--prune=**/*.testproj ^
55
--include-extension=.rb ^
66
--include-extension=.erb ^
7+
--include-extension=.gemspec ^
8+
--include=**/Gemfile ^
79
--size-limit=5m ^
810
--language=ruby ^
911
"%CODEQL_EXTRACTOR_RUBY_WIP_DATABASE%"

0 commit comments

Comments
 (0)