mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +01:00
This is solving a papercut, where the C++ build was relying on the local dbscheme file to be up-to-date, even if all the information for building is actually in `schema.yml`. This made a pure C++ development cycle with changes to `schema.yml` clumsy, as it required a further dbscheme generation step. Now for C++ the dbscheme is generated internally in the build files, and thus a change in `schema.yml` is reflected immediately in the C++ build. A `swift/codegen` step for checked in generated code (including the dbscheme) is still required, but a developer can do it just before running QL tests or committing, instead of during each C++ recompilation. Some directory reorganization was also carried out, moving specific generator modules to a new `generators` python package, and only leaving the two drivers at the top level.
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
""" generator script scaffolding """
|
|
|
|
import argparse
|
|
import logging
|
|
import sys
|
|
from typing import Set
|
|
|
|
from swift.codegen.lib import render, paths
|
|
from swift.codegen.generators import options
|
|
|
|
|
|
def _parse(tags: Set[str]) -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser()
|
|
for opt in options.get(tags):
|
|
opt.add_to(parser)
|
|
return parser.parse_args()
|
|
|
|
|
|
def run(*modules, **kwargs):
|
|
""" run generation functions in specified in `modules`, or in current module by default
|
|
"""
|
|
if modules:
|
|
if kwargs:
|
|
opts = argparse.Namespace(**kwargs)
|
|
else:
|
|
opts = _parse({t for m in modules for t in m.tags})
|
|
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 m in modules:
|
|
m.generate(opts, render.Renderer(exe_path))
|
|
else:
|
|
run(sys.modules["__main__"], **kwargs)
|