2017-11-02 14:14:13 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Auto-Generate XS and PM Files Required for Perl
|
|
|
|
####################################################################################################################################
|
|
|
|
package pgBackRestLibC::Build;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
use English '-no_match_vars';
|
|
|
|
|
|
|
|
use Cwd qw(abs_path);
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use Storable qw(dclone);
|
|
|
|
|
|
|
|
use lib dirname($0) . '/../build/lib';
|
|
|
|
use lib dirname($0) . '/../lib';
|
|
|
|
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::Version;
|
|
|
|
|
|
|
|
use pgBackRestBuild::Build;
|
|
|
|
use pgBackRestBuild::Build::Common;
|
2018-11-04 01:52:46 +02:00
|
|
|
use pgBackRestBuild::Config::Data;
|
2018-02-08 23:11:47 +02:00
|
|
|
use pgBackRestBuild::Error::Data;
|
2017-11-02 14:14:13 +02:00
|
|
|
|
2019-06-26 14:24:58 +02:00
|
|
|
use pgBackRestTest::Common::Storage;
|
|
|
|
use pgBackRestTest::Common::StoragePosix;
|
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Perl function and constant exports
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant BLD_EXPORTTYPE_SUB => 'sub';
|
|
|
|
use constant BLD_EXPORTTYPE_CONSTANT => 'constant';
|
|
|
|
|
|
|
|
use constant LIB_AUTO_NAME => 'LibCAuto';
|
|
|
|
|
2018-11-04 01:52:46 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Save contents to a file if the file is missing or the contents are different. This saves write IO and prevents the timestamp from
|
|
|
|
# changing.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub buildPutDiffers
|
|
|
|
{
|
|
|
|
my $oStorage = shift;
|
|
|
|
my $strFile = shift;
|
|
|
|
my $strContents = shift;
|
|
|
|
|
|
|
|
# Attempt to load the file
|
|
|
|
my $bSave = true;
|
|
|
|
my $oFile = $oStorage->openRead($strFile, {bIgnoreMissing => true});
|
|
|
|
|
|
|
|
# If file was found see if the content is the same
|
|
|
|
if (defined($oFile) && ${$oStorage->get($oFile)} eq $strContents)
|
|
|
|
{
|
|
|
|
$bSave = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Save if the contents are different or missing
|
|
|
|
if ($bSave)
|
|
|
|
{
|
|
|
|
$oStorage->put($strFile, $strContents);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $bSave;
|
|
|
|
}
|
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Static exports
|
|
|
|
####################################################################################################################################
|
|
|
|
my $rhExport =
|
|
|
|
{
|
|
|
|
'checksum' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
|
|
|
pageChecksum
|
|
|
|
)],
|
|
|
|
},
|
|
|
|
|
|
|
|
'config' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
|
|
|
cfgCommandName
|
|
|
|
cfgOptionIndex
|
|
|
|
cfgOptionIndexTotal
|
|
|
|
cfgOptionName
|
|
|
|
)],
|
|
|
|
},
|
|
|
|
|
|
|
|
'configDefine' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
|
|
|
cfgCommandId
|
|
|
|
cfgDefOptionDefault
|
|
|
|
cfgDefOptionPrefix
|
|
|
|
cfgDefOptionSecure
|
|
|
|
cfgDefOptionType
|
|
|
|
cfgDefOptionValid
|
|
|
|
cfgOptionId
|
|
|
|
cfgOptionTotal
|
|
|
|
)],
|
|
|
|
},
|
|
|
|
|
2018-06-11 20:52:26 +02:00
|
|
|
'crypto' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
|
|
|
CIPHER_MODE_ENCRYPT
|
|
|
|
CIPHER_MODE_DECRYPT
|
|
|
|
cryptoHashOne
|
|
|
|
)],
|
|
|
|
},
|
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
'debug' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
2018-05-22 18:53:08 +02:00
|
|
|
libcUvSize
|
2017-11-02 14:14:13 +02:00
|
|
|
)],
|
|
|
|
},
|
|
|
|
|
|
|
|
'encode' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_CONSTANT => [qw(
|
|
|
|
ENCODE_TYPE_BASE64
|
|
|
|
)],
|
|
|
|
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
|
|
|
decodeToBin
|
|
|
|
encodeToStr
|
|
|
|
)],
|
|
|
|
},
|
2017-11-03 19:57:58 +02:00
|
|
|
|
2018-04-11 15:36:12 +02:00
|
|
|
'lock' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
|
|
|
lockAcquire
|
|
|
|
lockRelease
|
|
|
|
)],
|
|
|
|
},
|
|
|
|
|
2017-11-03 19:57:58 +02:00
|
|
|
'random' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
2018-11-07 03:04:16 +02:00
|
|
|
cryptoRandomBytes
|
2017-11-03 19:57:58 +02:00
|
|
|
)],
|
|
|
|
},
|
2018-02-05 19:32:30 +02:00
|
|
|
|
2018-04-11 14:21:09 +02:00
|
|
|
'storage' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
2019-06-26 14:24:58 +02:00
|
|
|
storageRepoFree
|
2018-04-11 14:21:09 +02:00
|
|
|
)],
|
|
|
|
},
|
|
|
|
|
2018-02-05 19:32:30 +02:00
|
|
|
'test' =>
|
|
|
|
{
|
|
|
|
&BLD_EXPORTTYPE_SUB => [qw(
|
|
|
|
cfgParseTest
|
|
|
|
)],
|
|
|
|
},
|
2017-11-02 14:14:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Execute all build functions
|
|
|
|
####################################################################################################################################
|
|
|
|
sub buildXsAll
|
|
|
|
{
|
|
|
|
my $strBuildPath = shift;
|
|
|
|
|
2018-11-04 01:52:46 +02:00
|
|
|
# List of files built
|
|
|
|
my @stryBuilt;
|
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
# Storage
|
2019-06-26 14:24:58 +02:00
|
|
|
my $oStorage = new pgBackRestTest::Common::Storage(
|
|
|
|
$strBuildPath, new pgBackRestTest::Common::StoragePosix({bFileSync => false, bPathSync => false}));
|
2017-11-02 14:14:13 +02:00
|
|
|
|
|
|
|
# Build interface file
|
|
|
|
my $strContent =
|
|
|
|
('#' x 132) . "\n" .
|
|
|
|
'# ' . bldAutoWarning('Build.pm') . "\n" .
|
|
|
|
('#' x 132) . "\n" .
|
|
|
|
"package pgBackRest::LibCAuto;\n" .
|
|
|
|
"\n" .
|
2018-05-22 18:53:08 +02:00
|
|
|
"use strict;\n" .
|
|
|
|
"use warnings;\n";
|
2017-11-02 14:14:13 +02:00
|
|
|
|
|
|
|
# Generate constants for options that have a list of strings as allowed values
|
|
|
|
my $rhConfigDefine = cfgDefine();
|
|
|
|
my $strConstantBlock;
|
|
|
|
|
|
|
|
foreach my $strOption (sort(keys(%{$rhConfigDefine})))
|
|
|
|
{
|
|
|
|
my $rhOption = $rhConfigDefine->{$strOption};
|
|
|
|
|
|
|
|
next if $rhOption->{&CFGDEF_TYPE} ne CFGDEF_TYPE_STRING;
|
|
|
|
next if $strOption =~ /^log-level-/;
|
|
|
|
|
|
|
|
if (defined($rhOption->{&CFGDEF_ALLOW_LIST}))
|
|
|
|
{
|
|
|
|
$strConstantBlock .= defined($strConstantBlock) ? "\n" : '';
|
|
|
|
|
|
|
|
foreach my $strValue (@{$rhOption->{&CFGDEF_ALLOW_LIST}})
|
|
|
|
{
|
|
|
|
my $strConstant = 'CFGOPTVAL_' . uc("${strOption}_${strValue}");
|
|
|
|
$strConstant =~ s/\-/\_/g;
|
|
|
|
|
|
|
|
$strConstantBlock .= " ${strConstant}" . (' ' x (69 - length($strConstant) - 4)) . "=> '${strValue}',\n";
|
|
|
|
push(@{$rhExport->{'config'}{&BLD_EXPORTTYPE_CONSTANT}}, $strConstant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $strCommand (sort(keys(%{$rhOption->{&CFGDEF_COMMAND}})))
|
|
|
|
{
|
|
|
|
my $rhCommand = $rhOption->{&CFGDEF_COMMAND}{$strCommand};
|
|
|
|
|
|
|
|
if (defined($rhCommand->{&CFGDEF_ALLOW_LIST}))
|
|
|
|
{
|
|
|
|
$strConstantBlock .= defined($strConstantBlock) ? "\n" : '';
|
|
|
|
|
|
|
|
foreach my $strValue (@{$rhCommand->{&CFGDEF_ALLOW_LIST}})
|
|
|
|
{
|
|
|
|
my $strConstant = 'CFGOPTVAL_' . uc("${strCommand}_${strOption}_${strValue}");
|
|
|
|
$strConstant =~ s/\-/\_/g;
|
|
|
|
|
|
|
|
$strConstantBlock .= " ${strConstant}" . (' ' x (69 - length($strConstant) - 4)) . "=> '${strValue}',\n";
|
|
|
|
push(@{$rhExport->{'config'}{&BLD_EXPORTTYPE_CONSTANT}}, $strConstant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Generate command constants
|
|
|
|
foreach my $strCommand (cfgDefineCommandList())
|
|
|
|
{
|
|
|
|
my $strConstant = "CFGCMD_" . uc($strCommand);
|
|
|
|
$strConstant =~ s/\-/\_/g;
|
|
|
|
|
|
|
|
push(@{$rhExport->{'config'}{&BLD_EXPORTTYPE_CONSTANT}}, $strConstant);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate option constants
|
|
|
|
foreach my $strOption (sort(keys(%{$rhConfigDefine})))
|
|
|
|
{
|
|
|
|
# Build Perl constant
|
|
|
|
my $strConstant = "CFGOPT_" . uc($strOption);
|
|
|
|
$strConstant =~ s/\-/\_/g;
|
|
|
|
|
2018-08-25 01:31:45 +02:00
|
|
|
# Builds option data
|
|
|
|
for (my $iOptionIndex = 1; $iOptionIndex <= $rhConfigDefine->{$strOption}{&CFGDEF_INDEX_TOTAL}; $iOptionIndex++)
|
|
|
|
{
|
|
|
|
push(@{$rhExport->{'config'}{&BLD_EXPORTTYPE_CONSTANT}}, $strConstant . ($iOptionIndex == 1 ? '' : $iOptionIndex));
|
|
|
|
}
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate option type constants
|
|
|
|
$strConstantBlock .= defined($strConstantBlock) ? "\n" : '';
|
2018-08-25 01:31:45 +02:00
|
|
|
my $iIndex = 0;
|
2018-05-22 18:53:08 +02:00
|
|
|
|
|
|
|
foreach my $strOptionType (cfgDefineOptionTypeList())
|
|
|
|
{
|
|
|
|
# Build Perl constant
|
|
|
|
my $strConstant = "CFGDEF_TYPE_" . uc($strOptionType);
|
|
|
|
$strConstant =~ s/\-/\_/g;
|
|
|
|
|
|
|
|
$strConstantBlock .=
|
|
|
|
" ${strConstant}" . (' ' x (69 - length($strConstant) - 4)) . "=> $iIndex,\n";
|
|
|
|
push(@{$rhExport->{'configDefine'}{&BLD_EXPORTTYPE_CONSTANT}}, $strConstant);
|
|
|
|
|
|
|
|
$iIndex++;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Generate encode type constants
|
|
|
|
$strConstantBlock .= defined($strConstantBlock) ? "\n" : '';
|
|
|
|
|
|
|
|
my $strConstant = "ENCODE_TYPE_BASE64";
|
|
|
|
$strConstantBlock .=
|
|
|
|
" ${strConstant}" . (' ' x (69 - length($strConstant) - 4)) . "=> 0,\n";
|
|
|
|
|
|
|
|
# Generate cipher type constants
|
|
|
|
$strConstantBlock .= defined($strConstantBlock) ? "\n" : '';
|
|
|
|
|
|
|
|
$strConstant = "CIPHER_MODE_ENCRYPT";
|
|
|
|
$strConstantBlock .=
|
|
|
|
" ${strConstant}" . (' ' x (69 - length($strConstant) - 4)) . "=> 0,\n";
|
|
|
|
$strConstant = "CIPHER_MODE_DECRYPT";
|
|
|
|
$strConstantBlock .=
|
|
|
|
" ${strConstant}" . (' ' x (69 - length($strConstant) - 4)) . "=> 1,\n";
|
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
$strContent .=
|
|
|
|
"\n" .
|
|
|
|
"# Configuration option value constants\n" .
|
|
|
|
"sub libcAutoConstant\n" .
|
|
|
|
"{\n" .
|
2017-11-06 19:51:12 +02:00
|
|
|
" return\n" .
|
2017-11-02 14:14:13 +02:00
|
|
|
" {\n" .
|
|
|
|
" " . trim($strConstantBlock) . "\n" .
|
|
|
|
" }\n" .
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
# Generate export tags
|
|
|
|
my $strExportTags;
|
|
|
|
|
|
|
|
foreach my $strSection (sort(keys(%{$rhExport})))
|
|
|
|
{
|
|
|
|
my $rhExportSection = $rhExport->{$strSection};
|
|
|
|
|
|
|
|
$strExportTags .= (defined($strExportTags) ? "\n" : '') . " ${strSection} =>\n [\n";
|
|
|
|
|
|
|
|
if (defined($rhExportSection->{&BLD_EXPORTTYPE_CONSTANT}) && @{$rhExportSection->{&BLD_EXPORTTYPE_CONSTANT}} > 0)
|
|
|
|
{
|
|
|
|
foreach my $strConstant (@{$rhExportSection->{&BLD_EXPORTTYPE_CONSTANT}})
|
|
|
|
{
|
|
|
|
$strExportTags .= " '${strConstant}',\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($rhExportSection->{&BLD_EXPORTTYPE_SUB}) && @{$rhExportSection->{&BLD_EXPORTTYPE_SUB}} > 0)
|
|
|
|
{
|
|
|
|
foreach my $strSub (@{$rhExportSection->{&BLD_EXPORTTYPE_SUB}})
|
|
|
|
{
|
|
|
|
$strExportTags .= " '${strSub}',\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$strExportTags .= " ],\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$strContent .=
|
|
|
|
"\n" .
|
|
|
|
"# Export function and constants\n" .
|
|
|
|
"sub libcAutoExportTag\n" .
|
|
|
|
"{\n" .
|
|
|
|
" return\n" .
|
|
|
|
" {\n" .
|
|
|
|
$strExportTags .
|
|
|
|
" }\n" .
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
# Add module end marker
|
|
|
|
$strContent .=
|
|
|
|
"\n" .
|
|
|
|
"1;\n";
|
|
|
|
|
2018-03-10 06:00:20 +02:00
|
|
|
# Save the file
|
2018-11-25 02:05:03 +02:00
|
|
|
my $strFile = 'lib/' . PROJECT_NAME . '/' . LIB_AUTO_NAME . '.pm';
|
2018-11-04 01:52:46 +02:00
|
|
|
|
|
|
|
if (buildPutDiffers($oStorage, "../${strFile}", $strContent))
|
|
|
|
{
|
|
|
|
push(@stryBuilt, $strFile);
|
|
|
|
}
|
2018-02-08 23:11:47 +02:00
|
|
|
|
|
|
|
# Build error file
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
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};
|
|
|
|
$rhErrorId->{$iCode} = $strType;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Output errors
|
|
|
|
$strContent =
|
|
|
|
('#' x 132) . "\n" .
|
|
|
|
"# COMMON EXCEPTION AUTO MODULE\n" .
|
|
|
|
"# \n" .
|
|
|
|
'# ' . bldAutoWarning('Build.pm') . "\n" .
|
|
|
|
('#' x 132) . "\n" .
|
|
|
|
"package pgBackRest::Common::ExceptionAuto;\n" .
|
|
|
|
"\n" .
|
|
|
|
"use strict;\n" .
|
|
|
|
"use warnings FATAL => qw(all);\n" .
|
|
|
|
"\n" .
|
|
|
|
"use Exporter qw(import);\n" .
|
|
|
|
" our \@EXPORT = qw();\n" .
|
|
|
|
"\n" .
|
|
|
|
('#' x 132) . "\n" .
|
|
|
|
"# Error Definitions\n" .
|
|
|
|
('#' x 132) . "\n" .
|
|
|
|
"use constant ERROR_MINIMUM => " . ERRDEF_MIN . ";\n" .
|
|
|
|
"push \@EXPORT, qw(ERROR_MINIMUM);\n" .
|
|
|
|
"use constant ERROR_MAXIMUM => " . ERRDEF_MAX . ";\n" .
|
|
|
|
"push \@EXPORT, qw(ERROR_MAXIMUM);\n" .
|
|
|
|
"\n";
|
|
|
|
|
|
|
|
foreach my $iCode (sort({sprintf("%03d", $a) cmp sprintf("%03d", $b)} keys(%{$rhErrorId})))
|
|
|
|
{
|
|
|
|
my $strType = "ERROR_" . uc($rhErrorId->{$iCode});
|
|
|
|
$strType =~ s/\-/\_/g;
|
|
|
|
|
|
|
|
$strContent .=
|
|
|
|
"use constant ${strType}" . (' ' x (54 - length($strType))) . " => $iCode;\n" .
|
|
|
|
"push \@EXPORT, qw(${strType});\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
$strContent .=
|
|
|
|
"\n" .
|
|
|
|
"1;\n";
|
|
|
|
|
2018-11-25 02:05:03 +02:00
|
|
|
$strFile = 'lib/' . PROJECT_NAME . '/Common/ExceptionAuto.pm';
|
2018-11-04 01:52:46 +02:00
|
|
|
|
|
|
|
if (buildPutDiffers($oStorage, "../${strFile}", $strContent))
|
|
|
|
{
|
|
|
|
push(@stryBuilt, $strFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return list of files built
|
|
|
|
return @stryBuilt;
|
2017-11-02 14:14:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(buildXsAll);
|
|
|
|
|
|
|
|
1;
|