chiark / gitweb /
doxygen: avoid having stale url_base when parsing defines.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 18 Jun 2018 11:30:42 +0000 (13:30 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 18 Jun 2018 13:23:29 +0000 (15:23 +0200)
I *knew* something would blow up here.

doxygen/dox2html5.py
doxygen/test/compound_namespace_members_in_file_scope_define_base_url/Doxyfile [new file with mode: 0644]
doxygen/test/compound_namespace_members_in_file_scope_define_base_url/File.h [new file with mode: 0644]
doxygen/test/compound_namespace_members_in_file_scope_define_base_url/File_8h.html [new file with mode: 0644]
doxygen/test/test_compound.py

index 8efd03e0ba5688e5ee77f4a07e6d9735cce6b8e8..3df5c40823a8a81a71cea3f654b5792049561e4d 100755 (executable)
@@ -1719,7 +1719,11 @@ def parse_define(state: State, element: ET.Element):
     assert element.tag == 'memberdef' and element.attrib['kind'] == 'define'
 
     define = Empty()
-    define.id = extract_id_hash(state, element)
+    # defines are always only defined in files, never duplicated to namespaces,
+    # so we don't need to have define.base_url. Can't use extract_id_hash()
+    # here because current_definition_url_base might be stale. See a test in
+    # compound_namespace_members_in_file_scope_define_base_url.
+    state.current_definition_url_base, _, define.id = parse_id(element)
     define.name = element.find('name').text
     define.brief = parse_desc(state, element.find('briefdescription'))
     define.description, params, define.return_value, search_keywords, define.is_deprecated = parse_define_desc(state, element)
diff --git a/doxygen/test/compound_namespace_members_in_file_scope_define_base_url/Doxyfile b/doxygen/test/compound_namespace_members_in_file_scope_define_base_url/Doxyfile
new file mode 100644 (file)
index 0000000..cd500a2
--- /dev/null
@@ -0,0 +1,14 @@
+INPUT                   = File.h
+QUIET                   = YES
+GENERATE_HTML           = NO
+GENERATE_LATEX          = NO
+GENERATE_XML            = YES
+XML_PROGRAMLISTING      = NO
+XML_NAMESPACE_MEMBERS_IN_FILE_SCOPE = YES
+
+##! M_PAGE_FINE_PRINT   =
+##! M_THEME_COLOR       =
+##! M_FAVICON           =
+##! M_LINKS_NAVBAR1     =
+##! M_LINKS_NAVBAR2     =
+##! M_SEARCH_DISABLED   = YES
diff --git a/doxygen/test/compound_namespace_members_in_file_scope_define_base_url/File.h b/doxygen/test/compound_namespace_members_in_file_scope_define_base_url/File.h
new file mode 100644 (file)
index 0000000..0247d16
--- /dev/null
@@ -0,0 +1,22 @@
+/** @file
+ * @brief A file
+ */
+
+/* Preprocessor defines are usually first in the XML file, but if there is a
+   user-defined group, that is first. That triggers a corder case in define ID
+   extraction -- parsing the var will set current base url to namespaceNS,
+   but that shouldn't trigger any error when parsing the define after. */
+
+/** @brief A namespace */
+namespace NS {
+
+/** @{ @name Variables */
+
+int var; /**< @brief A variable */
+
+/*@}*/
+
+}
+
+/** @brief A define */
+#define A_DEFINE
diff --git a/doxygen/test/compound_namespace_members_in_file_scope_define_base_url/File_8h.html b/doxygen/test/compound_namespace_members_in_file_scope_define_base_url/File_8h.html
new file mode 100644 (file)
index 0000000..f266c11
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>File.h file | My Project</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
+  <link rel="stylesheet" href="m-dark+doxygen.compiled.css" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="index.html" id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">My Project</a>
+    </div>
+  </div>
+</nav></header>
+<main><article>
+  <div class="m-container m-container-inflatable">
+    <div class="m-row">
+      <div class="m-col-l-10 m-push-l-1">
+        <h1>
+          File.h <span class="m-thin">file</span>
+        </h1>
+        <p>A file.</p>
+        <div class="m-block m-default">
+          <h3>Contents</h3>
+          <ul>
+            <li>
+              Reference
+              <ul>
+                <li><a href="#namespaces">Namespaces</a></li>
+                <li><a href="#defines">Defines</a></li>
+                <li><a href="#variables">Variables</a></li>
+              </ul>
+            </li>
+          </ul>
+        </div>
+        <section id="namespaces">
+          <h2><a href="#namespaces">Namespaces</a></h2>
+          <dl class="m-dox">
+            <dt>namespace <a href="namespaceNS.html" class="m-dox">NS</a></dt>
+            <dd>A namespace.</dd>
+          </dl>
+        </section>
+        <section id="define-members">
+          <h2><a href="#define-members">Defines</a></h2>
+          <dl class="m-dox">
+            <dt>
+              <span class="m-dox-wrap-bumper">#define <a href="#a144a2a84c08d05de76f6a4a245584810" class="m-dox-self" name="a144a2a84c08d05de76f6a4a245584810">A_DEFINE</a></span>
+            </dt>
+            <dd>A define.</dd>
+          </dl>
+        </section>
+        <section id="variables">
+          <h2><a href="#variables">Variables</a></h2>
+          <dl class="m-dox">
+            <dt>int <a href="namespaceNS.html#a0bd189dc3154c8566a9e70f94b274c33" class="m-dox">var</a></dt>
+            <dd>A variable.</dd>
+          </dl>
+        </section>
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
index 8b2d2be0ffd4d069b4f7143f098e3c755e003e9c..aa91be986910595ce798521dfcfabd7a98810034 100644 (file)
@@ -207,6 +207,18 @@ class NamespaceMembersInFileScope(IntegrationTestCase):
         # The file should have just links to detailed docs
         self.assertEqual(*self.actual_expected_contents('File_8h.html'))
 
+class NamespaceMembersInFileScopeDefineBaseUrl(IntegrationTestCase):
+    def __init__(self, *args, **kwargs):
+        super().__init__(__file__, 'namespace_members_in_file_scope_define_base_url', *args, **kwargs)
+
+    @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.14"),
+                         "https://github.com/doxygen/doxygen/pull/653")
+    def test(self):
+        self.run_dox2html5(wildcard='File_8h.xml')
+
+        # The file should have just links to detailed docs
+        self.assertEqual(*self.actual_expected_contents('File_8h.html'))
+
 class FilenameCase(IntegrationTestCase):
     def __init__(self, *args, **kwargs):
         super().__init__(__file__, 'filename_case', *args, **kwargs)