From 483a87abe925388e7319807a076fa54449c4b33e Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 13 Feb 2023 09:32:26 +0100 Subject: [PATCH] Swift: make `codegen` run also outside `bazel` --- swift/codegen/README.md | 7 +++++++ swift/codegen/codegen.py | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/swift/codegen/README.md b/swift/codegen/README.md index d7efe304de79..db94d327da61 100644 --- a/swift/codegen/README.md +++ b/swift/codegen/README.md @@ -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 diff --git a/swift/codegen/codegen.py b/swift/codegen/codegen.py index 58160e9b9982..f9c85ce6049c 100755 --- a/swift/codegen/codegen.py +++ b/swift/codegen/codegen.py @@ -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