12
12
are on the PATH. It'll try to automatically set the CodeQL search path correctly,
13
13
as long as you run the script from one of the following locations:
14
14
- anywhere from within a clone of the CodeQL Git repo
15
- - from the parent directory of a clone of the CodeQL Git repo (assuming 'codeql'
15
+ - from the parent directory of a clone of the CodeQL Git repo (assuming 'codeql'
16
16
and 'codeql-go' directories both exist)
17
17
"""
18
18
@@ -27,14 +27,14 @@ def prefix_repo_nwo(filename):
27
27
This function relies on `git` being available.
28
28
29
29
For example:
30
- /home/alice/git/ql/java/ql/src/MyQuery.ql
30
+ /home/alice/git/ql/java/ql/src/MyQuery.ql
31
31
becomes:
32
32
github/codeql/java/ql/src/MyQuery.ql
33
-
33
+
34
34
If we can't detect a known NWO (e.g. github/codeql, github/codeql-go), the
35
35
path will be truncated to the root of the git repo:
36
36
ql/java/ql/src/MyQuery.ql
37
-
37
+
38
38
If the filename is not part of a Git repo, the return value is the
39
39
same as the input value: the whole path.
40
40
"""
@@ -45,9 +45,9 @@ def prefix_repo_nwo(filename):
45
45
except :
46
46
# Not a Git repo
47
47
return filename
48
-
48
+
49
49
git_toplevel_dir = git_toplevel_dir_subp .stdout .strip ()
50
-
50
+
51
51
# Detect 'github/codeql' and 'github/codeql-go' repositories by checking the remote (it's a bit
52
52
# of a hack but will work in most cases, as long as the remotes have 'codeql' and 'codeql-go'
53
53
# in the URL
@@ -100,7 +100,7 @@ def subprocess_run(cmd):
100
100
#
101
101
# (and assumes the codeql-go repo is in a similar location)
102
102
codeql_search_path = "./codeql:./codeql-go:." # will be extended further down
103
-
103
+
104
104
# Extend CodeQL search path by detecting root of the current Git repo (if any). This means that you
105
105
# can run this script from any location within the CodeQL git repository.
106
106
try :
@@ -116,7 +116,7 @@ def subprocess_run(cmd):
116
116
# Create CSV writer and write CSV header to stdout
117
117
csvwriter = csv .writer (sys .stdout )
118
118
csvwriter .writerow ([
119
- "Query filename" , "Suite" , "Query name" , "Query ID" ,
119
+ "Query filename" , "Suite" , "Query name" , "Query ID" ,
120
120
"Kind" , "Severity" , "Precision" , "Tags"
121
121
])
122
122
@@ -132,26 +132,25 @@ def subprocess_run(cmd):
132
132
print (
133
133
"Warning: couldn't find query pack '%s' for language '%s'. Do you have the right repositories in the right places (search path: '%s')?" % (pack , lang , codeql_search_path ),
134
134
file = sys .stderr
135
- )
135
+ )
136
136
continue
137
137
138
138
# Investigate metadata for every query by using 'codeql resolve metadata'
139
139
for queryfile in queries_subp .stdout .strip ().split ("\n " ):
140
140
query_metadata_json = subprocess_run (["codeql" ,"resolve" ,"metadata" ,queryfile ]).stdout .strip ()
141
-
141
+
142
142
# Turn an absolute path to a query file into an nwo-prefixed path (e.g. github/codeql/java/ql/src/....)
143
143
queryfile_nwo = prefix_repo_nwo (queryfile )
144
144
145
145
meta = json .loads (query_metadata_json )
146
146
147
147
# Python's CSV writer will automatically quote fields if necessary
148
148
csvwriter .writerow ([
149
- queryfile_nwo , pack ,
149
+ queryfile_nwo , pack ,
150
150
get_query_metadata ('name' , meta , queryfile_nwo ),
151
151
get_query_metadata ('id' , meta , queryfile_nwo ),
152
152
get_query_metadata ('kind' , meta , queryfile_nwo ),
153
153
get_query_metadata ('problem.severity' , meta , queryfile_nwo ),
154
154
get_query_metadata ('precision' , meta , queryfile_nwo ),
155
155
get_query_metadata ('tags' , meta , queryfile_nwo )
156
156
])
157
-
0 commit comments