Skip to content

Commit f07c598

Browse files
authored
Merge pull request github#12164 from github/redsun82/swift-codegen-outside-bazel
Swift: make `codegen` run also outside `bazel`
2 parents 124e4dd + 483a87a commit f07c598

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

swift/codegen/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ separated list to select what to generate (choosing among `dbscheme`, `ql`, `tra
1919
C++ code is generated during build (see [`swift/extractor/trap/BUILD.bazel`](../extractor/trap/BUILD.bazel)). After a
2020
build you can browse the generated code in `bazel-bin/swift/extractor/trap/generated`.
2121

22+
For debugging you can also run `./codegen.py` directly. You must then ensure dependencies are installed, which you can
23+
with the command
24+
25+
```bash
26+
pip3 install -r ./requirements.txt
27+
```
28+
2229
## Implementation notes
2330

2431
The suite uses [mustache templating](https://mustache.github.io/) for generation. Templates are

swift/codegen/codegen.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
import argparse
55
import logging
6-
import pathlib
6+
import os
77
import sys
8-
import importlib
9-
import types
8+
import pathlib
109
import typing
1110

11+
if 'BUILD_WORKSPACE_DIRECTORY' not in os.environ:
12+
# we are not running with `bazel run`, set up module search path
13+
_repo_root = pathlib.Path(__file__).resolve().parents[2]
14+
sys.path.append(str(_repo_root))
15+
1216
from swift.codegen.lib import render, paths
1317
from swift.codegen.generators import generate
1418

0 commit comments

Comments
 (0)