From 90c0c902f3dceaddff0b4c613178a47617db26e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 9 Apr 2018 12:55:45 +0200 Subject: [PATCH] doxygen: prevent particular Doxyfile values from becoming empty. In particular the HTML_EXTRA_STYLESHEET, which is set to empty by the doxygen -g generated Doxyfile. --- doxygen/.gitignore | 2 + doxygen/dox2html5.py | 21 ++++- .../test/layout_generated_doxyfile/index.html | 91 +++++++++++++++++++ .../xml/indexpage.xml | 11 +++ doxygen/test/test_layout.py | 13 +++ 5 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 doxygen/test/layout_generated_doxyfile/index.html create mode 100644 doxygen/test/layout_generated_doxyfile/xml/indexpage.xml diff --git a/doxygen/.gitignore b/doxygen/.gitignore index 0f08147f..234111b9 100644 --- a/doxygen/.gitignore +++ b/doxygen/.gitignore @@ -1,4 +1,6 @@ test/*/html/ test/*/xml/ +test/layout_generated_doxyfile/Doxyfile +!test/layout_generated_doxyfile/xml/ test/node_modules/ coverage/ diff --git a/doxygen/dox2html5.py b/doxygen/dox2html5.py index 9554388f..fb95c08e 100755 --- a/doxygen/dox2html5.py +++ b/doxygen/dox2html5.py @@ -27,6 +27,7 @@ import xml.etree.ElementTree as ET import argparse import base64 +import copy import sys import re import html @@ -2587,11 +2588,7 @@ def parse_doxyfile(state: State, doxyfile, config = None): variable_continuation_re = re.compile(r"""^\s*(?P[A-Z_]+)\s*\+=\s*(?P['"]?)(?P.*)(?P=quote)\s*(?P\\?)$""") continuation_re = re.compile(r"""^\s*(?P['"]?)(?P.*)(?P=quote)\s*(?P\\?)$""") - # Defaults so we don't fail with minimal Doxyfiles and also that the - # user-provided Doxygen can append to them. They are later converted to - # string or kept as a list based on type, so all have to be a list of - # strings now. - if not config: config = { + default_config = { 'PROJECT_NAME': ['My Project'], 'OUTPUT_DIRECTORY': [''], 'XML_OUTPUT': ['xml'], @@ -2621,6 +2618,12 @@ list using and 'M_SEARCH_EXTERNAL_URL': [''] } + # Defaults so we don't fail with minimal Doxyfiles and also that the + # user-provided Doxygen can append to them. They are later converted to + # string or kept as a list based on type, so all have to be a list of + # strings now. + if not config: config = copy.deepcopy(default_config) + def parse_value(var): if var.group('quote') == '"': out = [var.group('value')] @@ -2686,6 +2689,14 @@ list using and logging.warning("{}: unmatchable line {}".format(doxyfile, line)) # pragma: no cover + # Some values are set to empty in the default-generated Doxyfile but they + # shouldn't be empty. Revert them to our defaults. + # TODO: this may behave strange in corner cases where multiple @INCLUDEd + # files set or append to the same thing + for i in ['HTML_EXTRA_STYLESHEET']: + if i in config and not config[i]: + config[i] = default_config[i] + # String values that we want for i in ['PROJECT_NAME', 'PROJECT_BRIEF', diff --git a/doxygen/test/layout_generated_doxyfile/index.html b/doxygen/test/layout_generated_doxyfile/index.html new file mode 100644 index 00000000..4a692453 --- /dev/null +++ b/doxygen/test/layout_generated_doxyfile/index.html @@ -0,0 +1,91 @@ + + + + + My Project + + + + + + +
+
+
+
+
+

+ My Project +

+
+
+
+
+ + + +
+ + diff --git a/doxygen/test/layout_generated_doxyfile/xml/indexpage.xml b/doxygen/test/layout_generated_doxyfile/xml/indexpage.xml new file mode 100644 index 00000000..fa7a2a87 --- /dev/null +++ b/doxygen/test/layout_generated_doxyfile/xml/indexpage.xml @@ -0,0 +1,11 @@ + + + + index + My Project + + + + + + diff --git a/doxygen/test/test_layout.py b/doxygen/test/test_layout.py index de5cecf8..28971441 100644 --- a/doxygen/test/test_layout.py +++ b/doxygen/test/test_layout.py @@ -23,6 +23,7 @@ # import os +import subprocess from test import BaseTestCase @@ -37,6 +38,18 @@ class Layout(BaseTestCase): self.assertTrue(os.path.exists(os.path.join(self.path, 'html', 'search.js'))) self.assertTrue(os.path.exists(os.path.join(self.path, 'html', 'searchdata.js'))) +class LayoutGeneratedDoxyfile(BaseTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'generated_doxyfile', *args, **kwargs) + + def test(self): + if os.path.exists(os.path.join(self.path, 'Doxyfile')): + os.remove(os.path.join(self.path, 'Doxyfile')) + + subprocess.run(['doxygen', '-g'], cwd=self.path) + self.run_dox2html5(wildcard='indexpage.xml') + self.assertEqual(*self.actual_expected_contents('index.html')) + class LayoutMinimal(BaseTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'minimal', *args, **kwargs) -- 2.30.2