aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2019-07-15 15:22:31 -0400
committerDave Wallace <dwallacelf@gmail.com>2019-07-17 13:41:02 +0000
commit9529feb4525dfd13e5636640083361256121d275 (patch)
tree3422ce636b9c97458f258e7b25d43cba50b9ceef /src/tools
parent6e8b811ee409bff97996cd60d2ae04e884fd66d3 (diff)
build: add targets for json api files
Type: make Ticket: VPP-1715 Change-Id: I78497d679d9e793b47a06a0c5cb3b12d86b08489 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'src/tools')
-rwxr-xr-xsrc/tools/vppapigen/generate_json.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/tools/vppapigen/generate_json.py b/src/tools/vppapigen/generate_json.py
new file mode 100755
index 00000000000..6987cd21f25
--- /dev/null
+++ b/src/tools/vppapigen/generate_json.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python3
+# Copyright (c) 2019. Vinci Consulting Corp. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import argparse
+import pathlib
+import subprocess
+BASE_DIR = subprocess.check_output('git rev-parse --show-toplevel',
+ shell=True).strip().decode()
+vppapigen_bin = pathlib.Path(
+ '%s/src/tools/vppapigen/vppapigen.py' % BASE_DIR).as_posix()
+
+api_types = ['vnet', 'plugins']
+src_dir_depth = 3
+output_path = pathlib.Path(
+ '%s/build-root/install-vpp-native/vpp/share/vpp/api/' % BASE_DIR)
+output_path_debug = pathlib.Path(
+ '%s/build-root/install-vpp_debug-native/vpp/share/vpp/api/' % BASE_DIR)
+
+output_dir_map = {'vnet': 'core',
+ 'plugins': 'plugins'}
+
+
+def api_search_globs(src_dir):
+ globs = []
+ for g in api_types:
+ globs.extend(list(src_dir.glob('%s/**/*.api' % g)))
+ return globs
+
+
+def api_files(src_dir):
+ print("Searching '%s' for .api files." % src_dir.as_posix())
+ return [x for x in api_search_globs(src_dir)]
+
+
+def vppapigen(vppapigen_bin, output_path, src_dir, src_file):
+ try:
+ subprocess.check_output(
+ [vppapigen_bin, '--includedir', src_dir.as_posix(),
+ '--input', src_file.as_posix(), 'JSON',
+ '--output', '%s/%s/%s.json' % (
+ output_path,
+ output_dir_map[src_file.as_posix().split('/')[
+ src_dir_depth + BASE_DIR.count('/') - 1]],
+ src_file.name)])
+ except KeyError:
+ print('src_file: %s' % src_file)
+ raise
+
+
+def main():
+ cliparser = argparse.ArgumentParser(
+ description='VPP API JSON definition generator')
+ cliparser.add_argument('--srcdir', action='store',
+ default='%s/src' % BASE_DIR),
+ cliparser.add_argument('--output', action='store',
+ help='directory to store files'),
+ cliparser.add_argument('--debug-target', action='store_true',
+ default=False,
+ help="'True' if -debug target"),
+ args = cliparser.parse_args()
+
+ src_dir = pathlib.Path(args.srcdir)
+ output_target = output_path_debug if args.debug_target else output_path
+
+ if args.output:
+ output_dir = pathlib.Path(args.output)
+ else:
+ output_dir = pathlib.Path(output_target)
+
+ for d in output_dir_map.values():
+ output_dir.joinpath(d).mkdir(exist_ok=True, parents=True)
+
+ for f in output_dir.glob('**/*.api.json'):
+ f.unlink()
+
+ for f in api_files(src_dir):
+ vppapigen(vppapigen_bin, output_dir, src_dir, f)
+ print('json files written to: %s/.' % output_dir)
+
+
+if __name__ == '__main__':
+ main()