• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright © 2021 Intel Corporation
4#
5# Permission is hereby granted, free of charge, to any person obtaining a
6# copy of this software and associated documentation files (the
7# "Software"), to deal in the Software without restriction, including
8# without limitation the rights to use, copy, modify, merge, publish,
9# distribute, sub license, and/or sell copies of the Software, and to
10# permit persons to whom the Software is furnished to do so, subject to
11# the following conditions:
12#
13# The above copyright notice and this permission notice (including the
14# next paragraph) shall be included in all copies or substantial portions
15# of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25import argparse
26from mako.template import Template
27import os
28import subprocess
29import tempfile
30
31INPUT_PATHS = [
32    'src/compiler/nir/nir.h',
33    'src/intel/isl',
34]
35
36TEMPLATE_DOXYFILE = Template("""
37# Doxyfile 1.9.1
38DOXYFILE_ENCODING = UTF-8
39PROJECT_NAME = "Mesa"
40
41INPUT = ${' '.join(input_files)}
42XML_OUTPUT = ${output_xml}
43
44# Only generate XML
45GENERATE_HTML = NO
46GENERATE_LATEX = NO
47GENERATE_XML = YES
48
49# Add aliases for easily writing reStructuredText in comments
50ALIASES  = "rst=\\verbatim embed:rst:leading-asterisk"
51ALIASES += "endrst=\endverbatim"
52
53ENABLE_PREPROCESSING = YES
54MACRO_EXPANSION = YES
55EXPAND_ONLY_PREDEF = YES
56
57# Defines required to keep doxygen from tripping on our attribute macros
58PREDEFINED  = PACKED=
59PREDEFINED += ATTRIBUTE_CONST=
60""")
61
62def run_doxygen(output_path, input_paths=[]):
63    doxyfile = tempfile.NamedTemporaryFile(mode='w', delete=False)
64    try:
65        doxyfile.write(TEMPLATE_DOXYFILE.render(
66            input_files=[ os.path.abspath(i) for i in input_paths ],
67            output_xml=os.path.abspath(output_path),
68        ))
69        doxyfile.close()
70
71        subprocess.run(['doxygen', doxyfile.name])
72
73    finally:
74        doxyfile.close()
75        os.unlink(doxyfile.name)
76
77if __name__ == '__main__':
78    parser = argparse.ArgumentParser()
79    parser.add_argument('--out-dir',
80                        help='Output XML directory.',
81                        required=True)
82    args = parser.parse_args()
83
84    this_dir = os.path.dirname(os.path.abspath(__file__))
85    mesa_dir = os.path.join(this_dir, '..')
86    def fixpath(p):
87        if os.path.isabs(p):
88            return p
89        return os.path.join(mesa_dir, p)
90
91    input_paths = [ fixpath(p) for p in INPUT_PATHS ]
92
93    run_doxygen(args.out_dir, input_paths)
94