Skip to content

Commit 8dd59e5

Browse files
authored
Detect XML structure instead of relying on Doxygen version (#2240)
* Detect XML structure instead of relying on Doxygen version Signed-off-by: Vivek Reddy <[email protected]>
1 parent 6d37506 commit 8dd59e5

File tree

2 files changed

+123
-46
lines changed

2 files changed

+123
-46
lines changed

meta/parse.pl

Lines changed: 113 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5294,68 +5294,136 @@ sub CreateSourcePragmaPop
52945294
WriteSource "#pragma GCC diagnostic pop";
52955295
}
52965296

5297-
sub GetDoxygenVersion
5297+
sub NeedsTwoPassProcessing
52985298
{
5299-
# Try running doxygen --version
5300-
my $version = `doxygen --version 2>/dev/null`;
5301-
chomp $version;
5302-
return $version if $version =~ /^\d+\.\d+\.\d+$/;
5299+
#
5300+
# Detect if XML files require two-pass processing based on their structure.
5301+
#
5302+
# In Doxygen 1.9.8+, the XML structure changed:
5303+
# - sai_*.xml files have empty enum/define sections (just sectiondef exists, no memberdefs)
5304+
# - group_*.xml files contain the actual enum definitions with enumvalues and defines
5305+
#
5306+
# In older Doxygen versions:
5307+
# - sai_*.xml files contain both defines and enums with enumvalues
5308+
# - group_*.xml files don't exist or aren't used
5309+
#
5310+
# Returns 1 if two-pass processing is needed (new structure):
5311+
# - First pass: process all defines from group_*.xml files
5312+
# - Second pass: process enums/typedefs/functions from group_*.xml and sai_*.xml files
5313+
#
5314+
# Returns 0 if single-pass processing is sufficient (old structure):
5315+
# - Process sai_*.xml files only
5316+
#
53035317

5304-
return undef;
5305-
}
5318+
my $sai_file = "$XMLDIR/sai_8h.xml";
53065319

