Skip to content

Commit

Permalink
msggen: Start making the msggen library a standalone tool
Browse files Browse the repository at this point in the history
There are quite some things we want to generate from the schema
definitions, both inside and outside of CLN itself. By bundling the
schemas into the library we can make use of the tooling without
running in the CLN source tree. This is in part used to generate some
of the interfaces in Greenlight.

Changelog-None
  • Loading branch information
cdecker committed Feb 8, 2024
1 parent b5bd907 commit 00fbd59
Show file tree
Hide file tree
Showing 10 changed files with 17,010 additions and 27 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ include connectd/Makefile
include lightningd/Makefile
include cli/Makefile
include doc/Makefile
include contrib/msggen/Makefile
include devtools/Makefile
include tools/Makefile
include plugins/Makefile
Expand All @@ -368,8 +369,8 @@ ifneq ($(RUST),0)
include cln-rpc/Makefile
include cln-grpc/Makefile

$(MSGGEN_GENALL)&: doc/schemas/*.request.json doc/schemas/*.schema.json
PYTHONPATH=contrib/msggen $(PYTHON) contrib/msggen/msggen/__main__.py
$(MSGGEN_GENALL)&: contrib/msggen/msggen/schema.json
PYTHONPATH=contrib/msggen $(PYTHON) contrib/msggen/msggen/__main__.py generate

# The compiler assumes that the proto files are in the same
# directory structure as the generated files will be. Since we
Expand Down
2 changes: 1 addition & 1 deletion cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contrib/msggen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contrib/msggen/dist/
4 changes: 4 additions & 0 deletions contrib/msggen/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /usr/bin/make

contrib/msggen/msggen/schema.json: ${SCHEMAS}
PYTHONPATH=contrib/msggen ${PYTHON} contrib/msggen/msggen/__main__.py bundle doc/schemas
35 changes: 22 additions & 13 deletions contrib/msggen/msggen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from msggen.gen.grpc2py import Grpc2PyGenerator
from msggen.gen.rust import RustGenerator
from msggen.gen.generator import GeneratorChain
from msggen.utils import load_jsonrpc_service
from msggen.utils import load_jsonrpc_service, combine_schemas
import logging
from msggen.patch import VersionAnnotationPatch, OptionalPatch, OverridePatch
from msggen.checks import VersioningCheck
Expand Down Expand Up @@ -62,11 +62,9 @@ def write_msggen_meta(meta):
os.rename(f'.msggen.json.tmp.{pid}', '.msggen.json')


def run(rootdir: Path):
schemadir = rootdir / "doc" / "schemas"
def run():
meta = load_msggen_meta()
service = load_jsonrpc_service(
schema_dir=schemadir,
)

p = VersionAnnotationPatch(meta=meta)
Expand All @@ -91,14 +89,25 @@ def run(rootdir: Path):
write_msggen_meta(meta)


if __name__ == "__main__":
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--rootdir',
dest='rootdir',
default='.'
)
subcmds = parser.add_subparsers(required=True, dest='command')
bundle = subcmds.add_parser("bundle", help="bundle schemas into package")
bundle.add_argument('schema_dir', action='store')

subcmds.add_parser("generate", help="generate all files")
args = parser.parse_args()
run(
rootdir=Path(args.rootdir)
)

if args.command == 'generate':
run()
elif args.command == 'bundle':
dest = Path(__file__).parent / 'schema.json'
src = Path(__file__).parent / '..' / '..' / '..' / 'doc' / 'schemas'

print(f"Combining schemas from {src.resolve()} into {dest.resolve()}")
schema = combine_schemas(src, dest)
print(f"Created {dest} from {len(schema)} files")


if __name__ == "__main__":
main()
Loading

0 comments on commit 00fbd59

Please sign in to comment.