File tree Expand file tree Collapse file tree 8 files changed +74
-64
lines changed Expand file tree Collapse file tree 8 files changed +74
-64
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,8 @@ def _parse_args() -> argparse.Namespace:
43
43
"compute QL imports and in some comments and as root for relative paths provided as options. "
44
44
"If not provided it defaults to the directory of the configuration file, if any" )
45
45
path_arguments = [
46
- p .add_argument ("--schema" , default = "schema.py" ,
47
- help = "input schema file (default %(default)s )" ),
46
+ p .add_argument ("--schema" ,
47
+ help = "input schema file (default schema.py )" ),
48
48
p .add_argument ("--dbscheme" ,
49
49
help = "output file for dbscheme generation, input file for trap generation" ),
50
50
p .add_argument ("--ql-output" ,
@@ -87,6 +87,8 @@ def _parse_args() -> argparse.Namespace:
87
87
setattr (opts , flag , getattr (defaults , flag ))
88
88
if opts .root_dir is None :
89
89
opts .root_dir = opts .configuration_file .parent
90
+ if opts .schema is None :
91
+ opts .schema = "schema.py"
90
92
if not opts .generate :
91
93
p .error ("Nothing to do, specify --generate" )
92
94
# absolutize all paths
Original file line number Diff line number Diff line change 1
1
""" schema loader """
2
+ import sys
2
3
3
4
import inflection
4
5
import typing
@@ -140,6 +141,8 @@ def load(m: types.ModuleType) -> schema.Schema:
140
141
continue
141
142
if name .startswith ("__" ) or name == "_" :
142
143
continue
144
+ if isinstance (data , types .ModuleType ):
145
+ continue
143
146
cls = _get_class (data )
144
147
if classes and not cls .bases :
145
148
raise schema .Error (
@@ -160,7 +163,10 @@ def load(m: types.ModuleType) -> schema.Schema:
160
163
161
164
162
165
def load_file (path : pathlib .Path ) -> schema .Schema :
163
- spec = importlib .util .spec_from_file_location ("schema" , path )
164
- module = importlib .util .module_from_spec (spec )
165
- spec .loader .exec_module (module )
166
+ assert path .suffix in ("" , ".py" )
167
+ sys .path .insert (0 , str (path .parent ))
168
+ try :
169
+ module = importlib .import_module (path .with_suffix ("" ).name )
170
+ finally :
171
+ sys .path .remove (str (path .parent ))
166
172
return load (module )
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ package(default_visibility = ["//rust:__subpackages__"])
9
9
10
10
filegroup (
11
11
name = "schema" ,
12
- srcs = ["schema.py" ],
12
+ srcs = glob ( ["schema/* .py" ]) ,
13
13
)
14
14
15
15
filegroup (
Original file line number Diff line number Diff line change 1
1
# configuration file for Rust code generation default options
2
+ --schema=schema
2
3
--generate=dbscheme,rusttest,ql,rust
3
4
--dbscheme=ql/lib/rust.dbscheme
4
5
--ql-output=ql/lib/codeql/rust/elements/internal/generated
Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ locatable_locations(
117
117
);
118
118
119
119
120
- // from schema.py
120
+ // from schema
121
121
122
122
@element =
123
123
@locatable
Original file line number Diff line number Diff line change
1
+ """
2
+ Schema description
3
+
4
+ This file should be kept simple:
5
+ * no flow control
6
+ * no aliases
7
+ * only class definitions with annotations and `include` calls
8
+
9
+ For how documentation of generated QL code works, please read `misc/codegen/schema_documentation.md`.
10
+ """
11
+
12
+ from .prelude import *
13
+ from .ast import *
14
+
15
+ include ("../shared/tree-sitter-extractor/src/generator/prefix.dbscheme" )
16
+ include ("prefix.dbscheme" )
Original file line number Diff line number Diff line change 1
- """
2
- Schema description
3
-
4
- This file should be kept simple:
5
- * no flow control
6
- * no aliases
7
- * only class definitions with annotations and `include` calls
8
-
9
- For how documentation of generated QL code works, please read `misc/codegen/schema_documentation.md`.
10
- """
11
-
12
- from misc .codegen .lib .schemadefs import *
13
-
14
- include ("../shared/tree-sitter-extractor/src/generator/prefix.dbscheme" )
15
- include ("prefix.dbscheme" )
16
-
17
-
18
- @qltest .skip
19
- class Element :
20
- pass
21
-
22
-
23
- @qltest .skip
24
- class Locatable (Element ):
25
- pass
26
-
27
-
28
- @qltest .skip
29
- class AstNode (Locatable ):
30
- pass
31
-
32
-
33
- @qltest .skip
34
- class Unextracted (Element ):
35
- """
36
- The base class marking everything that was not properly extracted for some reason, such as:
37
- * syntax errors
38
- * insufficient context information
39
- * yet unimplemented parts of the extractor
40
- """
41
- pass
42
-
43
-
44
- @qltest .skip
45
- class Missing (Unextracted ):
46
- """
47
- The base class marking errors during parsing or resolution.
48
- """
49
-
50
-
51
- @qltest .skip
52
- class Unimplemented (Unextracted ):
53
- """
54
- The base class for unimplemented nodes. This is used to mark nodes that are not yet extracted.
55
- """
56
- pass
57
-
1
+ from .prelude import *
58
2
59
3
class AssocItem (AstNode ):
60
4
pass
Original file line number Diff line number Diff line change
1
+ from misc .codegen .lib .schemadefs import *
2
+
3
+ @qltest .skip
4
+ class Element :
5
+ pass
6
+
7
+
8
+ @qltest .skip
9
+ class Locatable (Element ):
10
+ pass
11
+
12
+
13
+ @qltest .skip
14
+ class AstNode (Locatable ):
15
+ pass
16
+
17
+
18
+ @qltest .skip
19
+ class Unextracted (Element ):
20
+ """
21
+ The base class marking everything that was not properly extracted for some reason, such as:
22
+ * syntax errors
23
+ * insufficient context information
24
+ * yet unimplemented parts of the extractor
25
+ """
26
+ pass
27
+
28
+
29
+ @qltest .skip
30
+ class Missing (Unextracted ):
31
+ """
32
+ The base class marking errors during parsing or resolution.
33
+ """
34
+
35
+
36
+ @qltest .skip
37
+ class Unimplemented (Unextracted ):
38
+ """
39
+ The base class for unimplemented nodes. This is used to mark nodes that are not yet extracted.
40
+ """
41
+ pass
You can’t perform that action at this time.
0 commit comments