5307-
sub ProcessXmlFiles
5308-
{
5309-
my $doxygen_version = GetDoxygenVersion();
5310-
my $use_group_files = 0;
5311-
5312-
if (defined $doxygen_version) {
5313-
# Doxygen 1.9.8+ puts enum definitions in group_*.xml files instead of sai*_8h.xml
5314-
# Compare version: 1.9.8 or higher
5315-
if ($doxygen_version =~ /^(\d+)\.(\d+)\.(\d+)$/) {
5316-
my ($major, $minor, $patch) = ($1, $2, $3);
5317-
# Convert to comparable number: major*10000 + minor*100 + patch
5318-
my $version_num = $major * 10000 + $minor * 100 + $patch;
5319-
if ($version_num >= 10908) {
5320-
$use_group_files = 1;
5321-
LogInfo "Doxygen version $doxygen_version detected - using group_*.xml files";
5322-
} else {
5323-
LogInfo "Doxygen version $doxygen_version detected - using legacy sai*_8h.xml files only";
5320+
my $saiacl_file = "$XMLDIR/saiacl_8h.xml";
5321+
5322+
return 1 if not -f $sai_file or not -f $saiacl_file;
5323+
5324+
#
5325+
# Check sai_8h.xml for enumvalue with name="SAI_API_SWITCH"
5326+
#
5327+
5328+
my $sai_ref = ReadXml $sai_file;
5329+
5330+
return 1 if not defined $sai_ref->{compounddef}[0];
5331+
5332+
my @sai_sections = @{ $sai_ref->{compounddef}[0]->{sectiondef} };
5333+
5334+
my $has_enumvalue = 0;
5335+
5336+
for my $section (@sai_sections)
5337+
{
5338+
next if not $section->{kind} eq "enum";
5339+
5340+
for my $memberdef (@{ $section->{memberdef} })
5341+
{
5342+
next if not $memberdef->{kind} eq "enum";
5343+
5344+
if (defined $memberdef->{enumvalue})
5345+
{
5346+
for my $enumvalue (@{ $memberdef->{enumvalue} })
5347+
{
5348+
if (defined $enumvalue->{name} and defined $enumvalue->{name}[0] and $enumvalue->{name}[0] eq "SAI_API_SWITCH")
5349+
{
5350+
$has_enumvalue = 1;
5351+
5352+
last;
5353+
}
5354+
}
53245355
}
53255356
}
5357+
5358+
last if $has_enumvalue;
53265359
}
53275360

5328-
if ($use_group_files) {
5329-
# Doxygen 1.9.8+ approach: two-pass processing
5330-
# We need to process #defines BEFORE enums that reference them
5331-
my @all_files = ();
5332-
push @all_files, glob("$XMLDIR/group_*.xml");
5333-
push @all_files, map { "$XMLDIR/$_" } GetSaiXmlFiles($XMLDIR);
5361+
#
5362+
# Check saiacl_8h.xml for memberdef kind="define"
5363+
#
53345364

5335-
# PASS 1: Process ONLY #define sections from all files
5336-
for my $fullpath (@all_files) {
5337-
my $file = $fullpath;
5338-
$file =~ s/^.*\///;
5339-
LogInfo "Processing $file (defines pass)";
5340-
ProcessXmlFileDefinesOnly($fullpath);
5365+
my $saiacl_ref = ReadXml $saiacl_file;
5366+
5367+
return 1 if not defined $saiacl_ref->{compounddef}[0];
5368+
5369+
my @saiacl_sections = @{ $saiacl_ref->{compounddef}[0]->{sectiondef} };
5370+
5371+
my $has_define = 0;
5372+
5373+
for my $section (@saiacl_sections)
5374+
{
5375+
next if not $section->{kind} eq "define";
5376+
5377+
for my $memberdef (@{ $section->{memberdef} })
5378+
{
5379+
if ($memberdef->{kind} eq "define")
5380+
{
5381+
$has_define = 1;
5382+
5383+
last;
5384+
}
53415385
}
53425386

5343-
# PASS 2: Process everything else (enums, typedefs, functions)
5344-
for my $fullpath (@all_files) {
5345-
my $file = $fullpath;
5346-
$file =~ s/^.*\///;
5347-
LogInfo "Processing $file";
5348-
ProcessXmlFile($fullpath);
5387+
last if $has_define;
5388+
}
5389+
5390+
#
5391+
# If sai_8h.xml has enumvalues and saiacl_8h.xml has defines, it's old structure (single-pass)
5392+
# Otherwise, use two-pass processing (group_*.xml files contain the actual content)
5393+
#
5394+
5395+
return not ($has_enumvalue and $has_define);
5396+
}
5397+
5398+
sub ProcessXmlFiles
5399+
{
5400+
if (NeedsTwoPassProcessing())
5401+
{
5402+
LogInfo "New XML structure detected, proceeding with 2 pass processing";
5403+
5404+
my @group_files = GetGroupXmlFiles($XMLDIR);
5405+
5406+
for my $file (@group_files)
5407+
{
5408+
LogInfo "Processing $file (defines pass)";
5409+
5410+
ProcessXmlFileDefinesOnly("$XMLDIR/$file");
53495411
}
5350-
} else {
5351-
# Legacy approach: single-pass, only sai*_8h.xml files
5352-
for my $file (GetSaiXmlFiles($XMLDIR))
5412+
5413+
for my $file (@group_files)
53535414
{
53545415
LogInfo "Processing $file";
53555416

53565417
ProcessXmlFile("$XMLDIR/$file");
53575418
}
53585419
}
5420+
5421+
for my $file (GetSaiXmlFiles($XMLDIR))
5422+
{
5423+
LogInfo "Processing $file";
5424+
5425+
ProcessXmlFile("$XMLDIR/$file");
5426+
}
53595427
}
53605428

53615429
sub ProcessXmlFileDefinesOnly

meta/xmlutils.pm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ sub GetXmlUnionFiles
239239
return grep { /^union_\w*\.xml$/ } @files;
240240
}
241241

242+
sub GetGroupXmlFiles
243+
{
244+
my $dir = shift;
245+
246+
my @files = GetXmlFiles($dir);
247+
248+
return grep { /^group__\w+\.xml$/ } @files;
249+
}
250+
242251
sub ProcessStructCount
243252
{
244253
my ($structName, $tagValue, $previousTagValue) = @_;
@@ -626,7 +635,7 @@ BEGIN
626635
{
627636
our @ISA = qw(Exporter);
628637
our @EXPORT = qw/
629-
ReadXml UnescapeXml GetSaiXmlFiles GetXmlUnionFiles
638+
ReadXml UnescapeXml GetSaiXmlFiles GetXmlUnionFiles GetGroupXmlFiles
630639
ExtractDescription ExtractStructInfo ExtractStructInfoEx
631640
/;
632641
}

0 commit comments

Comments
 (0)