codeql/misc/codegen
Paolo Tranquilli bd08bc7923 Rust: address review 2024-10-15 14:21:11 +02:00
..
generators Merge pull request #17537 from github/redsun82/rust-doctest-gen 2024-09-23 11:41:32 +02:00
lib Rust: address review 2024-10-15 14:21:11 +02:00
loaders Codegen: move `use_for_null` to pragmas 2024-09-20 12:47:45 +02:00
templates Codegen: Do not cache injectors/projectors in `Synth` module 2024-09-24 14:41:20 +02:00
test Rust: address review 2024-10-15 14:21:11 +02:00
.pep8
BUILD.bazel Bazel: introduce buildifier formatting 2024-04-24 15:49:48 +02:00
README.md Codegen: update `README.md` files 2023-02-27 10:01:50 +01:00
codegen.py Codegen/Rust: allow breaking up schema file 2024-09-19 15:57:42 +02:00
requirements_in.txt Bazel: use bzlmod 2024-02-12 10:55:40 +01:00
requirements_lock.txt Bazel: use bzlmod 2024-02-12 10:55:40 +01:00
schema_documentation.md Rust: archiving + skeleton def translator 2024-08-28 17:15:49 +02:00

README.md

Code generation suite

This directory contains the code generation suite used by the Swift extractor and the QL library. This suite will use the abstract class specification of schema.py to generate:

An example schema.py can be found in the Swift package.

Usage

By default bazel run //misc/codegen -- -c your-codegen.conf will load options from your-codegen.conf. See the Swift configuration for an example. Calling misc/codegen/codegen.py directly (provided you installed dependencies via pip3 install -r misc/codegen/requirements.txt) will use a file named codegen.conf contained in an ancestor directory if any exists.

See bazel run //misc/codegen -- --help for a list of all options. In particular --generate can be used with a comma separated list to select what to generate (choosing among dbscheme, ql, trap and cpp).

Implementation notes

The suite uses mustache templating for generation. Templates are in the templates directory, prefixed with the generation target they are used for.

Rather than passing dictionaries to the templating engine, python dataclasses are used as defined in the lib directory. For each of the four generation targets the entry point for the implementation is specified as the generate function in the modules within the generators directory.

Finally, codegen.py is the driver script gluing everything together and specifying the command line options.

Unit tests are in the test directory and can be run via bazel test //misc/codegen/test.

For more details about each specific generation target, please refer to the module docstrings in the generators directory.