Files
codeql/swift/codegen/codegen.py
Paolo Tranquilli 77f7fe8dbc Swift: merge codegen and cppcodegen
Python code was simplified, and now a `--generate` option can be used
to drive what can be generated.

The extractor pack creation now will use an internally generated
dbscheme. This should be the same as the checked in one, but doing so
allows `bazel run create-extractor-pack` and `bazel run codegen` to be
run independently from one another, while previously the former had to
follow the latter in case of a schema change. This is the change that
triggered the above simplification, as in order for the two dbscheme
files to be identical, the first `// generated` line had to state the
same generator script.
2022-06-01 17:07:52 +02:00

50 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
""" Driver script to run all code generation """
import argparse
import logging
import pathlib
import sys
import importlib
import types
import typing
from swift.codegen.lib import render, paths
from swift.codegen.generators import generate
def _parse_args() -> argparse.Namespace:
p = argparse.ArgumentParser()
p.add_argument("--generate", type=lambda x: x.split(","), default=["dbscheme", "ql"])
p.add_argument("--verbose", "-v", action="store_true")
p.add_argument("--swift-dir", type=_abspath, default=paths.swift_dir)
p.add_argument("--schema", type=_abspath, default=paths.swift_dir / "codegen/schema.yml")
p.add_argument("--dbscheme", type=_abspath, default=paths.swift_dir / "ql/lib/swift.dbscheme")
p.add_argument("--ql-output", type=_abspath, default=paths.swift_dir / "ql/lib/codeql/swift/generated")
p.add_argument("--ql-stub-output", type=_abspath, default=paths.swift_dir / "ql/lib/codeql/swift/elements")
p.add_argument("--ql-format", action="store_true", default=True)
p.add_argument("--no-ql-format", action="store_false", dest="ql_format")
p.add_argument("--codeql-binary", default="codeql")
p.add_argument("--cpp-output", type=_abspath)
p.add_argument("--cpp-namespace", default="codeql")
p.add_argument("--trap-affix", default="Trap")
p.add_argument("--cpp-include-dir", default="swift/extractor/trap")
return p.parse_args()
def _abspath(x: str) -> pathlib.Path:
return pathlib.Path(x).resolve()
def run():
opts = _parse_args()
log_level = logging.DEBUG if opts.verbose else logging.INFO
logging.basicConfig(format="{levelname} {message}", style='{', level=log_level)
exe_path = paths.exe_file.relative_to(opts.swift_dir)
for target in opts.generate:
generate(target, opts, render.Renderer(exe_path))
if __name__ == "__main__":
run()