10
10
11
11
import doxmlparser
12
12
from docutils import nodes
13
+ from docutils .parsers .rst import directives
13
14
from doxmlparser .compound import DoxCompoundKind , DoxMemberKind
14
15
from sphinx import addnodes
15
16
from sphinx .application import Sphinx
@@ -34,6 +35,9 @@ class DoxygenGroupDirective(SphinxDirective):
34
35
has_content = False
35
36
required_arguments = 1
36
37
optional_arguments = 0
38
+ option_spec = {
39
+ "project" : directives .unchanged ,
40
+ }
37
41
38
42
def run (self ):
39
43
@@ -48,6 +52,7 @@ def run(self):
48
52
reftype = "group" ,
49
53
reftarget = self .arguments [0 ],
50
54
refwarn = True ,
55
+ project = self .options .get ("project" )
51
56
)
52
57
group_xref += nodes .Text (self .arguments [0 ])
53
58
title_signode += group_xref
@@ -73,28 +78,40 @@ def run(self, **kwargs: Any) -> None:
73
78
if reftype in ("member" , "data" ):
74
79
reftype = "var"
75
80
76
- entry = self .app .env .doxybridge_cache .get (reftype )
77
- if not entry :
78
- continue
81
+ found_name = None
82
+ found_id = None
83
+ for name in self .app .config .doxybridge_projects :
84
+ entry = self .app .env .doxybridge_cache [name ].get (reftype )
85
+ if not entry :
86
+ continue
79
87
80
- reftarget = node .get ("reftarget" ).replace ("." , "::" ).rstrip ("()" )
81
- id = entry .get (reftarget )
82
- if not id :
83
- if reftype == "func" :
84
- # macros are sometimes referenced as functions, so try that
85
- id = self .app .env .doxybridge_cache .get ("macro" ).get (reftarget )
86
- if not id :
88
+ reftarget = node .get ("reftarget" ).replace ("." , "::" ).rstrip ("()" )
89
+ id = entry .get (reftarget )
90
+ if not id :
91
+ if reftype == "func" :
92
+ # macros are sometimes referenced as functions, so try that
93
+ id = self .app .env .doxybridge_cache [name ].get ("macro" ).get (reftarget )
94
+ if not id :
95
+ continue
96
+ else :
87
97
continue
88
- else :
89
- continue
98
+
99
+ found_name = name
100
+ found_id = id
101
+ break
102
+
103
+ if not found_name or not found_id :
104
+ continue
90
105
91
106
if reftype in ("struct" , "union" , "group" ):
92
107
doxygen_target = f"{ id } .html"
93
108
else :
94
- split = id .split ("_" )
109
+ split = found_id .split ("_" )
95
110
doxygen_target = f"{ '_' .join (split [:- 1 ])} .html#{ split [- 1 ][1 :]} "
96
111
97
- doxygen_target = str (self .app .config .doxybridge_dir ) + "/html/" + doxygen_target
112
+ doxygen_target = (
113
+ str (self .app .config .doxybridge_projects [found_name ]) + "/html/" + doxygen_target
114
+ )
98
115
99
116
doc_dir = os .path .dirname (self .document .get ("source" ))
100
117
doc_dest = os .path .join (
@@ -109,7 +126,7 @@ def run(self, **kwargs: Any) -> None:
109
126
110
127
if reftype == "group" :
111
128
refnode ["classes" ].append ("doxygroup" )
112
- title = self .app .env .doxybridge_group_titles .get (reftarget , "group" )
129
+ title = self .app .env .doxybridge_group_titles [ found_name ] .get (reftarget , "group" )
113
130
refnode [0 ] = nodes .Text (title )
114
131
115
132
node .replace_self ([refnode ])
@@ -178,7 +195,7 @@ def parse_compound(inDirName, baseName) -> dict:
178
195
return cache , group_titles
179
196
180
197
181
- def parse_index (app : Sphinx , inDirName ):
198
+ def parse_index (app : Sphinx , name , inDirName ):
182
199
rootObj = doxmlparser .index .parse (inDirName + "/index.xml" , True )
183
200
compounds = rootObj .get_compound ()
184
201
@@ -190,33 +207,40 @@ def parse_index(app: Sphinx, inDirName):
190
207
for future in concurrent .futures .as_completed (futures ):
191
208
cache , group_titles = future .result ()
192
209
for kind , data in cache .items ():
193
- app .env .doxybridge_cache .setdefault (kind , {}).update (data )
194
- app .env .doxybridge_group_titles .update (group_titles )
210
+ app .env .doxybridge_cache [ name ] .setdefault (kind , {}).update (data )
211
+ app .env .doxybridge_group_titles [ name ] .update (group_titles )
195
212
196
213
197
214
def doxygen_parse (app : Sphinx ) -> None :
198
- if not app .env .doxygen_input_changed :
199
- return
200
-
201
- app .env .doxybridge_cache = {
202
- "macro" : {},
203
- "var" : {},
204
- "type" : {},
205
- "enum" : {},
206
- "enumerator" : {},
207
- "func" : {},
208
- "union" : {},
209
- "struct" : {},
210
- "group" : {},
211
- }
215
+ if not hasattr (app .env , "doxybridge_cache" ):
216
+ app .env .doxybridge_cache = dict ()
217
+
218
+ if not hasattr (app .env , "doxybridge_group_titles" ):
219
+ app .env .doxybridge_group_titles = dict ()
220
+
221
+ for project , path in app .config .doxybridge_projects .items ():
222
+ if project in app .env .doxygen_input_changed and not app .env .doxygen_input_changed [project ]:
223
+ return
224
+
225
+ app .env .doxybridge_cache [project ] = {
226
+ "macro" : {},
227
+ "var" : {},
228
+ "type" : {},
229
+ "enum" : {},
230
+ "enumerator" : {},
231
+ "func" : {},
232
+ "union" : {},
233
+ "struct" : {},
234
+ "group" : {},
235
+ }
212
236
213
- app .env .doxybridge_group_titles = {}
237
+ app .env .doxybridge_group_titles [ project ] = dict ()
214
238
215
- parse_index (app , str (app . config . doxybridge_dir / "xml" ))
239
+ parse_index (app , project , str (path / "xml" ))
216
240
217
241
218
242
def setup (app : Sphinx ) -> dict [str , Any ]:
219
- app .add_config_value ("doxybridge_dir " , None , "env" )
243
+ app .add_config_value ("doxybridge_projects " , None , "env" )
220
244
221
245
app .add_directive ("doxygengroup" , DoxygenGroupDirective )
222
246
0 commit comments