Skip to content

Commit

Permalink
Fix C++ apigen support for macros with Sphinx >= 7.4 (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbms authored Oct 26, 2024
1 parent 69e685a commit fcc5f76
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
25 changes: 16 additions & 9 deletions sphinx_immaterial/apidoc/cpp/symbol_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,23 @@ def add_declaration(declaration, docname: str, line: int):
symbol.siblingBelow.siblingAbove = siblingAbove
symbol.siblingBelow = None

# Remove duplicate symbol that was just created
for other_symbol in symbol.parent._children:
if other_symbol.declaration is declaration:
assert other_symbol.isRedeclaration
other_symbol.remove()
break
parent_children = symbol.parent._children
if isinstance(parent_children, list):
# Remove duplicate symbol that was just created
for other_symbol in symbol.parent._children:
if other_symbol.declaration is declaration:
assert other_symbol.isRedeclaration
other_symbol.remove()
break
else:
raise AssertionError(
"Duplicate symbol not found: %r" % (symbol.dump(2),)
)
else:
raise AssertionError(
"Duplicate symbol not found: %r" % (symbol.dump(2),)
)
# Updated C domain that stores children as a dict and does
# not create duplicates
# (https://github.com/sphinx-doc/sphinx/pull/12162).
pass
return symbol

parentSymbol.add_declaration = add_declaration
Expand Down
36 changes: 36 additions & 0 deletions tests/cpp_apigen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,39 @@ def test_unnamed_template_parameter(immaterial_make_app):
app.build()

assert not app._warning.getvalue()


def test_macro(immaterial_make_app):
app = immaterial_make_app(
extra_conf="""
extensions.append("sphinx_immaterial.apidoc.cpp.apigen")
""",
confoverrides=dict(
nitpicky=True,
cpp_apigen_configs=[
dict(
document_prefix="cpp_apigen_generated/",
api_parser_config=dict(
input_content=r"""
/// Tests something.
///
/// \ingroup Array
#define IS_ARRAY(x) x + 1
""",
compiler_flags=["-std=c++17", "-x", "c++"],
verbose=True,
),
),
],
),
files={
"index.rst": """
.. cpp-apigen-group:: Array
"""
},
)

app.build()

assert not app._warning.getvalue()

0 comments on commit fcc5f76

Please sign in to comment.