summaryrefslogtreecommitdiff
path: root/utils/ipc/extract-docs.py
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2021-05-24 16:46:42 +0900
committerPaul Elder <paul.elder@ideasonboard.com>2021-05-27 17:07:04 +0900
commitbd06b648fb1c7b0a137f23f15cd5e72c5edd881a (patch)
tree237d422df2b9479a14923b33c5bc96faa391f45b /utils/ipc/extract-docs.py
parent6c5f3fe6ced796eb396926a22394a45724e02fef (diff)
utils: ipc: Add script to extract doxygen docs from mojom files
Add a script to extract doxygen documentation comments from mojom files. It matches based on ^\/\*\*$ for start of block and ^ \*\/$ for end of block, and simply copies the comments to the output file along with a header and the libcamera namespace. Also add it to the meson file so it is usable by other meson files. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Acked-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'utils/ipc/extract-docs.py')
-rwxr-xr-xutils/ipc/extract-docs.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/utils/ipc/extract-docs.py b/utils/ipc/extract-docs.py
new file mode 100755
index 00000000..56566ce0
--- /dev/null
+++ b/utils/ipc/extract-docs.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2021, Google Inc.
+#
+# Author: Paul Elder <paul.elder@ideasonboard.com>
+#
+# extract-docs.py - Extract doxygen documentation from mojom files
+
+import argparse
+import re
+import sys
+
+regex_block_start = re.compile('^\/\*\*$')
+regex_block_end = re.compile('^ \*\/$')
+
+
+def main(argv):
+
+ # Parse command line arguments
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-o', dest='output', metavar='file',
+ type=argparse.FileType('w', encoding='utf-8'),
+ default=sys.stdout,
+ help='Output file name (default: standard output)')
+ parser.add_argument('input', type=str,
+ help='Input file name.')
+ args = parser.parse_args(argv[1:])
+
+ lines = open(args.input, 'r').readlines()
+ pipeline = args.input.split('/')[-1].replace('.mojom', '')
+ data = f'''\
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2021, Google Inc.
+ *
+ * {pipeline}_ipa_interface.cpp - Docs file for generated {pipeline}.mojom
+ *
+ * This file is auto-generated. Do not edit.
+ */
+
+namespace libcamera {{
+
+'''
+
+ in_block = False
+ comment = ''
+ for lineno, line in enumerate(lines, start=1):
+ if regex_block_start.match(line):
+ if in_block:
+ raise SyntaxError('Expected end of comment',
+ (args.input, lineno, 1, line))
+ in_block = True
+ comment = line
+ continue
+
+ if regex_block_end.match(line):
+ if in_block:
+ comment += line
+ data += comment + '\n'
+ in_block = False
+ continue
+
+ if in_block:
+ comment += line
+
+ data += '} /* namespace libcamera */\n'
+
+ args.output.write(data)
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))