Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 2 | # |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 3 | # Copyright (c) 2016,2018 Cisco and/or its affiliates. |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at: |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
Marek Gradzki | 4746a5d | 2017-01-27 08:57:40 +0100 | [diff] [blame] | 9 | # |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 16 | import argparse |
Marek Gradzki | 568cc60 | 2018-01-26 11:39:27 +0100 | [diff] [blame] | 17 | import logging |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 18 | import os |
| 19 | import sys |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 20 | |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 21 | from jvppgen.types_gen import generate_types |
| 22 | from jvppgen.dto_gen import generate_dtos |
| 23 | from jvppgen.jvpp_ifc_gen import generate_java_ifc |
| 24 | from jvppgen.jvpp_impl_gen import generate_java_impl |
| 25 | from jvppgen.callback_gen import generate_callbacks |
| 26 | from jvppgen.jni_gen import generate_jni |
| 27 | from jvppgen.notification_gen import generate_notifications |
| 28 | from jvppgen.jvpp_future_facade_gen import generate_future_facade |
| 29 | from jvppgen.jvpp_callback_facade_gen import generate_callback_facade |
| 30 | from jvppgen.jvpp_model import JVppModel |
Marek Gradzki | 568cc60 | 2018-01-26 11:39:27 +0100 | [diff] [blame] | 31 | |
| 32 | |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 33 | def generate_jvpp(root_dir, model, logger): |
| 34 | base_dir = "%s/target/%s" % (root_dir, model.plugin_package.replace(".", "/")) |
| 35 | generate_types(_work_dir(base_dir, "types"), model, logger) |
| 36 | generate_dtos(_work_dir(base_dir, "dto"), model, logger) |
| 37 | generate_java_ifc(_work_dir(base_dir), model, logger) |
| 38 | generate_java_impl(_work_dir(base_dir), model, logger) |
| 39 | generate_callbacks(_work_dir(base_dir, "callback"), model, logger) |
| 40 | generate_jni(root_dir, model, logger) |
| 41 | generate_notifications(_work_dir(base_dir, "notification"), model, logger) |
| 42 | generate_future_facade(_work_dir(base_dir, "future"), model, logger) |
| 43 | generate_callback_facade(_work_dir(base_dir, "callfacade"), model, logger) |
Marek Gradzki | 2fee4c8 | 2016-11-25 08:38:29 +0100 | [diff] [blame] | 44 | |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 45 | |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 46 | def _work_dir(work_dir, sub_dir=None): |
| 47 | if sub_dir: |
| 48 | work_dir = "%s/%s" % (work_dir, sub_dir) |
| 49 | try: |
| 50 | os.makedirs(work_dir) |
| 51 | except OSError: |
| 52 | if not os.path.isdir(work_dir): |
| 53 | raise |
| 54 | return work_dir |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 55 | |
| 56 | |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 57 | def _init_logger(): |
| 58 | try: |
| 59 | verbose = int(os.getenv("V", 0)) |
| 60 | except: |
| 61 | verbose = 0 |
| 62 | |
| 63 | log_level = logging.WARNING |
| 64 | if verbose == 1: |
| 65 | log_level = logging.INFO |
| 66 | elif verbose >= 2: |
| 67 | log_level = logging.DEBUG |
| 68 | |
| 69 | logging.basicConfig(stream=sys.stdout, level=log_level) |
| 70 | logger = logging.getLogger("JVPP GEN") |
| 71 | logger.setLevel(log_level) |
| 72 | return logger |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 73 | |
| 74 | |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 75 | if __name__ == '__main__': |
| 76 | logger = _init_logger() |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 77 | |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 78 | argparser = argparse.ArgumentParser(description="VPP Java API generator") |
| 79 | argparser.add_argument('-i', nargs='+', metavar='api_file.json', help="json vpp api file(s)") |
| 80 | argparser.add_argument('--plugin_name') |
| 81 | argparser.add_argument('--root_dir') |
| 82 | args = argparser.parse_args() |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 83 | |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 84 | logger.info("Generating Java API for %s" % args.i) |
| 85 | logger.debug("plugin_name: %s" % args.plugin_name) |
| 86 | logger.debug("root_dir: %s" % args.root_dir) |
Marek Gradzki | 2fee4c8 | 2016-11-25 08:38:29 +0100 | [diff] [blame] | 87 | |
Marek Gradzki | a51ccb5 | 2018-02-09 13:42:12 +0100 | [diff] [blame] | 88 | model = JVppModel(logger, args.i, args.plugin_name) |
| 89 | generate_jvpp(args.root_dir, model, logger) |