Skip to content

Commit 67df890

Browse files
committed
Misc: Fail by default if query pack can't be found
1 parent 9386a90 commit 67df890

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

misc/scripts/generate-code-scanning-query-list.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import csv
44
import sys
55
import os
6+
import argparse
67

78
"""
89
This script collects CodeQL queries that are part of code scanning query packs
@@ -16,6 +17,15 @@
1617
and 'codeql-go' directories both exist)
1718
"""
1819

20+
parser = argparse.ArgumentParser(__name__)
21+
parser.add_argument(
22+
"--ignore-missing-query-packs",
23+
action="store_true",
24+
help="Don't fail if a query pack can't be found",
25+
)
26+
arguments = parser.parse_args()
27+
assert hasattr(arguments, "ignore_missing_query_packs")
28+
1929
# Define which languages and query packs to consider
2030
languages = [ "cpp", "csharp", "go", "java", "javascript", "python"]
2131
packs = [ "code-scanning", "security-and-quality", "security-extended" ]
@@ -129,11 +139,15 @@ def subprocess_run(cmd):
129139
except Exception as e:
130140
# Resolving queries might go wrong if the github/codeql and github/codeql-go repositories are not
131141
# on the search path.
142+
level = "Warning" if arguments.ignore_missing_query_packs else "Error"
132143
print(
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),
144+
"%s: couldn't find query pack '%s' for language '%s'. Do you have the right repositories in the right places (search path: '%s')?" % (level, pack, lang, codeql_search_path),
134145
file=sys.stderr
135146
)
136-
continue
147+
if arguments.ignore_missing_query_packs:
148+
continue
149+
else:
150+
sys.exit("You can use '--ignore-missing-query-packs' to ignore this error")
137151

138152
# Investigate metadata for every query by using 'codeql resolve metadata'
139153
for queryfile in queries_subp.stdout.strip().split("\n"):

0 commit comments

Comments
 (0)