mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Codegen/Rust: allow breaking up schema file
This commit is contained in:
@@ -43,8 +43,8 @@ def _parse_args() -> argparse.Namespace:
|
|||||||
"compute QL imports and in some comments and as root for relative paths provided as options. "
|
"compute QL imports and in some comments and as root for relative paths provided as options. "
|
||||||
"If not provided it defaults to the directory of the configuration file, if any")
|
"If not provided it defaults to the directory of the configuration file, if any")
|
||||||
path_arguments = [
|
path_arguments = [
|
||||||
p.add_argument("--schema", default="schema.py",
|
p.add_argument("--schema",
|
||||||
help="input schema file (default %(default)s)"),
|
help="input schema file (default schema.py)"),
|
||||||
p.add_argument("--dbscheme",
|
p.add_argument("--dbscheme",
|
||||||
help="output file for dbscheme generation, input file for trap generation"),
|
help="output file for dbscheme generation, input file for trap generation"),
|
||||||
p.add_argument("--ql-output",
|
p.add_argument("--ql-output",
|
||||||
@@ -87,6 +87,8 @@ def _parse_args() -> argparse.Namespace:
|
|||||||
setattr(opts, flag, getattr(defaults, flag))
|
setattr(opts, flag, getattr(defaults, flag))
|
||||||
if opts.root_dir is None:
|
if opts.root_dir is None:
|
||||||
opts.root_dir = opts.configuration_file.parent
|
opts.root_dir = opts.configuration_file.parent
|
||||||
|
if opts.schema is None:
|
||||||
|
opts.schema = "schema.py"
|
||||||
if not opts.generate:
|
if not opts.generate:
|
||||||
p.error("Nothing to do, specify --generate")
|
p.error("Nothing to do, specify --generate")
|
||||||
# absolutize all paths
|
# absolutize all paths
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
""" schema loader """
|
""" schema loader """
|
||||||
|
import sys
|
||||||
|
|
||||||
import inflection
|
import inflection
|
||||||
import typing
|
import typing
|
||||||
@@ -140,6 +141,8 @@ def load(m: types.ModuleType) -> schema.Schema:
|
|||||||
continue
|
continue
|
||||||
if name.startswith("__"):
|
if name.startswith("__"):
|
||||||
continue
|
continue
|
||||||
|
if isinstance(data, types.ModuleType):
|
||||||
|
continue
|
||||||
cls = _get_class(data)
|
cls = _get_class(data)
|
||||||
if classes and not cls.bases:
|
if classes and not cls.bases:
|
||||||
raise schema.Error(
|
raise schema.Error(
|
||||||
@@ -160,7 +163,10 @@ def load(m: types.ModuleType) -> schema.Schema:
|
|||||||
|
|
||||||
|
|
||||||
def load_file(path: pathlib.Path) -> schema.Schema:
|
def load_file(path: pathlib.Path) -> schema.Schema:
|
||||||
spec = importlib.util.spec_from_file_location("schema", path)
|
assert path.suffix in ("", ".py")
|
||||||
module = importlib.util.module_from_spec(spec)
|
sys.path.insert(0, str(path.parent))
|
||||||
spec.loader.exec_module(module)
|
try:
|
||||||
|
module = importlib.import_module(path.with_suffix("").name)
|
||||||
|
finally:
|
||||||
|
sys.path.remove(str(path.parent))
|
||||||
return load(module)
|
return load(module)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ package(default_visibility = ["//rust:__subpackages__"])
|
|||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "schema",
|
name = "schema",
|
||||||
srcs = ["schema.py"],
|
srcs = glob(["schema/*.py"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# configuration file for Rust code generation default options
|
# configuration file for Rust code generation default options
|
||||||
|
--schema=schema
|
||||||
--generate=dbscheme,rusttest,ql,rust
|
--generate=dbscheme,rusttest,ql,rust
|
||||||
--dbscheme=ql/lib/rust.dbscheme
|
--dbscheme=ql/lib/rust.dbscheme
|
||||||
--ql-output=ql/lib/codeql/rust/elements/internal/generated
|
--ql-output=ql/lib/codeql/rust/elements/internal/generated
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ locatable_locations(
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// from schema.py
|
// from schema
|
||||||
|
|
||||||
@element =
|
@element =
|
||||||
@locatable
|
@locatable
|
||||||
|
|||||||
16
rust/schema/__init__.py
Normal file
16
rust/schema/__init__.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
Schema description
|
||||||
|
|
||||||
|
This file should be kept simple:
|
||||||
|
* no flow control
|
||||||
|
* no aliases
|
||||||
|
* only class definitions with annotations and `include` calls
|
||||||
|
|
||||||
|
For how documentation of generated QL code works, please read `misc/codegen/schema_documentation.md`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .prelude import *
|
||||||
|
from .ast import *
|
||||||
|
|
||||||
|
include("../shared/tree-sitter-extractor/src/generator/prefix.dbscheme")
|
||||||
|
include("prefix.dbscheme")
|
||||||
@@ -1,60 +1,4 @@
|
|||||||
"""
|
from .prelude import *
|
||||||
Schema description
|
|
||||||
|
|
||||||
This file should be kept simple:
|
|
||||||
* no flow control
|
|
||||||
* no aliases
|
|
||||||
* only class definitions with annotations and `include` calls
|
|
||||||
|
|
||||||
For how documentation of generated QL code works, please read `misc/codegen/schema_documentation.md`.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from misc.codegen.lib.schemadefs import *
|
|
||||||
|
|
||||||
include("../shared/tree-sitter-extractor/src/generator/prefix.dbscheme")
|
|
||||||
include("prefix.dbscheme")
|
|
||||||
|
|
||||||
|
|
||||||
@qltest.skip
|
|
||||||
class Element:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@qltest.skip
|
|
||||||
class Locatable(Element):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@qltest.skip
|
|
||||||
class AstNode(Locatable):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@qltest.skip
|
|
||||||
class Unextracted(Element):
|
|
||||||
"""
|
|
||||||
The base class marking everything that was not properly extracted for some reason, such as:
|
|
||||||
* syntax errors
|
|
||||||
* insufficient context information
|
|
||||||
* yet unimplemented parts of the extractor
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@qltest.skip
|
|
||||||
class Missing(Unextracted):
|
|
||||||
"""
|
|
||||||
The base class marking errors during parsing or resolution.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@qltest.skip
|
|
||||||
class Unimplemented(Unextracted):
|
|
||||||
"""
|
|
||||||
The base class for unimplemented nodes. This is used to mark nodes that are not yet extracted.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AssocItem(AstNode):
|
class AssocItem(AstNode):
|
||||||
pass
|
pass
|
||||||
41
rust/schema/prelude.py
Normal file
41
rust/schema/prelude.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
from misc.codegen.lib.schemadefs import *
|
||||||
|
|
||||||
|
@qltest.skip
|
||||||
|
class Element:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@qltest.skip
|
||||||
|
class Locatable(Element):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@qltest.skip
|
||||||
|
class AstNode(Locatable):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@qltest.skip
|
||||||
|
class Unextracted(Element):
|
||||||
|
"""
|
||||||
|
The base class marking everything that was not properly extracted for some reason, such as:
|
||||||
|
* syntax errors
|
||||||
|
* insufficient context information
|
||||||
|
* yet unimplemented parts of the extractor
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@qltest.skip
|
||||||
|
class Missing(Unextracted):
|
||||||
|
"""
|
||||||
|
The base class marking errors during parsing or resolution.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@qltest.skip
|
||||||
|
class Unimplemented(Unextracted):
|
||||||
|
"""
|
||||||
|
The base class for unimplemented nodes. This is used to mark nodes that are not yet extracted.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user