Skip to content

Swift: make codegen run also outside bazel #12164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions swift/codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ separated list to select what to generate (choosing among `dbscheme`, `ql`, `tra
C++ code is generated during build (see [`swift/extractor/trap/BUILD.bazel`](../extractor/trap/BUILD.bazel)). After a
build you can browse the generated code in `bazel-bin/swift/extractor/trap/generated`.

For debugging you can also run `./codegen.py` directly. You must then ensure dependencies are installed, which you can
with the command

```bash
pip3 install -r ./requirements.txt
```

## Implementation notes

The suite uses [mustache templating](https://mustache.github.io/) for generation. Templates are
Expand Down
10 changes: 7 additions & 3 deletions swift/codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

import argparse
import logging
import pathlib
import os
import sys
import importlib
import types
import pathlib
import typing

if 'BUILD_WORKSPACE_DIRECTORY' not in os.environ:
# we are not running with `bazel run`, set up module search path
_repo_root = pathlib.Path(__file__).resolve().parents[2]
sys.path.append(str(_repo_root))

from swift.codegen.lib import render, paths
from swift.codegen.generators import generate

Expand Down