mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-04-25 12:04:48 +02:00
This directory was once the home of the production Perl code but since f0ef73db this is no longer true. Move the modules to test in most cases, except where the module is expected to be useful for the doc engine beyond the expected lifetime of the Perl test code (about a year if all goes well). The exception is pgBackRest::Version which requires more work to migrate since it is used to track pgBackRest versions.
137 lines
4.4 KiB
Perl
137 lines
4.4 KiB
Perl
####################################################################################################################################
|
|
# Auto-Generate Error Mappings
|
|
####################################################################################################################################
|
|
package pgBackRestBuild::Error::Build;
|
|
|
|
use strict;
|
|
use warnings FATAL => qw(all);
|
|
use Carp qw(confess);
|
|
use English '-no_match_vars';
|
|
|
|
use Exporter qw(import);
|
|
our @EXPORT = qw();
|
|
|
|
use BackRestDoc::Common::Log;
|
|
|
|
use pgBackRestBuild::Build::Common;
|
|
use pgBackRestBuild::Error::Data;
|
|
|
|
####################################################################################################################################
|
|
# Constants
|
|
####################################################################################################################################
|
|
use constant BLDLCL_FILE_DEFINE => 'error';
|
|
|
|
use constant BLDLCL_DATA_ERROR => '01-dataError';
|
|
use constant BLDLCL_DATA_ERROR_ARRAY => '01-dataErrorArray';
|
|
|
|
####################################################################################################################################
|
|
# Definitions for constants and data to build
|
|
####################################################################################################################################
|
|
my $strSummary = 'Error Type Definition';
|
|
|
|
my $rhBuild =
|
|
{
|
|
&BLD_FILE =>
|
|
{
|
|
&BLDLCL_FILE_DEFINE =>
|
|
{
|
|
&BLD_SUMMARY => $strSummary,
|
|
|
|
&BLD_DECLARE =>
|
|
{
|
|
&BLDLCL_DATA_ERROR =>
|
|
{
|
|
&BLD_SUMMARY => 'Error type declarations',
|
|
},
|
|
},
|
|
|
|
&BLD_DATA =>
|
|
{
|
|
&BLDLCL_DATA_ERROR =>
|
|
{
|
|
&BLD_SUMMARY => 'Error type definitions',
|
|
},
|
|
|
|
&BLDLCL_DATA_ERROR_ARRAY =>
|
|
{
|
|
&BLD_SUMMARY => 'Error type array',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
####################################################################################################################################
|
|
# Build configuration constants and data
|
|
####################################################################################################################################
|
|
sub buildError
|
|
{
|
|
# Build error list
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
my $rhErrorDefine = errorDefine();
|
|
|
|
# Order by id for the list that is id ordered
|
|
my $rhErrorId = {};
|
|
|
|
foreach my $strType (sort(keys(%{$rhErrorDefine})))
|
|
{
|
|
my $iCode = $rhErrorDefine->{$strType};
|
|
|
|
if (defined($rhErrorId->{$iCode}))
|
|
{
|
|
confess &log(ERROR, "error code ${iCode} is by '" . $rhErrorId->{$iCode} . "' and '${strType}'");
|
|
}
|
|
|
|
$rhErrorId->{$iCode} = $strType;
|
|
}
|
|
|
|
# Output errors
|
|
my $strBuildSource;
|
|
|
|
foreach my $iCode (sort({sprintf("%03d", $a) cmp sprintf("%03d", $b)} keys(%{$rhErrorId})))
|
|
{
|
|
my $strType = $rhErrorId->{$iCode};
|
|
|
|
$strBuildSource .=
|
|
"ERROR_DECLARE(" . bldEnum("", $strType, true) . "Error);\n";
|
|
}
|
|
|
|
$rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_DECLARE}{&BLDLCL_DATA_ERROR}{&BLD_SOURCE} = $strBuildSource;
|
|
|
|
# Output error definition data
|
|
$strBuildSource = undef;
|
|
|
|
foreach my $iCode (sort({sprintf("%03d", $a) cmp sprintf("%03d", $b)} keys(%{$rhErrorId})))
|
|
{
|
|
my $strType = $rhErrorId->{$iCode};
|
|
|
|
$strBuildSource .=
|
|
"ERROR_DEFINE(" . (' ' x (3 - length($iCode))) . "${iCode}, " . bldEnum("", $strType, true) . "Error, RuntimeError);\n";
|
|
}
|
|
|
|
$rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_DATA}{&BLDLCL_DATA_ERROR}{&BLD_SOURCE} = $strBuildSource;
|
|
|
|
# Output error array
|
|
$strBuildSource =
|
|
"static const ErrorType *errorTypeList[] =\n" .
|
|
"{\n";
|
|
|
|
foreach my $iCode (sort({sprintf("%03d", $a) cmp sprintf("%03d", $b)} keys(%{$rhErrorId})))
|
|
{
|
|
$strBuildSource .=
|
|
" &" . bldEnum("", $rhErrorId->{$iCode}, true) . "Error,\n";
|
|
}
|
|
|
|
$strBuildSource .=
|
|
" NULL,\n" .
|
|
"};";
|
|
|
|
$rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_DATA}{&BLDLCL_DATA_ERROR_ARRAY}{&BLD_SOURCE} = $strBuildSource;
|
|
|
|
return $rhBuild;
|
|
}
|
|
|
|
push @EXPORT, qw(buildError);
|
|
|
|
1;
|