1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-09-16 09:06:18 +02:00

Embed exported C functions and Perl modules directly into the pgBackRest executable.

This commit is contained in:
David Steele
2018-05-22 12:53:08 -04:00
parent ada5c5c0d9
commit 4c7408ea52
32 changed files with 27463 additions and 1308 deletions

View File

@@ -12,8 +12,8 @@ services:
- docker - docker
env: env:
- PGB_CI="--vm=co6 test"
- PGB_CI="--vm=u16 test" - PGB_CI="--vm=u16 test"
- PGB_CI="--vm=co6 test"
- PGB_CI="--vm=co7 test" - PGB_CI="--vm=co7 test"
- PGB_CI="--vm=u12 test" - PGB_CI="--vm=u12 test"
- PGB_CI="doc" - PGB_CI="doc"

View File

@@ -33,8 +33,6 @@ use constant BLD_HEADER => 'h';
use constant BLD_CONSTANT => 'constant'; use constant BLD_CONSTANT => 'constant';
push @EXPORT, qw(BLD_CONSTANT); push @EXPORT, qw(BLD_CONSTANT);
use constant BLD_CONSTANT_EXPORT => 'constantExport';
push @EXPORT, qw(BLD_CONSTANT_EXPORT);
use constant BLD_CONSTANT_GROUP => 'constantGroup'; use constant BLD_CONSTANT_GROUP => 'constantGroup';
push @EXPORT, qw(BLD_CONSTANT_GROUP); push @EXPORT, qw(BLD_CONSTANT_GROUP);
use constant BLD_CONSTANT_VALUE => 'constantValue'; use constant BLD_CONSTANT_VALUE => 'constantValue';

View File

@@ -0,0 +1,115 @@
####################################################################################################################################
# Auto-Generate Embedded Perl Modules
####################################################################################################################################
package pgBackRestBuild::Embed::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 pgBackRestBuild::Build::Common;
use pgBackRest::Common::Log;
use pgBackRest::Common::String;
####################################################################################################################################
# Constants
####################################################################################################################################
use constant BLDLCL_FILE_DEFINE => 'embed';
use constant BLDLCL_DATA_EMBED => '01-dataEmbed';
####################################################################################################################################
# Definitions for constants and data to build
####################################################################################################################################
my $strSummary = 'Embed Perl modules';
my $rhBuild =
{
&BLD_FILE =>
{
&BLDLCL_FILE_DEFINE =>
{
&BLD_SUMMARY => $strSummary,
&BLD_DATA =>
{
&BLDLCL_DATA_EMBED =>
{
&BLD_SUMMARY => 'Embedded Perl modules',
},
},
},
},
};
####################################################################################################################################
# Embed Perl modules
####################################################################################################################################
sub buildEmbed
{
my $oStorage = shift;
# Output embedded modules array
my $strBuildSource =
"static const EmbeddedModule embeddedModule[] =\n" .
"{\n";
foreach my $strModule (sort(keys(%{$oStorage->manifest('lib')})))
{
# Ignore non-Perl modules
if ($strModule =~ /\.pm$/)
{
# Load data
my $strData = trim(${$oStorage->get("lib/${strModule}")});
# Escape \ and quotes
$strData =~ s/\\/\\\\/g;
$strData =~ s/\"/\\\"/g;
$strBuildSource .=
" {\n" .
" .name = \"${strModule}\",\n" .
" .data =\n";
# Process each line
foreach my $strLine (split("\n", $strData))
{
# Remove comments
$strLine =~ s/^\s*\#.*$//;
$strLine =~ s/\#[^\'\"]*$//;
# Remove spacing in constant declarations
if ($strLine =~ /use constant [A-Z0-9_]+/)
{
$strLine =~ s/\s{2,}\=\> / \=\> /g;
}
# Remove leading/trailing spaces
$strLine = trim($strLine);
# Output line
$strBuildSource .=
" \"$strLine\\n\"\n";
}
$strBuildSource .=
" },\n";
}
}
$strBuildSource .=
"};";
$rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_DATA}{&BLDLCL_DATA_EMBED}{&BLD_SOURCE} = $strBuildSource;
return $rhBuild;
}
push @EXPORT, qw(buildEmbed);
1;

View File

@@ -33,6 +33,10 @@
</release-bug-list> </release-bug-list>
<release-improvement-list> <release-improvement-list>
<release-item>
<p>Embed exported C functions and Perl modules directly into the <backrest/> executable.</p>
</release-item>
<release-item> <release-item>
<release-item-contributor-list> <release-item-contributor-list>
<release-item-ideator id="floersch.nick"/> <release-item-ideator id="floersch.nick"/>

View File

@@ -205,33 +205,6 @@
<!-- ======================================================================================================================= --> <!-- ======================================================================================================================= -->
<block-define id="br-install"> <block-define id="br-install">
<p keyword="default"><backrest/> is written in Perl which is included with {[user-guide-os]} by default. Some additional modules must also be installed but they are available as standard packages.</p>
<execute-list host="{[br-install-host]}" keyword="default">
<title>Install required Perl packages</title>
<execute user="root">
<exe-cmd>apt-get update</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>apt-get install libdbd-pg-perl libio-socket-ssl-perl libxml-libxml-perl</exe-cmd>
<exe-cmd-extra>-y 2>&amp;1</exe-cmd-extra>
</execute>
</execute-list>
<p keyword="co6"><backrest/> is written in Perl which is not included with {[user-guide-os]} by default, however all required modules are available as standard packages.</p>
<execute-list host="{[br-install-host]}" keyword="co6">
<title>Install required Perl packages</title>
<execute user="root">
<exe-cmd>yum install perl perl-Time-HiRes perl-parent perl-JSON
perl-Digest-SHA perl-DBD-Pg perl-XML-LibXML perl-IO-Socket-SSL</exe-cmd>
<exe-cmd-extra>-y 2>&amp;1</exe-cmd-extra>
</execute>
</execute-list>
<p keyword="default">{[user-guide-os]} packages for <backrest/> are available at <link url="https://www.postgresql.org/download/linux/ubuntu/">apt.postgresql.org</link>. If they are not provided for your distribution/version it is easy to download the source and install manually.</p> <p keyword="default">{[user-guide-os]} packages for <backrest/> are available at <link url="https://www.postgresql.org/download/linux/ubuntu/">apt.postgresql.org</link>. If they are not provided for your distribution/version it is easy to download the source and install manually.</p>
<p keyword="co6">{[user-guide-os]} packages for <backrest/> are available from <link url="{[crunchy-url-base]}">Crunchy Data</link> or <link url="http://yum.postgresql.org">yum.postgresql.org</link>, but it is also easy to download the source and install manually.</p> <p keyword="co6">{[user-guide-os]} packages for <backrest/> are available from <link url="{[crunchy-url-base]}">Crunchy Data</link> or <link url="http://yum.postgresql.org">yum.postgresql.org</link>, but it is also easy to download the source and install manually.</p>
@@ -250,12 +223,6 @@
<execute user="root" show="n"> <execute user="root" show="n">
<exe-cmd>mkdir /root/pgbackrest-release-{[version]}</exe-cmd> <exe-cmd>mkdir /root/pgbackrest-release-{[version]}</exe-cmd>
</execute> </execute>
<execute user="root" show="n">
<exe-cmd>cp -r /backrest/build /root/pgbackrest-release-{[version]}</exe-cmd>
</execute>
<execute user="root" show="n">
<exe-cmd>cp -r /backrest/lib /root/pgbackrest-release-{[version]}</exe-cmd>
</execute>
<execute user="root" show="n"> <execute user="root" show="n">
<exe-cmd>cp -r /backrest/libc /root/pgbackrest-release-{[version]}</exe-cmd> <exe-cmd>cp -r /backrest/libc /root/pgbackrest-release-{[version]}</exe-cmd>
</execute> </execute>
@@ -264,62 +231,8 @@
</execute> </execute>
</execute-list> </execute-list>
<execute-list host="{[br-install-host]}">
<title>Install <backrest/></title>
<execute user="root">
<exe-cmd>cp -r /root/pgbackrest-release-{[version]}/lib/pgBackRest
{[perl-lib-path]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>find {[perl-lib-path]}/pgBackRest -type f -exec chmod 644 {} +</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>find {[perl-lib-path]}/pgBackRest -type d -exec chmod 755 {} +</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>mkdir -m 770 /var/log/pgbackrest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>chown {[br-install-user]}:{[br-install-group]} /var/log/pgbackrest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>mkdir {[backrest-config-path]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>mkdir {[backrest-config-include-path]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>touch {[backrest-config-demo]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>chmod 640 {[backrest-config-demo]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>chown {[br-install-user]}:{[br-install-group]} {[backrest-config-demo]}</exe-cmd>
</execute>
</execute-list>
<!-- LibC installation -->
<p><backrest/> requires a companion C library that enhances performance and enables the `checksum-page` option and encryption. Pre-built packages are generally a better option than building the C library manually but the steps required are given below for completeness. Depending on the distribution a number of packages may be required which will not be enumerated here.</p>
<execute-list host="{[br-install-host]}">
<title>Build and Install C Library</title>
<execute user="root">
<exe-cmd>sh -c 'cd /root/pgbackrest-release-{[version]}/libc &amp;&amp;
perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none'</exe-cmd>
</execute>
<execute user="root" err-suppress="y">
<exe-cmd>make -C /root/pgbackrest-release-{[version]}/libc test</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>make -C /root/pgbackrest-release-{[version]}/libc install</exe-cmd>
</execute>
</execute-list>
<!-- Bin installation --> <!-- Bin installation -->
<p>Although most of <backrest/> is written in Perl, the main executable is written in C. This allows certain time-critical commands (like async <cmd>archive-push</cmd>) to run more quickly.</p> <p>The <backrest/> executable is written in C. This allows certain time-critical commands (like async <cmd>archive-push</cmd>/<cmd>archive-get</cmd>) to run more quickly.</p>
<execute-list host="{[br-install-host]}"> <execute-list host="{[br-install-host]}">
<title>Build and Install Binary</title> <title>Build and Install Binary</title>
@@ -331,6 +244,62 @@
<exe-cmd>make -C /root/pgbackrest-release-{[version]}/src install</exe-cmd> <exe-cmd>make -C /root/pgbackrest-release-{[version]}/src install</exe-cmd>
</execute> </execute>
</execute-list> </execute-list>
<!-- Perl installation -->
<p keyword="default"><backrest/> contains embedded Perl which requires some additional modules.</p>
<execute-list host="{[br-install-host]}" keyword="default">
<title>Install required Perl packages</title>
<execute user="root">
<exe-cmd>apt-get update</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>apt-get install libdbd-pg-perl libio-socket-ssl-perl libxml-libxml-perl</exe-cmd>
<exe-cmd-extra>-y 2>&amp;1</exe-cmd-extra>
</execute>
</execute-list>
<p keyword="co6"><backrest/> contains embedded Perl. All required Perl modules are available as standard packages.</p>
<execute-list host="{[br-install-host]}" keyword="co6">
<title>Install required Perl packages</title>
<execute user="root">
<exe-cmd>yum install perl perl-Time-HiRes perl-parent perl-JSON
perl-Digest-SHA perl-DBD-Pg perl-XML-LibXML perl-IO-Socket-SSL</exe-cmd>
<exe-cmd-extra>-y 2>&amp;1</exe-cmd-extra>
</execute>
</execute-list>
<p>Finally, <backrest/> requires log and configuration directories and a configuration file.</p>
<execute-list host="{[br-install-host]}">
<title>Create <backrest/> configuration file and directories</title>
<execute user="root">
<exe-cmd>mkdir -p -m 770 /var/log/pgbackrest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>chown {[br-install-user]}:{[br-install-group]} /var/log/pgbackrest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>mkdir -p {[backrest-config-path]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>mkdir -p {[backrest-config-include-path]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>touch {[backrest-config-demo]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>chmod 640 {[backrest-config-demo]}</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>chown {[br-install-user]}:{[br-install-group]} {[backrest-config-demo]}</exe-cmd>
</execute>
</execute-list>
</block-define> </block-define>
<block-define id="br-install-repo"> <block-define id="br-install-repo">
@@ -458,31 +427,6 @@
</execute> </execute>
</execute-list> </execute-list>
<p>If <backrest/> has been installed before it's best to be sure that no prior copies of it are still installed. Depending on how old the version of pgBackRest is it may have been installed in a few different locations. The following commands will remove all prior versions of pgBackRest.</p>
<execute-list host="{[host-pg1]}">
<title>Remove prior <backrest/> installations</title>
<execute user="root">
<exe-cmd>rm -f /usr/bin/pgbackrest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>rm -f /usr/bin/pg_backrest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>rm -rf /usr/lib/perl5/BackRest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>rm -rf {[perl-lib-path]}/BackRest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>rm -rf /usr/lib/perl5/pgBackRest</exe-cmd>
</execute>
<execute user="root">
<exe-cmd>rm -rf {[perl-lib-path]}/pgBackRest</exe-cmd>
</execute>
</execute-list>
<block id="br-install"> <block id="br-install">
<block-variable-replace key="br-install-host">{[host-pg1]}</block-variable-replace> <block-variable-replace key="br-install-host">{[host-pg1]}</block-variable-replace>
<block-variable-replace key="br-install-user">postgres</block-variable-replace> <block-variable-replace key="br-install-user">postgres</block-variable-replace>
@@ -2473,7 +2417,7 @@
<title>Create the spool directory</title> <title>Create the spool directory</title>
<execute user="root"> <execute user="root">
<exe-cmd>mkdir -m 750 {[spool-path]}</exe-cmd> <exe-cmd>mkdir -p -m 750 {[spool-path]}</exe-cmd>
</execute> </execute>
<execute user="root"> <execute user="root">
<exe-cmd>chown postgres:postgres {[spool-path]}</exe-cmd> <exe-cmd>chown postgres:postgres {[spool-path]}</exe-cmd>
@@ -2484,7 +2428,7 @@
<title>Create the spool directory</title> <title>Create the spool directory</title>
<execute user="root"> <execute user="root">
<exe-cmd>mkdir -m 750 {[spool-path]}</exe-cmd> <exe-cmd>mkdir -p -m 750 {[spool-path]}</exe-cmd>
</execute> </execute>
<execute user="root"> <execute user="root">
<exe-cmd>chown postgres:postgres {[spool-path]}</exe-cmd> <exe-cmd>chown postgres:postgres {[spool-path]}</exe-cmd>

35
lib/pgBackRest/LibC.pm Normal file
View File

@@ -0,0 +1,35 @@
####################################################################################################################################
# C to Perl Interface
####################################################################################################################################
package pgBackRest::LibC;
use base 'Exporter';
use 5.010001;
use strict;
use warnings;
use Carp;
use pgBackRest::LibCAuto;
# Dynamically create constants
my $rhConstant = pgBackRest::LibCAuto::libcAutoConstant();
foreach my $strConstant (keys(%{$rhConstant}))
{
eval ## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
"use constant ${strConstant} => '" . $rhConstant->{$strConstant} . "'";
}
# Export functions and constants
our %EXPORT_TAGS = %{pgBackRest::LibCAuto::libcAutoExportTag()};
our @EXPORT_OK;
foreach my $strSection (keys(%EXPORT_TAGS))
{
push(@EXPORT_OK, @{$EXPORT_TAGS{$strSection}});
}
# Nothing is exported by default
our @EXPORT = ();
1;

388
lib/pgBackRest/LibCAuto.pm Normal file
View File

@@ -0,0 +1,388 @@
####################################################################################################################################
# Automatically generated by Build.pm -- do not modify directly.
####################################################################################################################################
package pgBackRest::LibCAuto;
use strict;
use warnings;
# Configuration option value constants
sub libcAutoConstant
{
return
{
CFGOPTVAL_INFO_OUTPUT_TEXT => 'text',
CFGOPTVAL_INFO_OUTPUT_JSON => 'json',
CFGOPTVAL_REPO_CIPHER_TYPE_NONE => 'none',
CFGOPTVAL_REPO_CIPHER_TYPE_AES_256_CBC => 'aes-256-cbc',
CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_FULL => 'full',
CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_DIFF => 'diff',
CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_INCR => 'incr',
CFGOPTVAL_REPO_TYPE_CIFS => 'cifs',
CFGOPTVAL_REPO_TYPE_POSIX => 'posix',
CFGOPTVAL_REPO_TYPE_S3 => 's3',
CFGOPTVAL_RESTORE_TARGET_ACTION_PAUSE => 'pause',
CFGOPTVAL_RESTORE_TARGET_ACTION_PROMOTE => 'promote',
CFGOPTVAL_RESTORE_TARGET_ACTION_SHUTDOWN => 'shutdown',
CFGOPTVAL_BACKUP_TYPE_FULL => 'full',
CFGOPTVAL_BACKUP_TYPE_DIFF => 'diff',
CFGOPTVAL_BACKUP_TYPE_INCR => 'incr',
CFGOPTVAL_LOCAL_TYPE_DB => 'db',
CFGOPTVAL_LOCAL_TYPE_BACKUP => 'backup',
CFGOPTVAL_REMOTE_TYPE_DB => 'db',
CFGOPTVAL_REMOTE_TYPE_BACKUP => 'backup',
CFGOPTVAL_RESTORE_TYPE_NAME => 'name',
CFGOPTVAL_RESTORE_TYPE_TIME => 'time',
CFGOPTVAL_RESTORE_TYPE_XID => 'xid',
CFGOPTVAL_RESTORE_TYPE_PRESERVE => 'preserve',
CFGOPTVAL_RESTORE_TYPE_NONE => 'none',
CFGOPTVAL_RESTORE_TYPE_IMMEDIATE => 'immediate',
CFGOPTVAL_RESTORE_TYPE_DEFAULT => 'default',
CFGCMD_ARCHIVE_GET => 0,
CFGCMD_ARCHIVE_PUSH => 1,
CFGCMD_BACKUP => 2,
CFGCMD_CHECK => 3,
CFGCMD_EXPIRE => 4,
CFGCMD_HELP => 5,
CFGCMD_INFO => 6,
CFGCMD_LOCAL => 7,
CFGCMD_REMOTE => 8,
CFGCMD_RESTORE => 9,
CFGCMD_STANZA_CREATE => 10,
CFGCMD_STANZA_DELETE => 11,
CFGCMD_STANZA_UPGRADE => 12,
CFGCMD_START => 13,
CFGCMD_STOP => 14,
CFGCMD_VERSION => 15,
CFGOPT_ARCHIVE_ASYNC => 0,
CFGOPT_ARCHIVE_CHECK => 1,
CFGOPT_ARCHIVE_COPY => 2,
CFGOPT_ARCHIVE_GET_QUEUE_MAX => 3,
CFGOPT_ARCHIVE_PUSH_QUEUE_MAX => 4,
CFGOPT_ARCHIVE_TIMEOUT => 5,
CFGOPT_BACKUP_STANDBY => 6,
CFGOPT_BUFFER_SIZE => 7,
CFGOPT_CHECKSUM_PAGE => 8,
CFGOPT_CMD_SSH => 9,
CFGOPT_COMMAND => 10,
CFGOPT_COMPRESS => 11,
CFGOPT_COMPRESS_LEVEL => 12,
CFGOPT_COMPRESS_LEVEL_NETWORK => 13,
CFGOPT_CONFIG => 14,
CFGOPT_CONFIG_INCLUDE_PATH => 15,
CFGOPT_CONFIG_PATH => 16,
CFGOPT_DB_INCLUDE => 17,
CFGOPT_DB_TIMEOUT => 18,
CFGOPT_DELTA => 19,
CFGOPT_FORCE => 20,
CFGOPT_HOST_ID => 21,
CFGOPT_LINK_ALL => 22,
CFGOPT_LINK_MAP => 23,
CFGOPT_LOCK_PATH => 24,
CFGOPT_LOG_LEVEL_CONSOLE => 25,
CFGOPT_LOG_LEVEL_FILE => 26,
CFGOPT_LOG_LEVEL_STDERR => 27,
CFGOPT_LOG_PATH => 28,
CFGOPT_LOG_TIMESTAMP => 29,
CFGOPT_MANIFEST_SAVE_THRESHOLD => 30,
CFGOPT_NEUTRAL_UMASK => 31,
CFGOPT_ONLINE => 32,
CFGOPT_OUTPUT => 33,
CFGOPT_PERL_OPTION => 34,
CFGOPT_PG_HOST => 35,
CFGOPT_PG_HOST_CMD => 43,
CFGOPT_PG_HOST_CONFIG => 51,
CFGOPT_PG_HOST_CONFIG_INCLUDE_PATH => 59,
CFGOPT_PG_HOST_CONFIG_PATH => 67,
CFGOPT_PG_HOST_PORT => 75,
CFGOPT_PG_HOST_USER => 83,
CFGOPT_PG_PATH => 91,
CFGOPT_PG_PORT => 99,
CFGOPT_PG_SOCKET_PATH => 107,
CFGOPT_PROCESS => 115,
CFGOPT_PROCESS_MAX => 116,
CFGOPT_PROTOCOL_TIMEOUT => 117,
CFGOPT_RECOVERY_OPTION => 118,
CFGOPT_REPO_CIPHER_PASS => 119,
CFGOPT_REPO_CIPHER_TYPE => 120,
CFGOPT_REPO_HARDLINK => 121,
CFGOPT_REPO_HOST => 122,
CFGOPT_REPO_HOST_CMD => 123,
CFGOPT_REPO_HOST_CONFIG => 124,
CFGOPT_REPO_HOST_CONFIG_INCLUDE_PATH => 125,
CFGOPT_REPO_HOST_CONFIG_PATH => 126,
CFGOPT_REPO_HOST_PORT => 127,
CFGOPT_REPO_HOST_USER => 128,
CFGOPT_REPO_PATH => 129,
CFGOPT_REPO_RETENTION_ARCHIVE => 130,
CFGOPT_REPO_RETENTION_ARCHIVE_TYPE => 131,
CFGOPT_REPO_RETENTION_DIFF => 132,
CFGOPT_REPO_RETENTION_FULL => 133,
CFGOPT_REPO_S3_BUCKET => 134,
CFGOPT_REPO_S3_CA_FILE => 135,
CFGOPT_REPO_S3_CA_PATH => 136,
CFGOPT_REPO_S3_ENDPOINT => 137,
CFGOPT_REPO_S3_HOST => 138,
CFGOPT_REPO_S3_KEY => 139,
CFGOPT_REPO_S3_KEY_SECRET => 140,
CFGOPT_REPO_S3_REGION => 141,
CFGOPT_REPO_S3_TOKEN => 142,
CFGOPT_REPO_S3_VERIFY_SSL => 143,
CFGOPT_REPO_TYPE => 144,
CFGOPT_RESUME => 145,
CFGOPT_SET => 146,
CFGOPT_SPOOL_PATH => 147,
CFGOPT_STANZA => 148,
CFGOPT_START_FAST => 149,
CFGOPT_STOP_AUTO => 150,
CFGOPT_TABLESPACE_MAP => 151,
CFGOPT_TABLESPACE_MAP_ALL => 152,
CFGOPT_TARGET => 153,
CFGOPT_TARGET_ACTION => 154,
CFGOPT_TARGET_EXCLUSIVE => 155,
CFGOPT_TARGET_TIMELINE => 156,
CFGOPT_TEST => 157,
CFGOPT_TEST_DELAY => 158,
CFGOPT_TEST_POINT => 159,
CFGOPT_TYPE => 160,
CFGDEF_TYPE_BOOLEAN => 0,
CFGDEF_TYPE_FLOAT => 1,
CFGDEF_TYPE_HASH => 2,
CFGDEF_TYPE_INTEGER => 3,
CFGDEF_TYPE_LIST => 4,
CFGDEF_TYPE_SIZE => 5,
CFGDEF_TYPE_STRING => 6,
ENCODE_TYPE_BASE64 => 0,
CIPHER_MODE_ENCRYPT => 0,
CIPHER_MODE_DECRYPT => 1,
}
}
# Export function and constants
sub libcAutoExportTag
{
return
{
checksum =>
[
'pageChecksum',
'pageChecksumBufferTest',
'pageChecksumTest',
],
cipher =>
[
'CIPHER_MODE_ENCRYPT',
'CIPHER_MODE_DECRYPT',
],
config =>
[
'CFGOPTVAL_INFO_OUTPUT_TEXT',
'CFGOPTVAL_INFO_OUTPUT_JSON',
'CFGOPTVAL_REPO_CIPHER_TYPE_NONE',
'CFGOPTVAL_REPO_CIPHER_TYPE_AES_256_CBC',
'CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_FULL',
'CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_DIFF',
'CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_INCR',
'CFGOPTVAL_REPO_TYPE_CIFS',
'CFGOPTVAL_REPO_TYPE_POSIX',
'CFGOPTVAL_REPO_TYPE_S3',
'CFGOPTVAL_RESTORE_TARGET_ACTION_PAUSE',
'CFGOPTVAL_RESTORE_TARGET_ACTION_PROMOTE',
'CFGOPTVAL_RESTORE_TARGET_ACTION_SHUTDOWN',
'CFGOPTVAL_BACKUP_TYPE_FULL',
'CFGOPTVAL_BACKUP_TYPE_DIFF',
'CFGOPTVAL_BACKUP_TYPE_INCR',
'CFGOPTVAL_LOCAL_TYPE_DB',
'CFGOPTVAL_LOCAL_TYPE_BACKUP',
'CFGOPTVAL_REMOTE_TYPE_DB',
'CFGOPTVAL_REMOTE_TYPE_BACKUP',
'CFGOPTVAL_RESTORE_TYPE_NAME',
'CFGOPTVAL_RESTORE_TYPE_TIME',
'CFGOPTVAL_RESTORE_TYPE_XID',
'CFGOPTVAL_RESTORE_TYPE_PRESERVE',
'CFGOPTVAL_RESTORE_TYPE_NONE',
'CFGOPTVAL_RESTORE_TYPE_IMMEDIATE',
'CFGOPTVAL_RESTORE_TYPE_DEFAULT',
'CFGCMD_ARCHIVE_GET',
'CFGCMD_ARCHIVE_PUSH',
'CFGCMD_BACKUP',
'CFGCMD_CHECK',
'CFGCMD_EXPIRE',
'CFGCMD_HELP',
'CFGCMD_INFO',
'CFGCMD_LOCAL',
'CFGCMD_REMOTE',
'CFGCMD_RESTORE',
'CFGCMD_STANZA_CREATE',
'CFGCMD_STANZA_DELETE',
'CFGCMD_STANZA_UPGRADE',
'CFGCMD_START',
'CFGCMD_STOP',
'CFGCMD_VERSION',
'CFGOPT_ARCHIVE_ASYNC',
'CFGOPT_ARCHIVE_CHECK',
'CFGOPT_ARCHIVE_COPY',
'CFGOPT_ARCHIVE_GET_QUEUE_MAX',
'CFGOPT_ARCHIVE_PUSH_QUEUE_MAX',
'CFGOPT_ARCHIVE_TIMEOUT',
'CFGOPT_BACKUP_STANDBY',
'CFGOPT_BUFFER_SIZE',
'CFGOPT_CHECKSUM_PAGE',
'CFGOPT_CMD_SSH',
'CFGOPT_COMMAND',
'CFGOPT_COMPRESS',
'CFGOPT_COMPRESS_LEVEL',
'CFGOPT_COMPRESS_LEVEL_NETWORK',
'CFGOPT_CONFIG',
'CFGOPT_CONFIG_INCLUDE_PATH',
'CFGOPT_CONFIG_PATH',
'CFGOPT_DB_INCLUDE',
'CFGOPT_DB_TIMEOUT',
'CFGOPT_DELTA',
'CFGOPT_FORCE',
'CFGOPT_HOST_ID',
'CFGOPT_LINK_ALL',
'CFGOPT_LINK_MAP',
'CFGOPT_LOCK_PATH',
'CFGOPT_LOG_LEVEL_CONSOLE',
'CFGOPT_LOG_LEVEL_FILE',
'CFGOPT_LOG_LEVEL_STDERR',
'CFGOPT_LOG_PATH',
'CFGOPT_LOG_TIMESTAMP',
'CFGOPT_MANIFEST_SAVE_THRESHOLD',
'CFGOPT_NEUTRAL_UMASK',
'CFGOPT_ONLINE',
'CFGOPT_OUTPUT',
'CFGOPT_PERL_OPTION',
'CFGOPT_PG_HOST',
'CFGOPT_PG_HOST_CMD',
'CFGOPT_PG_HOST_CONFIG',
'CFGOPT_PG_HOST_CONFIG_INCLUDE_PATH',
'CFGOPT_PG_HOST_CONFIG_PATH',
'CFGOPT_PG_HOST_PORT',
'CFGOPT_PG_HOST_USER',
'CFGOPT_PG_PATH',
'CFGOPT_PG_PORT',
'CFGOPT_PG_SOCKET_PATH',
'CFGOPT_PROCESS',
'CFGOPT_PROCESS_MAX',
'CFGOPT_PROTOCOL_TIMEOUT',
'CFGOPT_RECOVERY_OPTION',
'CFGOPT_REPO_CIPHER_PASS',
'CFGOPT_REPO_CIPHER_TYPE',
'CFGOPT_REPO_HARDLINK',
'CFGOPT_REPO_HOST',
'CFGOPT_REPO_HOST_CMD',
'CFGOPT_REPO_HOST_CONFIG',
'CFGOPT_REPO_HOST_CONFIG_INCLUDE_PATH',
'CFGOPT_REPO_HOST_CONFIG_PATH',
'CFGOPT_REPO_HOST_PORT',
'CFGOPT_REPO_HOST_USER',
'CFGOPT_REPO_PATH',
'CFGOPT_REPO_RETENTION_ARCHIVE',
'CFGOPT_REPO_RETENTION_ARCHIVE_TYPE',
'CFGOPT_REPO_RETENTION_DIFF',
'CFGOPT_REPO_RETENTION_FULL',
'CFGOPT_REPO_S3_BUCKET',
'CFGOPT_REPO_S3_CA_FILE',
'CFGOPT_REPO_S3_CA_PATH',
'CFGOPT_REPO_S3_ENDPOINT',
'CFGOPT_REPO_S3_HOST',
'CFGOPT_REPO_S3_KEY',
'CFGOPT_REPO_S3_KEY_SECRET',
'CFGOPT_REPO_S3_REGION',
'CFGOPT_REPO_S3_TOKEN',
'CFGOPT_REPO_S3_VERIFY_SSL',
'CFGOPT_REPO_TYPE',
'CFGOPT_RESUME',
'CFGOPT_SET',
'CFGOPT_SPOOL_PATH',
'CFGOPT_STANZA',
'CFGOPT_START_FAST',
'CFGOPT_STOP_AUTO',
'CFGOPT_TABLESPACE_MAP',
'CFGOPT_TABLESPACE_MAP_ALL',
'CFGOPT_TARGET',
'CFGOPT_TARGET_ACTION',
'CFGOPT_TARGET_EXCLUSIVE',
'CFGOPT_TARGET_TIMELINE',
'CFGOPT_TEST',
'CFGOPT_TEST_DELAY',
'CFGOPT_TEST_POINT',
'CFGOPT_TYPE',
'cfgCommandName',
'cfgOptionIndex',
'cfgOptionIndexTotal',
'cfgOptionName',
],
configDefine =>
[
'CFGDEF_TYPE_BOOLEAN',
'CFGDEF_TYPE_FLOAT',
'CFGDEF_TYPE_HASH',
'CFGDEF_TYPE_INTEGER',
'CFGDEF_TYPE_LIST',
'CFGDEF_TYPE_SIZE',
'CFGDEF_TYPE_STRING',
'cfgCommandId',
'cfgDefOptionDefault',
'cfgDefOptionPrefix',
'cfgDefOptionSecure',
'cfgDefOptionType',
'cfgDefOptionValid',
'cfgOptionId',
'cfgOptionTotal',
],
debug =>
[
'libcUvSize',
],
encode =>
[
'ENCODE_TYPE_BASE64',
'decodeToBin',
'encodeToStr',
],
lock =>
[
'lockAcquire',
'lockRelease',
],
random =>
[
'randomBytes',
],
storage =>
[
'storageDriverPosixPathRemove',
],
test =>
[
'cfgParseTest',
],
}
}
1;

View File

@@ -28,12 +28,17 @@ Order is critical here so don't change it.
#pragma GCC diagnostic ignored "-Wuninitialized" #pragma GCC diagnostic ignored "-Wuninitialized"
#endif #endif
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#include <XSUB.h> #include <XSUB.h>
#include <EXTERN.h> #include <EXTERN.h>
#include <perl.h> #include <perl.h>
#if WARNING_MAYBE_INITIALIZED || WARNING_INITIALIZED #if WARNING_MAYBE_INITIALIZED
#pragma GCC diagnostic pop #pragma GCC diagnostic warning "-Wmaybe-uninitialized"
#elif WARNING_INITIALIZED
#pragma GCC diagnostic warning "-Wuninitialized"
#endif #endif
/*********************************************************************************************************************************** /***********************************************************************************************************************************
@@ -64,19 +69,6 @@ These includes define data structures that are required for the C to Perl interf
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "xs/cipher/block.xsh" #include "xs/cipher/block.xsh"
#include "xs/common/encode.xsh" #include "xs/common/encode.xsh"
#include "xs/config/config.auto.xsh"
#include "xs/config/define.auto.xsh"
/***********************************************************************************************************************************
Constant include
Auto generated code that handles exporting C constants to Perl.
***********************************************************************************************************************************/
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "const-c.inc"
#pragma GCC diagnostic warning "-Wunused-parameter"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Module definition Module definition
@@ -84,15 +76,14 @@ Module definition
MODULE = pgBackRest::LibC PACKAGE = pgBackRest::LibC MODULE = pgBackRest::LibC PACKAGE = pgBackRest::LibC
PROTOTYPES: DISABLE PROTOTYPES: DISABLE
# Exported constants # Return UVSIZE to ensure that this Perl supports 64-bit integers
#
# The XS portion of the code that handles exporting C constants to Perl.
# ---------------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------------
#pragma GCC diagnostic ignored "-Wuninitialized" I32
libcUvSize()
INCLUDE: const-xs.inc CODE:
RETVAL = UVSIZE;
#pragma GCC diagnostic warning "-Wuninitialized" OUTPUT:
RETVAL
# Exported functions and modules # Exported functions and modules
# #

View File

@@ -17,9 +17,6 @@ use File::Basename qw(dirname);
use lib dirname($0) . '/lib'; use lib dirname($0) . '/lib';
use lib dirname($0) . '/build/lib'; use lib dirname($0) . '/build/lib';
use pgBackRest::LibCAuto;
use pgBackRestLibC::BuildParam;
#################################################################################################################################### ####################################################################################################################################
# Storage object to use for all file operations # Storage object to use for all file operations
#################################################################################################################################### ####################################################################################################################################
@@ -27,45 +24,6 @@ use constant BACKREST_NAME => 'pgBackRe
use constant LIB_NAME => 'LibC'; use constant LIB_NAME => 'LibC';
use constant LIB_AUTO_NAME => LIB_NAME . 'Auto'; use constant LIB_AUTO_NAME => LIB_NAME . 'Auto';
####################################################################################################################################
# Build list of constants to export from C and add them to the constant array
####################################################################################################################################
{
# Build constants
my $rhExport = pgBackRest::LibCAuto::libcAutoExportTag();
my @stryConstant;
foreach my $strSection (sort(keys(%{$rhExport})))
{
# Search exports for constants
foreach my $strExport (@{$rhExport->{$strSection}})
{
# Constants will be upper-case
if (uc($strExport) eq $strExport)
{
push(@stryConstant, $strExport);
}
}
}
# Build constant C code
if (eval {require ExtUtils::Constant; 1})
{
ExtUtils::Constant::WriteConstants
(
NAME => BACKREST_NAME . '::' . LIB_NAME,
NAMES => \@stryConstant,
DEFAULT_TYPE => 'IV',
C_FILE => 'const-c.inc',
XS_FILE => 'const-xs.inc',
);
}
else
{
die "ExtUtils::Constant is required to build constants!";
}
}
#################################################################################################################################### ####################################################################################################################################
# Create C Makefile # Create C Makefile
#################################################################################################################################### ####################################################################################################################################
@@ -145,22 +103,21 @@ for (my $iFileIdx = 1; $iFileIdx < @stryCFile; $iFileIdx++)
WriteMakefile WriteMakefile
( (
NAME => BACKREST_NAME . '::LibC', NAME => BACKREST_NAME . '::LibC',
VERSION_FROM => 'lib/' . BACKREST_NAME . '/LibC.pm', VERSION => '999',
AUTHOR => 'David Steele <david@pgbackrest.org>', AUTHOR => 'David Steele <david@pgbackrest.org>',
CCFLAGS => join(' ', buildParamCCAll()), CCFLAGS => join(' ', qw)
-Wfatal-errors -Wall -Wextra -Wwrite-strings -Wno-clobbered -Wno-missing-field-initializers
-o $@
-std=c99
-D_FILE_OFFSET_BITS=64
)),
INC => join(' ', qw( INC => join(' ', qw(
-I. -I.
-I../src -I../src
)), )),
PM =>
{
('lib/' . BACKREST_NAME . '/' . LIB_NAME . '.pm') => ('$(INST_LIB)/' . BACKREST_NAME . '/' . LIB_NAME . '.pm'),
('lib/' . BACKREST_NAME . '/' . LIB_AUTO_NAME . '.pm') => ('$(INST_LIB)/' . BACKREST_NAME . '/' . LIB_AUTO_NAME . '.pm'),
},
C => \@stryCFile, C => \@stryCFile,
LIBS => [-lcrypto], LIBS => [-lcrypto],

View File

@@ -28,9 +28,6 @@ use pgBackRestBuild::Build;
use pgBackRestBuild::Build::Common; use pgBackRestBuild::Build::Common;
use pgBackRestBuild::Error::Data; use pgBackRestBuild::Error::Data;
use pgBackRestLibC::Config::Build;
use pgBackRestLibC::Config::BuildDefine;
#################################################################################################################################### ####################################################################################################################################
# Perl function and constant exports # Perl function and constant exports
#################################################################################################################################### ####################################################################################################################################
@@ -87,12 +84,8 @@ my $rhExport =
'debug' => 'debug' =>
{ {
&BLD_EXPORTTYPE_CONSTANT => [qw(
UVSIZE
)],
&BLD_EXPORTTYPE_SUB => [qw( &BLD_EXPORTTYPE_SUB => [qw(
libcVersion libcUvSize
)], )],
}, },
@@ -145,37 +138,10 @@ sub buildXsAll
{ {
my $strBuildPath = shift; my $strBuildPath = shift;
my $rhBuild =
{
'config' =>
{
&BLD_DATA => buildXsConfig(),
&BLD_PATH => 'xs/config',
},
'configDefine' =>
{
&BLD_DATA => buildXsConfigDefine(),
&BLD_PATH => 'xs/config',
},
};
buildAll($strBuildPath, $rhBuild, 'xs');
# Storage # Storage
my $oStorage = new pgBackRest::Storage::Local( my $oStorage = new pgBackRest::Storage::Local(
$strBuildPath, new pgBackRest::Storage::Posix::Driver({bFileSync => false, bPathSync => false})); $strBuildPath, new pgBackRest::Storage::Posix::Driver({bFileSync => false, bPathSync => false}));
# Get current version
my $strVersion = BACKREST_VERSION;
my $bDev = false;
if ($strVersion =~ /dev$/)
{
$strVersion = substr($strVersion, 0, length($strVersion) - 3) . '.999';
$bDev = true;
}
# Build interface file # Build interface file
my $strContent = my $strContent =
('#' x 132) . "\n" . ('#' x 132) . "\n" .
@@ -183,11 +149,8 @@ sub buildXsAll
('#' x 132) . "\n" . ('#' x 132) . "\n" .
"package pgBackRest::LibCAuto;\n" . "package pgBackRest::LibCAuto;\n" .
"\n" . "\n" .
"# Library version (.999 indicates development version)\n" . "use strict;\n" .
"sub libcAutoVersion\n" . "use warnings;\n";
"{\n" .
" return '${strVersion}';\n" .
"}\n";
# Generate constants for options that have a list of strings as allowed values # Generate constants for options that have a list of strings as allowed values
my $rhConfigDefine = cfgDefine(); my $rhConfigDefine = cfgDefine();
@@ -234,6 +197,73 @@ sub buildXsAll
} }
} }
# Generate command constants
$strConstantBlock .= defined($strConstantBlock) ? "\n" : '';
my $iIndex = 0;
foreach my $strCommand (cfgDefineCommandList())
{
my $strConstant = "CFGCMD_" . uc($strCommand);
$strConstant =~ s/\-/\_/g;
$strConstantBlock .=
" ${strConstant}" . (' ' x (69 - length($strConstant) - 4)) . "=> $iIndex,\n";
push(@{$rhExport->{'config'}{&BLD_EXPORTTYPE_CONSTANT}}, $strConstant);
$iIndex++;
}
# Generate option constants
$strConstantBlock .= defined($strConstantBlock) ? "\n" : '';
$iIndex = 0;
foreach my $strOption (sort(keys(%{$rhConfigDefine})))
{
# Build Perl constant
my $strConstant = "CFGOPT_" . uc($strOption);
$strConstant =~ s/\-/\_/g;
$strConstantBlock .=
" ${strConstant}" . (' ' x (69 - length($strConstant) - 4)) . "=> $iIndex,\n";
push(@{$rhExport->{'config'}{&BLD_EXPORTTYPE_CONSTANT}}, $strConstant);
$iIndex += $rhConfigDefine->{$strOption}{&CFGDEF_INDEX_TOTAL};
}
# Generate option type constants
$strConstantBlock .= defined($strConstantBlock) ? "\n" : '';
$iIndex = 0;
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";
$strContent .= $strContent .=
"\n" . "\n" .
"# Configuration option value constants\n" . "# Configuration option value constants\n" .
@@ -245,29 +275,6 @@ sub buildXsAll
" }\n" . " }\n" .
"}\n"; "}\n";
foreach my $strBuild (sort(keys(%{$rhBuild})))
{
foreach my $strFile (sort(keys(%{$rhBuild->{$strBuild}{&BLD_DATA}{&BLD_FILE}})))
{
my $rhFileConstant = $rhBuild->{$strBuild}{&BLD_DATA}{&BLD_FILE}{$strFile}{&BLD_CONSTANT_GROUP};
foreach my $strConstantGroup (sort(keys(%{$rhFileConstant})))
{
my $rhConstantGroup = $rhFileConstant->{$strConstantGroup};
foreach my $strConstant (sort(keys(%{$rhConstantGroup->{&BLD_CONSTANT}})))
{
my $rhConstant = $rhConstantGroup->{&BLD_CONSTANT}{$strConstant};
if ($rhConstant->{&BLD_CONSTANT_EXPORT})
{
push(@{$rhExport->{$strBuild}{&BLD_EXPORTTYPE_CONSTANT}}, $strConstant);
}
}
}
}
}
# Generate export tags # Generate export tags
my $strExportTags; my $strExportTags;
@@ -313,7 +320,7 @@ sub buildXsAll
"1;\n"; "1;\n";
# Save the file # Save the file
$oStorage->put('lib/' . BACKREST_NAME . '/' . LIB_AUTO_NAME . '.pm', $strContent); $oStorage->put('../lib/' . BACKREST_NAME . '/' . LIB_AUTO_NAME . '.pm', $strContent);
# Build error file # Build error file
#------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------------

View File

@@ -1,46 +0,0 @@
####################################################################################################################################
# Parameters used by LibC builds
####################################################################################################################################
package pgBackRestLibC::BuildParam;
use strict;
use warnings FATAL => qw(all);
use Carp qw(confess);
use English '-no_match_vars';
use Exporter qw(import);
our @EXPORT = qw();
####################################################################################################################################
# All CC params used for a debug build
####################################################################################################################################
sub buildParamCCDebug
{
return qw(
-Wfatal-errors -Wall -Wextra -Wwrite-strings -Wno-clobbered -Wno-missing-field-initializers
-o $@
-std=c99
-D_FILE_OFFSET_BITS=64
$(CFLAGS));
}
push @EXPORT, qw(buildParamCCDebug);
####################################################################################################################################
# All CC params used for a production build
####################################################################################################################################
sub buildParamCCAll
{
my @stryParams = buildParamCCDebug;
push(@stryParams, qw(
-DNDEBUG
-funroll-loops
-ftree-vectorize));
return @stryParams;
}
push @EXPORT, qw(buildParamCCAll);
1;

View File

@@ -1,105 +0,0 @@
####################################################################################################################################
# Auto-Generate Command and Option Configuration Constants for Export to Perl
####################################################################################################################################
package pgBackRestLibC::Config::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 pgBackRest::Common::Log;
use pgBackRest::Common::String;
use pgBackRestBuild::Config::Data;
use pgBackRest::Version;
use pgBackRestBuild::Build::Common;
use pgBackRestBuild::Config::Build;
####################################################################################################################################
# Constants
####################################################################################################################################
use constant BLDLCL_FILE_CONFIG => 'config';
use constant BLDLCL_CONSTANT_COMMAND => '01-command';
use constant BLDLCL_CONSTANT_OPTION => '02-option';
####################################################################################################################################
# Definitions for constants and data to build
####################################################################################################################################
my $rhBuild =
{
&BLD_FILE =>
{
#---------------------------------------------------------------------------------------------------------------------------
&BLDLCL_FILE_CONFIG =>
{
&BLD_SUMMARY => 'Command and Option Configuration',
&BLD_CONSTANT_GROUP =>
{
&BLDLCL_CONSTANT_COMMAND =>
{
&BLD_SUMMARY => 'Command',
&BLD_CONSTANT => {},
},
&BLDLCL_CONSTANT_OPTION =>
{
&BLD_SUMMARY => 'Option',
&BLD_CONSTANT => {},
},
},
},
},
};
####################################################################################################################################
# Build constants and data
####################################################################################################################################
sub buildXsConfig
{
# Build command constants and data
#-------------------------------------------------------------------------------------------------------------------------------
my $rhConstant = $rhBuild->{&BLD_FILE}{&BLDLCL_FILE_CONFIG}{&BLD_CONSTANT_GROUP}{&BLDLCL_CONSTANT_COMMAND}{&BLD_CONSTANT};
foreach my $strCommand (cfgDefineCommandList())
{
# Build Perl constant
my $strCommandEnum = buildConfigCommandEnum($strCommand);
my $strCommandConstant = "CFGCMD_" . uc($strCommand);
$strCommandConstant =~ s/\-/\_/g;
$rhConstant->{$strCommandConstant}{&BLD_CONSTANT_VALUE} = $strCommandEnum;
$rhConstant->{$strCommandConstant}{&BLD_CONSTANT_EXPORT} = true;
}
# Build option constants and data
#-------------------------------------------------------------------------------------------------------------------------------
my $rhConfigDefine = cfgDefine();
$rhConstant = $rhBuild->{&BLD_FILE}{&BLDLCL_FILE_CONFIG}{&BLD_CONSTANT_GROUP}{&BLDLCL_CONSTANT_OPTION}{&BLD_CONSTANT};
foreach my $strOption (sort(keys(%{$rhConfigDefine})))
{
# Build Perl constant
my $strOptionEnum = buildConfigOptionEnum($strOption);
my $strOptionConstant = "CFGOPT_" . uc($strOption);
$strOptionConstant =~ s/\-/\_/g;
$rhConstant->{$strOptionConstant}{&BLD_CONSTANT_VALUE} = $strOptionEnum;
$rhConstant->{$strOptionConstant}{&BLD_CONSTANT_EXPORT} = true;
}
return $rhBuild;
}
push @EXPORT, qw(buildXsConfig);
1;

View File

@@ -1,81 +0,0 @@
####################################################################################################################################
# Auto-Generate Command and Option Configuration Definition Constants for Export to Perl
####################################################################################################################################
package pgBackRestLibC::Config::BuildDefine;
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 pgBackRest::Common::Log;
use pgBackRest::Common::String;
use pgBackRestBuild::Config::Data;
use pgBackRest::Version;
use pgBackRestBuild::Build::Common;
use pgBackRestBuild::Config::BuildDefine;
####################################################################################################################################
# Constants
####################################################################################################################################
use constant BLDLCL_FILE_DEFINE => 'define';
use constant BLDLCL_CONSTANT_OPTION_TYPE => '01-constantOptionType';
####################################################################################################################################
# Definitions for constants and data to build
####################################################################################################################################
my $strSummary = 'Command and Option Definitions';
my $rhBuild =
{
&BLD_FILE =>
{
&BLDLCL_FILE_DEFINE =>
{
&BLD_SUMMARY => $strSummary,
&BLD_CONSTANT_GROUP =>
{
&BLDLCL_CONSTANT_OPTION_TYPE =>
{
&BLD_SUMMARY => 'Option type',
&BLD_CONSTANT => {},
},
},
},
},
};
####################################################################################################################################
# Build configuration constants and data
####################################################################################################################################
sub buildXsConfigDefine
{
# Build option type constants
#-------------------------------------------------------------------------------------------------------------------------------
my $rhConstant = $rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_CONSTANT_GROUP}{&BLDLCL_CONSTANT_OPTION_TYPE}{&BLD_CONSTANT};
foreach my $strOptionType (cfgDefineOptionTypeList())
{
# Build Perl constant
my $strOptionTypeConstant = "CFGDEF_TYPE_" . uc($strOptionType);
$strOptionTypeConstant =~ s/\-/\_/g;
$rhConstant->{$strOptionTypeConstant}{&BLD_CONSTANT_VALUE} = buildConfigDefineOptionTypeEnum($strOptionType);
$rhConstant->{$strOptionTypeConstant}{&BLD_CONSTANT_EXPORT} = true;
};
return $rhBuild;
}
push @EXPORT, qw(buildXsConfigDefine);
1;

View File

@@ -1,70 +0,0 @@
####################################################################################################################################
# C to Perl Interface
####################################################################################################################################
package pgBackRest::LibC;
use 5.010001;
use strict;
use warnings;
use Carp;
require Exporter;
use AutoLoader;
our @ISA = qw(Exporter);
use pgBackRest::LibCAuto;
# Library version
our $VERSION = pgBackRest::LibCAuto::libcAutoVersion();
sub libcVersion
{
return $VERSION;
}
# Dynamically create constants
my $rhConstant = pgBackRest::LibCAuto::libcAutoConstant();
foreach my $strConstant (keys(%{$rhConstant}))
{
eval "use constant ${strConstant} => '" . $rhConstant->{$strConstant} . "'";
}
# Export function and constants
our %EXPORT_TAGS = %{pgBackRest::LibCAuto::libcAutoExportTag()};
our @EXPORT_OK;
foreach my $strSection (keys(%EXPORT_TAGS))
{
push(@EXPORT_OK, @{$EXPORT_TAGS{$strSection}});
}
# Nothing is exported by default
our @EXPORT = ();
# Autoload constants from the constant() XS function
sub AUTOLOAD
{
my $strConstantFunctionName;
our $AUTOLOAD;
($strConstantFunctionName = $AUTOLOAD) =~ s/.*:://;
croak "&pgBackRest::LibC::constant not defined"
if $strConstantFunctionName eq 'constant';
my ($error, $val) = constant($strConstantFunctionName);
if ($error) {croak $error;}
{
no strict 'refs';
*$AUTOLOAD = sub {$val};
}
goto &$AUTOLOAD;
}
require XSLoader;
XSLoader::load('pgBackRest::LibC', $VERSION);
1;
__END__

View File

@@ -1,270 +0,0 @@
####################################################################################################################################
# Automatically generated by Build.pm -- do not modify directly.
####################################################################################################################################
package pgBackRest::LibCAuto;
# Library version (.999 indicates development version)
sub libcAutoVersion
{
return '2.03.999';
}
# Configuration option value constants
sub libcAutoConstant
{
return
{
CFGOPTVAL_INFO_OUTPUT_TEXT => 'text',
CFGOPTVAL_INFO_OUTPUT_JSON => 'json',
CFGOPTVAL_REPO_CIPHER_TYPE_NONE => 'none',
CFGOPTVAL_REPO_CIPHER_TYPE_AES_256_CBC => 'aes-256-cbc',
CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_FULL => 'full',
CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_DIFF => 'diff',
CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_INCR => 'incr',
CFGOPTVAL_REPO_TYPE_CIFS => 'cifs',
CFGOPTVAL_REPO_TYPE_POSIX => 'posix',
CFGOPTVAL_REPO_TYPE_S3 => 's3',
CFGOPTVAL_RESTORE_TARGET_ACTION_PAUSE => 'pause',
CFGOPTVAL_RESTORE_TARGET_ACTION_PROMOTE => 'promote',
CFGOPTVAL_RESTORE_TARGET_ACTION_SHUTDOWN => 'shutdown',
CFGOPTVAL_BACKUP_TYPE_FULL => 'full',
CFGOPTVAL_BACKUP_TYPE_DIFF => 'diff',
CFGOPTVAL_BACKUP_TYPE_INCR => 'incr',
CFGOPTVAL_LOCAL_TYPE_DB => 'db',
CFGOPTVAL_LOCAL_TYPE_BACKUP => 'backup',
CFGOPTVAL_REMOTE_TYPE_DB => 'db',
CFGOPTVAL_REMOTE_TYPE_BACKUP => 'backup',
CFGOPTVAL_RESTORE_TYPE_NAME => 'name',
CFGOPTVAL_RESTORE_TYPE_TIME => 'time',
CFGOPTVAL_RESTORE_TYPE_XID => 'xid',
CFGOPTVAL_RESTORE_TYPE_PRESERVE => 'preserve',
CFGOPTVAL_RESTORE_TYPE_NONE => 'none',
CFGOPTVAL_RESTORE_TYPE_IMMEDIATE => 'immediate',
CFGOPTVAL_RESTORE_TYPE_DEFAULT => 'default',
}
}
# Export function and constants
sub libcAutoExportTag
{
return
{
checksum =>
[
'pageChecksum',
'pageChecksumBufferTest',
'pageChecksumTest',
],
cipher =>
[
'CIPHER_MODE_ENCRYPT',
'CIPHER_MODE_DECRYPT',
],
config =>
[
'CFGOPTVAL_INFO_OUTPUT_TEXT',
'CFGOPTVAL_INFO_OUTPUT_JSON',
'CFGOPTVAL_REPO_CIPHER_TYPE_NONE',
'CFGOPTVAL_REPO_CIPHER_TYPE_AES_256_CBC',
'CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_FULL',
'CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_DIFF',
'CFGOPTVAL_REPO_RETENTION_ARCHIVE_TYPE_INCR',
'CFGOPTVAL_REPO_TYPE_CIFS',
'CFGOPTVAL_REPO_TYPE_POSIX',
'CFGOPTVAL_REPO_TYPE_S3',
'CFGOPTVAL_RESTORE_TARGET_ACTION_PAUSE',
'CFGOPTVAL_RESTORE_TARGET_ACTION_PROMOTE',
'CFGOPTVAL_RESTORE_TARGET_ACTION_SHUTDOWN',
'CFGOPTVAL_BACKUP_TYPE_FULL',
'CFGOPTVAL_BACKUP_TYPE_DIFF',
'CFGOPTVAL_BACKUP_TYPE_INCR',
'CFGOPTVAL_LOCAL_TYPE_DB',
'CFGOPTVAL_LOCAL_TYPE_BACKUP',
'CFGOPTVAL_REMOTE_TYPE_DB',
'CFGOPTVAL_REMOTE_TYPE_BACKUP',
'CFGOPTVAL_RESTORE_TYPE_NAME',
'CFGOPTVAL_RESTORE_TYPE_TIME',
'CFGOPTVAL_RESTORE_TYPE_XID',
'CFGOPTVAL_RESTORE_TYPE_PRESERVE',
'CFGOPTVAL_RESTORE_TYPE_NONE',
'CFGOPTVAL_RESTORE_TYPE_IMMEDIATE',
'CFGOPTVAL_RESTORE_TYPE_DEFAULT',
'CFGCMD_ARCHIVE_GET',
'CFGCMD_ARCHIVE_PUSH',
'CFGCMD_BACKUP',
'CFGCMD_CHECK',
'CFGCMD_EXPIRE',
'CFGCMD_HELP',
'CFGCMD_INFO',
'CFGCMD_LOCAL',
'CFGCMD_REMOTE',
'CFGCMD_RESTORE',
'CFGCMD_STANZA_CREATE',
'CFGCMD_STANZA_DELETE',
'CFGCMD_STANZA_UPGRADE',
'CFGCMD_START',
'CFGCMD_STOP',
'CFGCMD_VERSION',
'CFGOPT_ARCHIVE_ASYNC',
'CFGOPT_ARCHIVE_CHECK',
'CFGOPT_ARCHIVE_COPY',
'CFGOPT_ARCHIVE_GET_QUEUE_MAX',
'CFGOPT_ARCHIVE_PUSH_QUEUE_MAX',
'CFGOPT_ARCHIVE_TIMEOUT',
'CFGOPT_BACKUP_STANDBY',
'CFGOPT_BUFFER_SIZE',
'CFGOPT_CHECKSUM_PAGE',
'CFGOPT_CMD_SSH',
'CFGOPT_COMMAND',
'CFGOPT_COMPRESS',
'CFGOPT_COMPRESS_LEVEL',
'CFGOPT_COMPRESS_LEVEL_NETWORK',
'CFGOPT_CONFIG',
'CFGOPT_CONFIG_INCLUDE_PATH',
'CFGOPT_CONFIG_PATH',
'CFGOPT_DB_INCLUDE',
'CFGOPT_DB_TIMEOUT',
'CFGOPT_DELTA',
'CFGOPT_FORCE',
'CFGOPT_HOST_ID',
'CFGOPT_LINK_ALL',
'CFGOPT_LINK_MAP',
'CFGOPT_LOCK_PATH',
'CFGOPT_LOG_LEVEL_CONSOLE',
'CFGOPT_LOG_LEVEL_FILE',
'CFGOPT_LOG_LEVEL_STDERR',
'CFGOPT_LOG_PATH',
'CFGOPT_LOG_TIMESTAMP',
'CFGOPT_MANIFEST_SAVE_THRESHOLD',
'CFGOPT_NEUTRAL_UMASK',
'CFGOPT_ONLINE',
'CFGOPT_OUTPUT',
'CFGOPT_PERL_OPTION',
'CFGOPT_PG_HOST',
'CFGOPT_PG_HOST_CMD',
'CFGOPT_PG_HOST_CONFIG',
'CFGOPT_PG_HOST_CONFIG_INCLUDE_PATH',
'CFGOPT_PG_HOST_CONFIG_PATH',
'CFGOPT_PG_HOST_PORT',
'CFGOPT_PG_HOST_USER',
'CFGOPT_PG_PATH',
'CFGOPT_PG_PORT',
'CFGOPT_PG_SOCKET_PATH',
'CFGOPT_PROCESS',
'CFGOPT_PROCESS_MAX',
'CFGOPT_PROTOCOL_TIMEOUT',
'CFGOPT_RECOVERY_OPTION',
'CFGOPT_REPO_CIPHER_PASS',
'CFGOPT_REPO_CIPHER_TYPE',
'CFGOPT_REPO_HARDLINK',
'CFGOPT_REPO_HOST',
'CFGOPT_REPO_HOST_CMD',
'CFGOPT_REPO_HOST_CONFIG',
'CFGOPT_REPO_HOST_CONFIG_INCLUDE_PATH',
'CFGOPT_REPO_HOST_CONFIG_PATH',
'CFGOPT_REPO_HOST_PORT',
'CFGOPT_REPO_HOST_USER',
'CFGOPT_REPO_PATH',
'CFGOPT_REPO_RETENTION_ARCHIVE',
'CFGOPT_REPO_RETENTION_ARCHIVE_TYPE',
'CFGOPT_REPO_RETENTION_DIFF',
'CFGOPT_REPO_RETENTION_FULL',
'CFGOPT_REPO_S3_BUCKET',
'CFGOPT_REPO_S3_CA_FILE',
'CFGOPT_REPO_S3_CA_PATH',
'CFGOPT_REPO_S3_ENDPOINT',
'CFGOPT_REPO_S3_HOST',
'CFGOPT_REPO_S3_KEY',
'CFGOPT_REPO_S3_KEY_SECRET',
'CFGOPT_REPO_S3_REGION',
'CFGOPT_REPO_S3_TOKEN',
'CFGOPT_REPO_S3_VERIFY_SSL',
'CFGOPT_REPO_TYPE',
'CFGOPT_RESUME',
'CFGOPT_SET',
'CFGOPT_SPOOL_PATH',
'CFGOPT_STANZA',
'CFGOPT_START_FAST',
'CFGOPT_STOP_AUTO',
'CFGOPT_TABLESPACE_MAP',
'CFGOPT_TABLESPACE_MAP_ALL',
'CFGOPT_TARGET',
'CFGOPT_TARGET_ACTION',
'CFGOPT_TARGET_EXCLUSIVE',
'CFGOPT_TARGET_TIMELINE',
'CFGOPT_TEST',
'CFGOPT_TEST_DELAY',
'CFGOPT_TEST_POINT',
'CFGOPT_TYPE',
'cfgCommandName',
'cfgOptionIndex',
'cfgOptionIndexTotal',
'cfgOptionName',
],
configDefine =>
[
'CFGDEF_TYPE_BOOLEAN',
'CFGDEF_TYPE_FLOAT',
'CFGDEF_TYPE_HASH',
'CFGDEF_TYPE_INTEGER',
'CFGDEF_TYPE_LIST',
'CFGDEF_TYPE_SIZE',
'CFGDEF_TYPE_STRING',
'cfgCommandId',
'cfgDefOptionDefault',
'cfgDefOptionPrefix',
'cfgDefOptionSecure',
'cfgDefOptionType',
'cfgDefOptionValid',
'cfgOptionId',
'cfgOptionTotal',
],
debug =>
[
'UVSIZE',
'libcVersion',
],
encode =>
[
'ENCODE_TYPE_BASE64',
'decodeToBin',
'encodeToStr',
],
lock =>
[
'lockAcquire',
'lockRelease',
],
random =>
[
'randomBytes',
],
storage =>
[
'storageDriverPosixPathRemove',
],
test =>
[
'cfgParseTest',
],
}
}
1;

View File

@@ -8,17 +8,28 @@ use warnings;
use Carp; use Carp;
use English '-no_match_vars'; use English '-no_match_vars';
use Cwd qw(abs_path);
use File::Basename qw(dirname);
# Set number of tests # Set number of tests
use Test::More tests => 4; use Test::More tests => 5;
use lib abs_path(dirname($0) . '/../../lib');
# Make sure the module loads without errors # Make sure the module loads without errors
BEGIN {use_ok('pgBackRest::LibC', qw(:debug :config :configDefine))}; BEGIN {use_ok('pgBackRest::LibC', qw(:debug :config :configDefine))};
require XSLoader;
XSLoader::load('pgBackRest::LibC', '999');
# UVSIZE determines the pointer and long long int size. This needs to be 8 to indicate 64-bit types are available. # UVSIZE determines the pointer and long long int size. This needs to be 8 to indicate 64-bit types are available.
ok (&UVSIZE == 8, 'UVSIZE == 8'); ok (libcUvSize() == 8, 'UVSIZE == 8');
# Check constant that is created dynamically # Check constant that is created dynamically
ok (CFGOPTVAL_BACKUP_TYPE_FULL eq 'full', 'auto constant valid'); ok (CFGOPTVAL_BACKUP_TYPE_FULL eq 'full', 'auto constant valid');
# Check constant that is exported from C # Check constant that is exported from C
ok (CFGDEF_TYPE_HASH >= 0, 'auto constant valid'); ok (CFGDEF_TYPE_HASH >= 0, 'auto constant valid');
# Check a function
ok (cfgOptionName(CFGOPT_DELTA) eq 'delta', 'auto constant valid');

View File

@@ -1,8 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Block Cipher XS Header Block Cipher XS Header
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "../src/common/memContext.h" #include "common/memContext.h"
#include "../src/cipher/block.h" #include "cipher/block.h"
// Encrypt/decrypt modes // Encrypt/decrypt modes
#define CIPHER_MODE_ENCRYPT ((int)cipherModeEncrypt) #define CIPHER_MODE_ENCRYPT ((int)cipherModeEncrypt)

View File

@@ -1,7 +1,7 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Binary to String Encode/Decode XS Header Binary to String Encode/Decode XS Header
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "../src/common/encode.h" #include "common/encode.h"
// Encode types // Encode types
#define ENCODE_TYPE_BASE64 ((int)encodeBase64) #define ENCODE_TYPE_BASE64 ((int)encodeBase64)

View File

@@ -1,124 +0,0 @@
/***********************************************************************************************************************************
Command and Option Configuration
Automatically generated by Build.pm -- do not modify directly.
***********************************************************************************************************************************/
#ifndef XS_CONFIG_CONFIG_AUTO_H
#define XS_CONFIG_CONFIG_AUTO_H
/***********************************************************************************************************************************
Command constants
***********************************************************************************************************************************/
#define CFGCMD_ARCHIVE_GET cfgCmdArchiveGet
#define CFGCMD_ARCHIVE_PUSH cfgCmdArchivePush
#define CFGCMD_BACKUP cfgCmdBackup
#define CFGCMD_CHECK cfgCmdCheck
#define CFGCMD_EXPIRE cfgCmdExpire
#define CFGCMD_HELP cfgCmdHelp
#define CFGCMD_INFO cfgCmdInfo
#define CFGCMD_LOCAL cfgCmdLocal
#define CFGCMD_REMOTE cfgCmdRemote
#define CFGCMD_RESTORE cfgCmdRestore
#define CFGCMD_STANZA_CREATE cfgCmdStanzaCreate
#define CFGCMD_STANZA_DELETE cfgCmdStanzaDelete
#define CFGCMD_STANZA_UPGRADE cfgCmdStanzaUpgrade
#define CFGCMD_START cfgCmdStart
#define CFGCMD_STOP cfgCmdStop
#define CFGCMD_VERSION cfgCmdVersion
/***********************************************************************************************************************************
Option constants
***********************************************************************************************************************************/
#define CFGOPT_ARCHIVE_ASYNC cfgOptArchiveAsync
#define CFGOPT_ARCHIVE_CHECK cfgOptArchiveCheck
#define CFGOPT_ARCHIVE_COPY cfgOptArchiveCopy
#define CFGOPT_ARCHIVE_GET_QUEUE_MAX cfgOptArchiveGetQueueMax
#define CFGOPT_ARCHIVE_PUSH_QUEUE_MAX cfgOptArchivePushQueueMax
#define CFGOPT_ARCHIVE_TIMEOUT cfgOptArchiveTimeout
#define CFGOPT_BACKUP_STANDBY cfgOptBackupStandby
#define CFGOPT_BUFFER_SIZE cfgOptBufferSize
#define CFGOPT_CHECKSUM_PAGE cfgOptChecksumPage
#define CFGOPT_CMD_SSH cfgOptCmdSsh
#define CFGOPT_COMMAND cfgOptCommand
#define CFGOPT_COMPRESS cfgOptCompress
#define CFGOPT_COMPRESS_LEVEL cfgOptCompressLevel
#define CFGOPT_COMPRESS_LEVEL_NETWORK cfgOptCompressLevelNetwork
#define CFGOPT_CONFIG cfgOptConfig
#define CFGOPT_CONFIG_INCLUDE_PATH cfgOptConfigIncludePath
#define CFGOPT_CONFIG_PATH cfgOptConfigPath
#define CFGOPT_DB_INCLUDE cfgOptDbInclude
#define CFGOPT_DB_TIMEOUT cfgOptDbTimeout
#define CFGOPT_DELTA cfgOptDelta
#define CFGOPT_FORCE cfgOptForce
#define CFGOPT_HOST_ID cfgOptHostId
#define CFGOPT_LINK_ALL cfgOptLinkAll
#define CFGOPT_LINK_MAP cfgOptLinkMap
#define CFGOPT_LOCK_PATH cfgOptLockPath
#define CFGOPT_LOG_LEVEL_CONSOLE cfgOptLogLevelConsole
#define CFGOPT_LOG_LEVEL_FILE cfgOptLogLevelFile
#define CFGOPT_LOG_LEVEL_STDERR cfgOptLogLevelStderr
#define CFGOPT_LOG_PATH cfgOptLogPath
#define CFGOPT_LOG_TIMESTAMP cfgOptLogTimestamp
#define CFGOPT_MANIFEST_SAVE_THRESHOLD cfgOptManifestSaveThreshold
#define CFGOPT_NEUTRAL_UMASK cfgOptNeutralUmask
#define CFGOPT_ONLINE cfgOptOnline
#define CFGOPT_OUTPUT cfgOptOutput
#define CFGOPT_PERL_OPTION cfgOptPerlOption
#define CFGOPT_PG_HOST cfgOptPgHost
#define CFGOPT_PG_HOST_CMD cfgOptPgHostCmd
#define CFGOPT_PG_HOST_CONFIG cfgOptPgHostConfig
#define CFGOPT_PG_HOST_CONFIG_INCLUDE_PATH cfgOptPgHostConfigIncludePath
#define CFGOPT_PG_HOST_CONFIG_PATH cfgOptPgHostConfigPath
#define CFGOPT_PG_HOST_PORT cfgOptPgHostPort
#define CFGOPT_PG_HOST_USER cfgOptPgHostUser
#define CFGOPT_PG_PATH cfgOptPgPath
#define CFGOPT_PG_PORT cfgOptPgPort
#define CFGOPT_PG_SOCKET_PATH cfgOptPgSocketPath
#define CFGOPT_PROCESS cfgOptProcess
#define CFGOPT_PROCESS_MAX cfgOptProcessMax
#define CFGOPT_PROTOCOL_TIMEOUT cfgOptProtocolTimeout
#define CFGOPT_RECOVERY_OPTION cfgOptRecoveryOption
#define CFGOPT_REPO_CIPHER_PASS cfgOptRepoCipherPass
#define CFGOPT_REPO_CIPHER_TYPE cfgOptRepoCipherType
#define CFGOPT_REPO_HARDLINK cfgOptRepoHardlink
#define CFGOPT_REPO_HOST cfgOptRepoHost
#define CFGOPT_REPO_HOST_CMD cfgOptRepoHostCmd
#define CFGOPT_REPO_HOST_CONFIG cfgOptRepoHostConfig
#define CFGOPT_REPO_HOST_CONFIG_INCLUDE_PATH cfgOptRepoHostConfigIncludePath
#define CFGOPT_REPO_HOST_CONFIG_PATH cfgOptRepoHostConfigPath
#define CFGOPT_REPO_HOST_PORT cfgOptRepoHostPort
#define CFGOPT_REPO_HOST_USER cfgOptRepoHostUser
#define CFGOPT_REPO_PATH cfgOptRepoPath
#define CFGOPT_REPO_RETENTION_ARCHIVE cfgOptRepoRetentionArchive
#define CFGOPT_REPO_RETENTION_ARCHIVE_TYPE cfgOptRepoRetentionArchiveType
#define CFGOPT_REPO_RETENTION_DIFF cfgOptRepoRetentionDiff
#define CFGOPT_REPO_RETENTION_FULL cfgOptRepoRetentionFull
#define CFGOPT_REPO_S3_BUCKET cfgOptRepoS3Bucket
#define CFGOPT_REPO_S3_CA_FILE cfgOptRepoS3CaFile
#define CFGOPT_REPO_S3_CA_PATH cfgOptRepoS3CaPath
#define CFGOPT_REPO_S3_ENDPOINT cfgOptRepoS3Endpoint
#define CFGOPT_REPO_S3_HOST cfgOptRepoS3Host
#define CFGOPT_REPO_S3_KEY cfgOptRepoS3Key
#define CFGOPT_REPO_S3_KEY_SECRET cfgOptRepoS3KeySecret
#define CFGOPT_REPO_S3_REGION cfgOptRepoS3Region
#define CFGOPT_REPO_S3_TOKEN cfgOptRepoS3Token
#define CFGOPT_REPO_S3_VERIFY_SSL cfgOptRepoS3VerifySsl
#define CFGOPT_REPO_TYPE cfgOptRepoType
#define CFGOPT_RESUME cfgOptResume
#define CFGOPT_SET cfgOptSet
#define CFGOPT_SPOOL_PATH cfgOptSpoolPath
#define CFGOPT_STANZA cfgOptStanza
#define CFGOPT_START_FAST cfgOptStartFast
#define CFGOPT_STOP_AUTO cfgOptStopAuto
#define CFGOPT_TABLESPACE_MAP cfgOptTablespaceMap
#define CFGOPT_TABLESPACE_MAP_ALL cfgOptTablespaceMapAll
#define CFGOPT_TARGET cfgOptTarget
#define CFGOPT_TARGET_ACTION cfgOptTargetAction
#define CFGOPT_TARGET_EXCLUSIVE cfgOptTargetExclusive
#define CFGOPT_TARGET_TIMELINE cfgOptTargetTimeline
#define CFGOPT_TEST cfgOptTest
#define CFGOPT_TEST_DELAY cfgOptTestDelay
#define CFGOPT_TEST_POINT cfgOptTestPoint
#define CFGOPT_TYPE cfgOptType
#endif

View File

@@ -1,20 +0,0 @@
/***********************************************************************************************************************************
Command and Option Definitions
Automatically generated by Build.pm -- do not modify directly.
***********************************************************************************************************************************/
#ifndef XS_CONFIG_DEFINE_AUTO_H
#define XS_CONFIG_DEFINE_AUTO_H
/***********************************************************************************************************************************
Option type constants
***********************************************************************************************************************************/
#define CFGDEF_TYPE_BOOLEAN cfgDefOptTypeBoolean
#define CFGDEF_TYPE_FLOAT cfgDefOptTypeFloat
#define CFGDEF_TYPE_HASH cfgDefOptTypeHash
#define CFGDEF_TYPE_INTEGER cfgDefOptTypeInteger
#define CFGDEF_TYPE_LIST cfgDefOptTypeList
#define CFGDEF_TYPE_SIZE cfgDefOptTypeSize
#define CFGDEF_TYPE_STRING cfgDefOptTypeString
#endif

View File

@@ -14,7 +14,7 @@ CSTD = -std=c99
COPT = -O2 COPT = -O2
# Locations of header files # Locations of header files
CINCLUDE = -I. CINCLUDE = -I. -I../libc
# Compile warnings # Compile warnings
CWARN = -Wfatal-errors -Wall -Wextra -Wwrite-strings -Wswitch-enum -Wconversion -Wformat=2 -Wformat-nonliteral \ CWARN = -Wfatal-errors -Wall -Wextra -Wwrite-strings -Wswitch-enum -Wconversion -Wformat=2 -Wformat-nonliteral \
@@ -42,7 +42,7 @@ LDPERL = `perl -MExtUtils::Embed -e ldopts`
LDEXTRA = LDEXTRA =
# Concatenate options for easy usage # Concatenate options for easy usage
LDFLAGS = $(LDPERL) $(LDEXTRA) LDFLAGS = -lcrypto $(LDPERL) $(LDEXTRA)
#################################################################################################################################### ####################################################################################################################################
# Install options # Install options
@@ -54,12 +54,17 @@ DESTDIR =
# List of required source files. main.c should always be listed last and the rest in alpha order. # List of required source files. main.c should always be listed last and the rest in alpha order.
#################################################################################################################################### ####################################################################################################################################
SRCS = \ SRCS = \
cipher/block.c \
cipher/cipher.c \
cipher/random.c \
command/archive/common.c \ command/archive/common.c \
command/archive/get/get.c \ command/archive/get/get.c \
command/archive/push/push.c \ command/archive/push/push.c \
command/help/help.c \ command/help/help.c \
command/command.c \ command/command.c \
common/debug.c \ common/debug.c \
common/encode.c \
common/encode/base64.c \
common/error.c \ common/error.c \
common/exit.c \ common/exit.c \
common/fork.c \ common/fork.c \
@@ -87,6 +92,7 @@ SRCS = \
perl/config.c \ perl/config.c \
perl/exec.c \ perl/exec.c \
postgres/info.c \ postgres/info.c \
postgres/pageChecksum.c \
storage/driver/posix/driver.c \ storage/driver/posix/driver.c \
storage/driver/posix/driverFile.c \ storage/driver/posix/driverFile.c \
storage/driver/posix/driverRead.c \ storage/driver/posix/driverRead.c \
@@ -106,6 +112,9 @@ OBJS=$(SRCS:.c=.o)
pgbackrest: $(OBJS) pgbackrest: $(OBJS)
$(CC) -o pgbackrest $(OBJS) $(LDFLAGS) $(CC) -o pgbackrest $(OBJS) $(LDFLAGS)
postgres/pageChecksum.o:
$(CC) $(CFLAGS) -funroll-loops -ftree-vectorize -c postgres/pageChecksum.c -o postgres/pageChecksum.o
.c.o: .c.o:
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@

25113
src/perl/embed.auto.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -15,34 +15,28 @@ Execute Perl for Legacy Functionality
#include "perl/config.h" #include "perl/config.h"
#include "perl/exec.h" #include "perl/exec.h"
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) /***********************************************************************************************************************************
#define WARNING_PEDANTIC 1 Include LibC code
#endif
#pragma GCC diagnostic ignored "-Wsign-conversion"
#if WARNING_PEDANTIC
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
This file is generated by the LibC xs build. Including it here allows the functions provided by the C library to be provided by the
pgBackRest binary instead which means the C library does not need to be deployed in production builds.
***********************************************************************************************************************************/
#ifndef HAS_BOOL #ifndef HAS_BOOL
# define HAS_BOOL 1 # define HAS_BOOL 1
#endif #endif
#include <EXTERN.h> #include "perl/libc.auto.c"
#include <perl.h>
#if WARNING_PEDANTIC
#pragma GCC diagnostic warning "-Wpedantic"
#endif
#pragma GCC diagnostic warning "-Wsign-conversion"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Constants used to build perl options Include embedded Perl modules
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#define PGBACKREST_MODULE PGBACKREST_NAME "::Main" typedef struct EmbeddedModule
#define PGBACKREST_MAIN PGBACKREST_MODULE "::main" {
const char *name;
const char *data;
} EmbeddedModule;
#include "perl/embed.auto.c"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Perl interpreter Perl interpreter
@@ -51,6 +45,12 @@ This is a silly name but Perl prefers it.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
static PerlInterpreter *my_perl = NULL; static PerlInterpreter *my_perl = NULL;
/***********************************************************************************************************************************
Constants used to build perl options
***********************************************************************************************************************************/
#define PGBACKREST_MODULE PGBACKREST_NAME "::Main"
#define PGBACKREST_MAIN PGBACKREST_MODULE "::main"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Build list of parameters to use for perl main Build list of parameters to use for perl main
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@@ -72,11 +72,64 @@ perlMain()
FUNCTION_TEST_RESULT(STRING, mainCall); FUNCTION_TEST_RESULT(STRING, mainCall);
} }
/***********************************************************************************************************************************
Dynamic module loader
***********************************************************************************************************************************/
XS_EUPXS(embeddedModuleGet);
XS_EUPXS(embeddedModuleGet)
{
// Ensure all parameters were passed
dVAR; dXSARGS;
if (items != 1) // {uncovered - no invalid calls}
croak_xs_usage(cv, "moduleName"); // {+uncovered}
// Get module name
const char *moduleName = (const char *)SvPV_nolen(ST(0));
dXSTARG; // {uncovered - internal Perl macro branch}
// Find module
const char *result = NULL;
for (unsigned int moduleIdx = 0; // {uncovered - no invalid modules in embedded Perl}
moduleIdx < sizeof(embeddedModule) / sizeof(EmbeddedModule); moduleIdx++)
{
if (strcmp(embeddedModule[moduleIdx].name, moduleName) == 0)
{
result = embeddedModule[moduleIdx].data;
break;
}
}
// Error if the module was not found
if (result == NULL) // {uncovered - no invalid modules in embedded Perl}
croak("unable to load embedded module '%s'", moduleName); // {+uncovered}
// Return module data
sv_setpv(TARG, result);
XSprePUSH;
PUSHTARG; // {uncovered - internal Perl macro branch}
XSRETURN(1);
}
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Init the dynaloader so other C modules can be loaded Init the dynaloader so other C modules can be loaded
There are no FUNCTION_TEST* calls because this is a callback from Perl and it doesn't seem wise to mix our stack stuff up in it. There are no FUNCTION_TEST* calls because this is a callback from Perl and it doesn't seem wise to mix our stack stuff up in it.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#define LOADER_SUB \
"sub\n" \
"{\n" \
" if ($_[1] =~ /^pgBackRest/)\n" \
" {\n" \
" my $data = pgBackRest::LibC::embeddedModuleGet($_[1]);\n" \
"\n" \
" open my $fh, '<', \\$data;\n" \
" return $fh;\n" \
" }\n" \
"}"
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
static void xs_init(pTHX) static void xs_init(pTHX)
@@ -84,7 +137,14 @@ static void xs_init(pTHX)
dXSUB_SYS; dXSUB_SYS;
PERL_UNUSED_CONTEXT; PERL_UNUSED_CONTEXT;
/* DynaLoader is a special case */ // Register the LibC functions by registering the boot function and calling it
newXS("pgBackRest::LibC::boot", boot_pgBackRest__LibC, __FILE__);
eval_pv("pgBackRest::LibC::boot()", TRUE);
// Register the embedded module getter
newXS("pgBackRest::LibC::embeddedModuleGet", embeddedModuleGet, __FILE__);
// DynaLoader is a special case
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
} }
@@ -120,7 +180,7 @@ perlInit()
PERL_SYS_INIT3(&argc, (char ***)&argv, (char ***)&env); PERL_SYS_INIT3(&argc, (char ***)&argv, (char ***)&env);
// Create the interpreter // Create the interpreter
const char *embedding[] = {"", "-M"PGBACKREST_MODULE, "-e", "0"}; const char *embedding[] = {"", "-e", "0"};
my_perl = perl_alloc(); my_perl = perl_alloc();
perl_construct(my_perl); perl_construct(my_perl);
@@ -132,6 +192,12 @@ perlInit()
PL_exit_flags |= PERL_EXIT_DESTRUCT_END; PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_run(my_perl); perl_run(my_perl);
// Use customer loader to get all embedded modules
eval_pv("splice(@INC, 0, 0, " LOADER_SUB ");", true);
// Now that the custom loader is installed, load the main module;
eval_pv("use " PGBACKREST_MODULE ";", true);
// Set config data -- this is done separately to avoid it being included in stack traces // Set config data -- this is done separately to avoid it being included in stack traces
perlEval(strNewFmt(PGBACKREST_MAIN "ConfigSet('%s', '%s')", strPtr(cfgExe()), strPtr(perlOptionJson()))); perlEval(strNewFmt(PGBACKREST_MAIN "ConfigSet('%s', '%s')", strPtr(cfgExe()), strPtr(perlOptionJson())));
} }

1080
src/perl/libc.auto.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -134,6 +134,7 @@ sub testDefLoad
# Set module type variables # Set module type variables
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_C} = $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_C} =
$strModuleType eq TESTDEF_UNIT && $strTest !~ /\-perl$/ ? true : false; $strModuleType eq TESTDEF_UNIT && $strTest !~ /\-perl$/ ? true : false;
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INTEGRATION} = $strModuleType eq TESTDEF_INTEGRATION ? true : false;
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_EXPECT} = $bExpect; $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_EXPECT} = $bExpect;
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_CONTAINER} = $bContainer; $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_CONTAINER} = $bContainer;
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INDIVIDUAL} = $bIndividual; $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INDIVIDUAL} = $bIndividual;

View File

@@ -200,6 +200,8 @@ sub run
if (!$bGCovExists || $bFlagsChanged) if (!$bGCovExists || $bFlagsChanged)
{ {
executeTest("rsync -rt --delete $self->{strBackRestBase}/src/ $self->{strGCovPath}"); executeTest("rsync -rt --delete $self->{strBackRestBase}/src/ $self->{strGCovPath}");
executeTest("rsync -t $self->{strBackRestBase}/libc/LibC.h $self->{strGCovPath}");
executeTest("rsync -rt $self->{strBackRestBase}/libc/xs/ $self->{strGCovPath}/xs");
executeTest("rsync -rt $self->{strBackRestBase}/test/src/ $self->{strGCovPath}"); executeTest("rsync -rt $self->{strBackRestBase}/test/src/ $self->{strGCovPath}");
} }
@@ -209,7 +211,9 @@ sub run
# If testing Perl code (or C code that calls Perl code) install bin and Perl C Library # If testing Perl code (or C code that calls Perl code) install bin and Perl C Library
if (!$self->{oTest}->{&TEST_C} || $self->{oTest}->{&TEST_PERL_REQ}) if (!$self->{oTest}->{&TEST_C} || $self->{oTest}->{&TEST_PERL_REQ})
{ {
jobInstallC($self->{strBackRestBase}, $self->{oTest}->{&TEST_VM}, $strImage); jobInstallC(
$self->{strBackRestBase}, $self->{oTest}->{&TEST_VM}, $strImage,
!$self->{oTest}->{&TEST_C} && !$self->{oTest}->{&TEST_INTEGRATION});
} }
} }
} }
@@ -357,8 +361,9 @@ sub run
# This warning appears to be broken on U12 even though the functionality is fine # This warning appears to be broken on U12 even though the functionality is fine
($self->{oTest}->{&TEST_VM} eq VM_U12 || $self->{oTest}->{&TEST_VM} eq VM_CO6 ? ($self->{oTest}->{&TEST_VM} eq VM_U12 || $self->{oTest}->{&TEST_VM} eq VM_CO6 ?
" -Wno-missing-field-initializers \\\n" : '') . " -Wno-missing-field-initializers \\\n" : '') .
($self->{oTest}->{&TEST_VM} ne VM_CO6 && $self->{oTest}->{&TEST_VM} ne VM_U12 ? # ($self->{oTest}->{&TEST_VM} ne VM_CO6 && $self->{oTest}->{&TEST_VM} ne VM_U12 &&
" -Wpedantic \\\n" : '') . # $self->{oTest}->{&TEST_MODULE} ne 'perl' && $self->{oTest}->{&TEST_NAME} ne 'exec' ?
# " -Wpedantic \\\n" : '') .
" -Wformat=2 -Wformat-nonliteral \\\n" . " -Wformat=2 -Wformat-nonliteral \\\n" .
" `perl -MExtUtils::Embed -e ccopts`\n" . " `perl -MExtUtils::Embed -e ccopts`\n" .
"LDFLAGS=-lcrypto" . (vmCoverage($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? " -lgcov" : '') . "LDFLAGS=-lcrypto" . (vmCoverage($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? " -lgcov" : '') .
@@ -616,6 +621,7 @@ sub jobInstallC
my $strBasePath = shift; my $strBasePath = shift;
my $strVm = shift; my $strVm = shift;
my $strImage = shift; my $strImage = shift;
my $bCopyLibC = shift;
# Install Perl C Library # Install Perl C Library
my $oVm = vmGet(); my $oVm = vmGet();
@@ -623,20 +629,14 @@ sub jobInstallC
my $strBuildLibCPath = "$strBuildPath/libc/${strVm}/libc"; my $strBuildLibCPath = "$strBuildPath/libc/${strVm}/libc";
my $strBuildBinPath = "$strBuildPath/bin/${strVm}/src"; my $strBuildBinPath = "$strBuildPath/bin/${strVm}/src";
my $strPerlAutoPath = $oVm->{$strVm}{&VMDEF_PERL_ARCH_PATH} . '/auto/pgBackRest/LibC'; my $strPerlAutoPath = $oVm->{$strVm}{&VMDEF_PERL_ARCH_PATH} . '/auto/pgBackRest/LibC';
my $strPerlModulePath = $oVm->{$strVm}{&VMDEF_PERL_ARCH_PATH} . '/pgBackRest';
executeTest( executeTest(
"docker exec -i -u root ${strImage} bash -c '" . "docker exec -i -u root ${strImage} bash -c '" .
"mkdir -p -m 755 ${strPerlAutoPath} && " . (defined($bCopyLibC) && $bCopyLibC ?
# "cp ${strBuildLibCPath}/blib/arch/auto/pgBackRest/LibC/LibC.bs ${strPerlAutoPath} && " . "mkdir -p -m 755 ${strPerlAutoPath} && " .
"cp ${strBuildLibCPath}/blib/arch/auto/pgBackRest/LibC/LibC.so ${strPerlAutoPath} && " . "cp ${strBuildLibCPath}/blib/arch/auto/pgBackRest/LibC/LibC.so ${strPerlAutoPath} && " : '') .
"cp ${strBuildLibCPath}/blib/lib/auto/pgBackRest/LibC/autosplit.ix ${strPerlAutoPath} && " .
"mkdir -p -m 755 ${strPerlModulePath} && " .
"cp ${strBuildLibCPath}/blib/lib/pgBackRest/LibC.pm ${strPerlModulePath} && " .
"cp ${strBuildLibCPath}/blib/lib/pgBackRest/LibCAuto.pm ${strPerlModulePath} && " .
"cp ${strBuildBinPath}/" . BACKREST_EXE . ' /usr/bin/' . BACKREST_EXE . ' && ' . "cp ${strBuildBinPath}/" . BACKREST_EXE . ' /usr/bin/' . BACKREST_EXE . ' && ' .
'chmod 755 /usr/bin/' . BACKREST_EXE . ' && ' . 'chmod 755 /usr/bin/' . BACKREST_EXE . "'");
"ln -s ${strBasePath}/lib/pgBackRest /usr/share/perl5/pgBackRest'");
} }
push(@EXPORT, qw(jobInstallC)); push(@EXPORT, qw(jobInstallC));

View File

@@ -42,6 +42,8 @@ use constant TEST_PERL_REQ => 'perl-req
push @EXPORT, qw(TEST_PERL_REQ); push @EXPORT, qw(TEST_PERL_REQ);
use constant TEST_PGSQL_BIN => 'pgsql-bin'; use constant TEST_PGSQL_BIN => 'pgsql-bin';
push @EXPORT, qw(TEST_PGSQL_BIN); push @EXPORT, qw(TEST_PGSQL_BIN);
use constant TEST_INTEGRATION => 'integration';
push @EXPORT, qw(TEST_INTEGRATION);
use constant TEST_RUN => 'run'; use constant TEST_RUN => 'run';
push @EXPORT, qw(TEST_RUN); push @EXPORT, qw(TEST_RUN);
use constant TEST_VM => 'os'; use constant TEST_VM => 'os';
@@ -155,6 +157,7 @@ sub testListGet
&TEST_PGSQL_BIN => $strPgSqlBin, &TEST_PGSQL_BIN => $strPgSqlBin,
&TEST_PERL_ARCH_PATH => $$oyVm{$strTestOS}{&VMDEF_PERL_ARCH_PATH}, &TEST_PERL_ARCH_PATH => $$oyVm{$strTestOS}{&VMDEF_PERL_ARCH_PATH},
&TEST_PERL_REQ => $hTest->{&TESTDEF_PERL_REQ}, &TEST_PERL_REQ => $hTest->{&TESTDEF_PERL_REQ},
&TEST_INTEGRATION => $hTest->{&TESTDEF_INTEGRATION},
&TEST_MODULE => $strModule, &TEST_MODULE => $strModule,
&TEST_NAME => $strModuleTest, &TEST_NAME => $strModuleTest,
&TEST_RUN => &TEST_RUN =>

View File

@@ -105,7 +105,7 @@ use constant VM_HOST_DEFAULT => VM_U16;
use constant VM_COVERAGE => VM_U16; use constant VM_COVERAGE => VM_U16;
# Lists valid VMs # Lists valid VMs
use constant VM_LIST => (VM_CO6, VM_U16, VM_CO7, VM_U12); use constant VM_LIST => (VM_U16, VM_CO6, VM_CO7, VM_U12);
push @EXPORT, qw(VM_LIST); push @EXPORT, qw(VM_LIST);
my $oyVm = my $oyVm =

View File

@@ -0,0 +1,30 @@
--- pgbackrest.install
++++ pgbackrest.install
@@ -1,2 +1 @@
debian/pgbackrest.conf etc/
-lib/pgBackRest usr/share/perl5/
--- rules
+++ rules
@@ -20,22 +20,16 @@
-t pgbackrest \
-s 1 \
${MANTEMPLATE} > ${CURDIR}/doc/output/man/pgbackrest.1
- cd $(CURDIR)/libc; perl Makefile.PL INSTALLDIRS=vendor NO_PACKLIST=1
- make -C $(CURDIR)/libc/
make -C $(CURDIR)/src/
dh_auto_build
override_dh_auto_test:
- test "$(DEB_TARGET_ARCH_ENDIAN)" = "little" && \
- cd $(CURDIR)/libc; make test
dh_auto_test
override_dh_auto_clean:
rm -rf $(CURDIR)/doc/output
- test ! -f libc/Makefile || make -C libc distclean
dh_auto_clean
override_dh_auto_install:
- make -C libc install DESTDIR=$(CURDIR)/debian/pgbackrest
make -C src install DESTDIR=$(CURDIR)/debian/pgbackrest
dh_auto_install

View File

@@ -0,0 +1,37 @@
--- pgbackrest.spec
+++ pgbackrest.spec
@@ -28,11 +28,6 @@
%setup -q -n %{name}-release-%{version}
%build
-pushd libc
-perl Makefile.PL
-%{__make}
-popd
-
pushd src
%{__make}
popd
@@ -44,12 +39,6 @@
%{__install} -D -d -m 0700 %{buildroot}/var/spool/%{name}
%{__install} -D -d -m 0755 %{buildroot}%{_sysconfdir}
%{__install} %{SOURCE1} %{buildroot}/%{_sysconfdir}/%{name}.conf
-%{__cp} -a lib/* %{buildroot}%{perl_vendorlib}/
-%{__mkdir} -p %{buildroot}%{perl_vendorarch}/auto/pgBackRest/LibC
-%{__cp} -a libc/blib/arch/auto/pgBackRest/LibC/* %{buildroot}%{perl_vendorarch}/auto/pgBackRest/LibC
-%{__cp} -a libc/blib/lib/auto/pgBackRest/LibC/* %{buildroot}%{perl_vendorarch}/auto/pgBackRest/LibC
-%{__mkdir} -p %{buildroot}%{perl_vendorarch}/pgBackRest
-%{__cp} -a libc/blib/lib/pgBackRest/* %{buildroot}%{perl_vendorarch}/pgBackRest
%{__cp} -a src/%{name} %{buildroot}%{_bindir}/%{name}
%clean
@@ -64,9 +53,6 @@
%endif
%{_bindir}/%{name}
%config(noreplace) %attr (644,root,root) %{_sysconfdir}/%{name}.conf
-%{perl_vendorlib}/pgBackRest/
-%{perl_vendorarch}/pgBackRest/
-%{perl_vendorarch}/auto/pgBackRest/LibC
%attr(-,postgres,postgres) /var/log/%{name}
%attr(-,postgres,postgres) %{_sharedstatedir}/%{name}
%attr(-,postgres,postgres) /var/spool/%{name}

View File

@@ -42,6 +42,7 @@ use pgBackRestBuild::Build::Common;
use pgBackRestBuild::Config::Build; use pgBackRestBuild::Config::Build;
use pgBackRestBuild::Config::BuildDefine; use pgBackRestBuild::Config::BuildDefine;
use pgBackRestBuild::Config::BuildParse; use pgBackRestBuild::Config::BuildParse;
use pgBackRestBuild::Embed::Build;
use pgBackRestBuild::Error::Build; use pgBackRestBuild::Error::Build;
use pgBackRestBuild::Error::Data; use pgBackRestBuild::Error::Data;
@@ -78,10 +79,11 @@ test.pl [options]
--pg-version version of postgres to test (all, defaults to minimal) --pg-version version of postgres to test (all, defaults to minimal)
--log-force force overwrite of current test log files --log-force force overwrite of current test log files
--no-lint disable static source code analysis --no-lint disable static source code analysis
--build-only compile the C library / packages and run tests only --build-only compile the test library / packages and run tests only
--coverage-only only run coverage tests (as a subset of selected tests) --coverage-only only run coverage tests (as a subset of selected tests)
--c-only only run C tests --c-only only run C tests
--gen-only only run auto-generation --gen-only only run auto-generation
--no-gen do not run code generation
--code-count generate code counts --code-count generate code counts
--smart perform libc/package builds only when source timestamps have changed --smart perform libc/package builds only when source timestamps have changed
--no-package do not build packages --no-package do not build packages
@@ -143,6 +145,7 @@ my $bCoverageOnly = false;
my $bNoCoverage = false; my $bNoCoverage = false;
my $bCOnly = false; my $bCOnly = false;
my $bGenOnly = false; my $bGenOnly = false;
my $bNoGen = false;
my $bCodeCount = false; my $bCodeCount = false;
my $bSmart = false; my $bSmart = false;
my $bNoPackage = false; my $bNoPackage = false;
@@ -185,6 +188,7 @@ GetOptions ('q|quiet' => \$bQuiet,
'no-coverage' => \$bNoCoverage, 'no-coverage' => \$bNoCoverage,
'c-only' => \$bCOnly, 'c-only' => \$bCOnly,
'gen-only' => \$bGenOnly, 'gen-only' => \$bGenOnly,
'no-gen' => \$bNoGen,
'code-count' => \$bCodeCount, 'code-count' => \$bCodeCount,
'smart' => \$bSmart, 'smart' => \$bSmart,
'dev' => \$bDev, 'dev' => \$bDev,
@@ -360,87 +364,116 @@ eval
exit 0; exit 0;
} }
# Auto-generate C files # Auto-generate files unless --no-gen specified
#--------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------------
&log(INFO, "check code autogenerate"); if (!$bNoGen)
errorDefineLoad(${$oStorageBackRest->get("build/error.yaml")});
# Get last mod for build files and version file
my $lLastBuildMod = buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['build']);
my $lLastVersionMod = buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['lib'], 'Version\.pm$');
# If version mod is later than build mod, then make it the build mod
if ($lLastVersionMod > $lLastBuildMod)
{ {
$lLastBuildMod = $lLastVersionMod; &log(INFO, "check code autogenerate");
}
if (!$bSmart || $lLastBuildMod > buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['src'], '\.auto\.c$')) # Auto-generate C files
{ #-----------------------------------------------------------------------------------------------------------------------
&log(INFO, " autogenerate C code"); if (!$bSmart || buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['build']) >
buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['src'], '\.auto\.c$'))
my $rhBuild =
{ {
'config' => &log(INFO, " autogenerate C code");
{
&BLD_DATA => buildConfig(),
&BLD_PATH => 'config',
},
'configDefine' => errorDefineLoad(${$oStorageBackRest->get("build/error.yaml")});
{
&BLD_DATA => buildConfigDefine(),
&BLD_PATH => 'config',
},
'configParse' => my $rhBuild =
{ {
&BLD_DATA => buildConfigParse(), 'config' =>
&BLD_PATH => 'config', {
}, &BLD_DATA => buildConfig(),
&BLD_PATH => 'config',
},
'error' => 'configDefine' =>
{
&BLD_DATA => buildConfigDefine(),
&BLD_PATH => 'config',
},
'configParse' =>
{
&BLD_DATA => buildConfigParse(),
&BLD_PATH => 'config',
},
'error' =>
{
&BLD_DATA => buildError(),
&BLD_PATH => 'common',
},
};
buildAll("${strBackRestBase}/src", $rhBuild);
}
# Auto-generate Perl code
#-----------------------------------------------------------------------------------------------------------------------
use lib dirname(dirname($0)) . '/libc/build/lib';
use pgBackRestLibC::Build; ## no critic (Modules::ProhibitConditionalUseStatements)
if (!$bSmart || buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['build', 'libc/build']) >
buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['lib'], 'Auto\.pm$'))
{
&log(INFO, " autogenerate Perl code");
errorDefineLoad(${$oStorageBackRest->get("build/error.yaml")});
buildXsAll("${strBackRestBase}/libc");
}
# Auto-generate C library code to embed in the binary
#-----------------------------------------------------------------------------------------------------------------------
if (!$bSmart || buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['libc']) >
buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['src/perl'], '^libc\.auto\.c$'))
{
&log(INFO, " autogenerate embedded C code");
my $strLibC = executeTest(
"cd ${strBackRestBase}/libc && " .
"perl /usr/share/perl/5.22/ExtUtils/xsubpp -typemap /usr/share/perl/5.22/ExtUtils/typemap" .
" -typemap typemap LibC.xs");
# Trim off any trailing LFs
$strLibC = trim($strLibC) . "\n";
# Strip out line numbers. These are useful for the LibC build but only cause churn in the binary
# build.
$strLibC =~ s/^\#line .*\n//mg;
# Save into the bin src dir
$oStorageBackRest->put("${strBackRestBase}/src/perl/libc.auto.c", $strLibC);
}
# Auto-generate embedded Perl code
#-----------------------------------------------------------------------------------------------------------------------
if (!$bSmart || buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['lib']) >
buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['src/perl'], 'embed\.auto\.c'))
{
&log(INFO, " autogenerate embedded Perl code");
my $rhBuild =
{ {
&BLD_DATA => buildError(), 'embed' =>
&BLD_PATH => 'common', {
}, &BLD_DATA => buildEmbed($oStorageBackRest),
}; &BLD_PATH => 'perl',
},
};
buildAll("${strBackRestBase}/src", $rhBuild); buildAll("${strBackRestBase}/src", $rhBuild);
}
if ($bGenOnly)
{
exit 0;
}
} }
# Auto-generate XS files # Build CI config
#
# Use statements are put here so this will be easy to get rid of someday.
#--------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------------
use lib dirname(dirname($0)) . '/libc/build/lib';
use pgBackRestLibC::Build; ## no critic (Modules::ProhibitConditionalUseStatements)
use pgBackRestLibC::BuildParam; ## no critic (Modules::ProhibitConditionalUseStatements)
# Get last mod for Perl build files
my $lLastPerlBuildMod = buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['libc/build']);
# If Perl build mod is later than build mod, then make it the build mod
if ($lLastPerlBuildMod > $lLastBuildMod)
{
$lLastBuildMod = $lLastPerlBuildMod;
}
if (!$bSmart ||
$lLastBuildMod > buildLastModTime($oStorageBackRest, "${strBackRestBase}", ['libc', 'lib'], '(\.auto\.xs|Auto\.pm)$'))
{
&log(INFO, " autogenerate Perl code");
buildXsAll("${strBackRestBase}/libc");
}
if ($bGenOnly)
{
exit 0;
}
# Build CI configuration
if (!$bNoCiConfig) if (!$bNoCiConfig)
{ {
(new pgBackRestTest::Common::CiTest($oStorageBackRest))->process(); (new pgBackRestTest::Common::CiTest($oStorageBackRest))->process();
@@ -548,7 +581,9 @@ eval
# Determine which tests to run # Determine which tests to run
#--------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------------
my $oyTestRun; my $oyTestRun;
my $bBuildRequired = false; my $bBinRequired = $bBuildOnly;
my $bLibCHostRequired = $bBuildOnly;
my $bLibCVmRequired = $bBuildOnly;
# Only get the test list when they can run # Only get the test list when they can run
if (!$bBuildOnly) if (!$bBuildOnly)
@@ -557,274 +592,312 @@ eval
$oyTestRun = testListGet( $oyTestRun = testListGet(
$strVm, \@stryModule, \@stryModuleTest, \@iyModuleTestRun, $strPgVersion, $bCoverageOnly, $bCOnly); $strVm, \@stryModule, \@stryModuleTest, \@iyModuleTestRun, $strPgVersion, $bCoverageOnly, $bCOnly);
# Search for any tests that are not C unit tests to determine if the C binary and lib need to be built for testing. If # Determine if the C binary and test library need to be built
# all the tests are C unit tests then no builds are required. This saves a lot ot time.
foreach my $hTest (@{$oyTestRun}) foreach my $hTest (@{$oyTestRun})
{ {
# Bin build required for all Perl tests or if a C unit test calls Perl
if (!$hTest->{&TEST_C} || $hTest->{&TEST_PERL_REQ}) if (!$hTest->{&TEST_C} || $hTest->{&TEST_PERL_REQ})
{ {
$bBuildRequired = true; $bBinRequired = true;
last; }
# Host LibC required if a Perl test
if (!$hTest->{&TEST_C})
{
$bLibCHostRequired = true;
}
# VM LibC required if Perl and not an integration test
if (!$hTest->{&TEST_C} && !$hTest->{&TEST_INTEGRATION})
{
$bLibCVmRequired = true;
} }
} }
} }
my $strBuildRequired;
if ($bBinRequired || $bLibCHostRequired || $bLibCVmRequired)
{
if ($bBinRequired)
{
$strBuildRequired = "bin";
}
if ($bLibCHostRequired)
{
$strBuildRequired .= ", libc host";
}
if ($bLibCVmRequired)
{
$strBuildRequired .= ", libc vm";
}
}
else
{
$strBuildRequired = "none";
}
&log(INFO, "builds required: ${strBuildRequired}");
# Build the binary, library and packages # Build the binary, library and packages
#--------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------------
if (!$bDryRun && $bBuildRequired) if (!$bDryRun)
{ {
&log(INFO, "check bin builds");
my $oVm = vmGet(); my $oVm = vmGet();
my $strVagrantPath = "${strBackRestBase}/test/.vagrant"; my $strVagrantPath = "${strBackRestBase}/test/.vagrant";
my $lTimestampLast;
# Build the binary
#---------------------------------------------------------------------------------------------------------------------------
my $strBinPath = "${strVagrantPath}/bin";
my $strBinSmart = "${strBinPath}/build.timestamp";
my $bRebuild = !$bSmart;
my @stryBinSrcPath = ('src');
# Find the lastest modified time for dirs that affect the bin build
my $lTimestampLast = buildLastModTime($oStorageBackRest, $strBackRestBase, \@stryBinSrcPath);
# Rebuild if the modification time of the smart file does equal the last changes in source paths
if ($bSmart)
{
if (!$oStorageBackRest->exists($strBinSmart) || $oStorageBackRest->info($strBinSmart)->mtime < $lTimestampLast)
{
&log(INFO, ' bin dependencies have changed, rebuilding...');
$bRebuild = true;
}
}
else
{
executeTest("sudo rm -rf ${strBinPath}");
}
# Loop through VMs to do the C bin builds
my $bLogDetail = $strLogLevel eq 'detail';
my @stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm);
foreach my $strBuildVM (sort(@stryBuildVm))
{
my $strBuildPath = "${strBinPath}/${strBuildVM}/src";
if ($bRebuild)
{
&log(INFO, " build bin for ${strBuildVM} (${strBuildPath})");
executeTest(
"docker run -itd -h test-build --name=test-build" .
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build",
{bSuppressStdErr => true});
foreach my $strBinSrcPath (@stryBinSrcPath)
{
$oStorageBackRest->pathCreate(
"${strBinPath}/${strBuildVM}/${strBinSrcPath}", {bIgnoreExists => true, bCreateParent => true});
executeTest("rsync -rt ${strBackRestBase}/${strBinSrcPath}/* ${strBinPath}/${strBuildVM}/${strBinSrcPath}");
}
if (vmCoverage($strVm) && !$bNoLint)
{
&log(INFO, " clang static analyzer ${strBuildVM} (${strBuildPath})");
}
my $strCExtra =
"'-g" . (vmWithBackTrace($strBuildVM) && $bNoLint && $bBackTrace ? ' -DWITH_BACKTRACE' : '') . "'";
my $strLdExtra = vmWithBackTrace($strBuildVM) && $bNoLint && $bBackTrace ? '-lbacktrace' : '';
my $strCDebug = vmDebugIntegration($strBuildVM) ? 'CDEBUG=' : '';
executeTest(
'docker exec -i test-build' .
(vmCoverage($strVm) && !$bNoLint ? ' scan-build-5.0' : '') .
" make --silent --directory ${strBuildPath} CEXTRA=${strCExtra} LDEXTRA=${strLdExtra} ${strCDebug}",
{bShowOutputAsync => $bLogDetail});
executeTest(
"docker exec -i test-build make --silent --directory ${strBuildPath} install",
{bShowOutputAsync => $bLogDetail});
executeTest("docker rm -f test-build");
}
}
# Write files to indicate the last time a build was successful
$oStorageBackRest->put($strBinSmart);
utime($lTimestampLast, $lTimestampLast, $strBinSmart) or
confess "unable to set time for ${strBinSmart}" . (defined($!) ? ":$!" : '');
# Build the C Library # Build the C Library
#--------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
my $strLibCPath = "${strVagrantPath}/libc"; if ($bLibCHostRequired || $bLibCVmRequired)
my $strLibCSmart = "${strLibCPath}/build.timestamp";
$bRebuild = !$bSmart;
my @stryLibCSrcPath = ('libc', 'src');
# Find the lastest modified time for dirs that affect the libc build
$lTimestampLast = buildLastModTime($oStorageBackRest, $strBackRestBase, \@stryLibCSrcPath);
# Rebuild if the modification time of the smart file does equal the last changes in source paths
if ($bSmart)
{ {
if (!$oStorageBackRest->exists($strLibCSmart) || $oStorageBackRest->info($strLibCSmart)->mtime < $lTimestampLast) my $strLibCPath = "${strVagrantPath}/libc";
my $strLibCSmart = "${strLibCPath}/build.timestamp";
my $bRebuild = !$bSmart;
my @stryLibCSrcPath = $bLibCHostRequired || $bLibCVmRequired ? ('libc', 'src') : ('libc');
# Find the lastest modified time for dirs that affect the libc build
$lTimestampLast = buildLastModTime($oStorageBackRest, $strBackRestBase, \@stryLibCSrcPath);
# Rebuild if the modification time of the smart file does equal the last changes in source paths
if ($bSmart)
{ {
&log(INFO, ' libc dependencies have changed, rebuilding...'); if (!$oStorageBackRest->exists($strLibCSmart) ||
$oStorageBackRest->info($strLibCSmart)->mtime < $lTimestampLast)
{
&log(INFO, ' libc dependencies have changed, rebuilding...');
$bRebuild = true; $bRebuild = true;
}
}
else
{
executeTest("sudo rm -rf ${strLibCPath}");
} }
}
else
{
executeTest("sudo rm -rf ${strLibCPath}");
}
# Delete old libc files from the host
if ($bRebuild)
{
executeTest('sudo rm -rf ' . $oVm->{$strVmHost}{&VMDEF_PERL_ARCH_PATH} . '/auto/pgBackRest/LibC');
executeTest('sudo rm -rf ' . $oVm->{$strVmHost}{&VMDEF_PERL_ARCH_PATH} . '/pgBackRest');
}
# Loop through VMs to do the C Library builds
$bLogDetail = $strLogLevel eq 'detail';
@stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm eq $strVmHost ? ($strVm) : ($strVm, $strVmHost));
foreach my $strBuildVM (sort(@stryBuildVm))
{
my $strBuildPath = "${strLibCPath}/${strBuildVM}/libc";
my $bContainerExists = $strVm eq VM_ALL || $strBuildVM ne $strVmHost;
# Delete old libc files from the host
if ($bRebuild) if ($bRebuild)
{ {
&log(INFO, " build C library for ${strBuildVM} (${strBuildPath})"); executeTest('sudo rm -rf ' . $oVm->{$strVmHost}{&VMDEF_PERL_ARCH_PATH} . '/auto/pgBackRest/LibC');
executeTest('sudo rm -rf ' . $oVm->{$strVmHost}{&VMDEF_PERL_ARCH_PATH} . '/pgBackRest');
}
# It's very expensive to rebuild the Makefile so make sure it has actually changed # Loop through VMs to do the C Library builds
my $bMakeRebuild = my $bLogDetail = $strLogLevel eq 'detail';
!$oStorageBackRest->exists("${strBuildPath}/Makefile") || my @stryBuildVm = ();
($oStorageBackRest->info("${strBackRestBase}/libc/Makefile.PL")->mtime >
$oStorageBackRest->info("${strBuildPath}/Makefile.PL")->mtime);
if ($bContainerExists) if ($strVm eq VM_ALL)
{
@stryBuildVm = $bLibCVmRequired ? VM_LIST : ($strVmHost);
}
else
{
@stryBuildVm = $bLibCVmRequired ? ($strVmHost, $strVm) : ($strVmHost);
}
foreach my $strBuildVM (@stryBuildVm)
{
my $strBuildPath = "${strLibCPath}/${strBuildVM}/libc";
my $bContainerExists = $strBuildVM ne $strVmHost;
if ($bRebuild)
{ {
&log(INFO, " build test library for ${strBuildVM} (${strBuildPath})");
# It's very expensive to rebuild the Makefile so make sure it has actually changed
my $bMakeRebuild =
!$oStorageBackRest->exists("${strBuildPath}/Makefile") ||
($oStorageBackRest->info("${strBackRestBase}/libc/Makefile.PL")->mtime >
$oStorageBackRest->info("${strBuildPath}/Makefile.PL")->mtime);
if ($bContainerExists)
{
executeTest(
"docker run -itd -h test-build --name=test-build" .
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build",
{bSuppressStdErr => true});
}
foreach my $strLibCSrcPath ('lib', 'libc', 'src')
{
$oStorageBackRest->pathCreate(
"${strLibCPath}/${strBuildVM}/${strLibCSrcPath}", {bIgnoreExists => true, bCreateParent => true});
executeTest(
"rsync -rt ${strBackRestBase}/${strLibCSrcPath}/* ${strLibCPath}/${strBuildVM}/${strLibCSrcPath}");
}
if ($bMakeRebuild)
{
executeTest(
($bContainerExists ? "docker exec -i test-build bash -c '" : '') .
"cd ${strBuildPath} && perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none" .
($bContainerExists ? "'" : ''),
{bSuppressStdErr => true, bShowOutputAsync => $bLogDetail});
}
executeTest(
($bContainerExists ? 'docker exec -i test-build ' : '') .
"make --silent --directory ${strBuildPath}",
{bShowOutputAsync => $bLogDetail});
executeTest(
($bContainerExists ? 'docker exec -i test-build ' : '') .
"make --silent --directory ${strBuildPath} test",
{bShowOutputAsync => $bLogDetail});
executeTest(
($bContainerExists ? 'docker exec -i test-build ' : 'sudo ') .
"make --silent --directory ${strBuildPath} install",
{bShowOutputAsync => $bLogDetail});
if ($bContainerExists)
{
executeTest("docker rm -f test-build");
}
if ($strBuildVM eq $strVmHost)
{
executeTest("sudo make -C ${strBuildPath} install", {bSuppressStdErr => true});
# Load the module dynamically
require pgBackRest::LibC;
pgBackRest::LibC->import(qw(:debug));
require XSLoader;
XSLoader::load('pgBackRest::LibC', '999');
# Do a basic test to make sure it installed correctly
if (libcUvSize() != 8)
{
confess &log(ERROR, 'UVSIZE in test library does not equal 8');
}
}
}
}
# Write files to indicate the last time a build was successful
$oStorageBackRest->put($strLibCSmart);
utime($lTimestampLast, $lTimestampLast, $strLibCSmart) or
confess "unable to set time for ${strLibCSmart}" . (defined($!) ? ":$!" : '');
}
# Build the binary
#-----------------------------------------------------------------------------------------------------------------------
if ($bBinRequired)
{
my $strBinPath = "${strVagrantPath}/bin";
my $strBinSmart = "${strBinPath}/build.timestamp";
my $bRebuild = !$bSmart;
my @stryBinSrcPath = ('src', 'libc');
# Find the lastest modified time for dirs that affect the bin build
$lTimestampLast = buildLastModTime($oStorageBackRest, $strBackRestBase, \@stryBinSrcPath);
# Rebuild if the modification time of the smart file does equal the last changes in source paths
if ($bSmart)
{
if (!$oStorageBackRest->exists($strBinSmart) || $oStorageBackRest->info($strBinSmart)->mtime < $lTimestampLast)
{
&log(INFO, ' bin dependencies have changed, rebuilding...');
$bRebuild = true;
}
}
else
{
executeTest("sudo rm -rf ${strBinPath}");
}
# Loop through VMs to do the C bin builds
my $bLogDetail = $strLogLevel eq 'detail';
my @stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm);
foreach my $strBuildVM (@stryBuildVm)
{
my $strBuildPath = "${strBinPath}/${strBuildVM}/src";
if ($bRebuild)
{
&log(INFO, " build bin for ${strBuildVM} (${strBuildPath})");
executeTest( executeTest(
"docker run -itd -h test-build --name=test-build" . "docker run -itd -h test-build --name=test-build" .
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build", " -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build",
{bSuppressStdErr => true}); {bSuppressStdErr => true});
}
foreach my $strLibCSrcPath (@stryLibCSrcPath) foreach my $strBinSrcPath (@stryBinSrcPath)
{ {
$oStorageBackRest->pathCreate( $oStorageBackRest->pathCreate(
"${strLibCPath}/${strBuildVM}/${strLibCSrcPath}", {bIgnoreExists => true, bCreateParent => true}); "${strBinPath}/${strBuildVM}/${strBinSrcPath}", {bIgnoreExists => true, bCreateParent => true});
executeTest( executeTest(
"rsync -rt ${strBackRestBase}/${strLibCSrcPath}/* ${strLibCPath}/${strBuildVM}/${strLibCSrcPath}"); "rsync -rt ${strBackRestBase}/${strBinSrcPath}/* ${strBinPath}/${strBuildVM}/${strBinSrcPath}");
} }
if ($bMakeRebuild) if (vmCoverage($strVm) && !$bNoLint)
{ {
my $strCCFlags = vmDebugIntegration($strBuildVM) ? ' CCFLAGS="' . join(' ', buildParamCCDebug()) . '"' : ''; &log(INFO, " clang static analyzer ${strBuildVM} (${strBuildPath})");
$strCCFlags =~ s/\$/\\\$/; }
my $strCExtra =
"'-g" . (vmWithBackTrace($strBuildVM) && $bNoLint && $bBackTrace ? ' -DWITH_BACKTRACE' : '') . "'";
my $strLdExtra = vmWithBackTrace($strBuildVM) && $bNoLint && $bBackTrace ? '-lbacktrace' : '';
my $strCDebug = vmDebugIntegration($strBuildVM) ? 'CDEBUG=' : '';
executeTest( executeTest(
($bContainerExists ? "docker exec -i test-build bash -c '" : '') . 'docker exec -i test-build' .
"cd ${strBuildPath} && perl Makefile.PL${strCCFlags} INSTALLMAN1DIR=none INSTALLMAN3DIR=none" . (vmCoverage($strVm) && !$bNoLint ? ' scan-build-5.0' : '') .
($bContainerExists ? "'" : ''), " make --silent --directory ${strBuildPath} CEXTRA=${strCExtra} LDEXTRA=${strLdExtra} ${strCDebug}",
{bSuppressStdErr => true, bShowOutputAsync => $bLogDetail}); {bShowOutputAsync => $bLogDetail});
}
executeTest(
($bContainerExists ? 'docker exec -i test-build ' : '') .
"make --silent --directory ${strBuildPath}",
{bShowOutputAsync => $bLogDetail});
executeTest(
($bContainerExists ? 'docker exec -i test-build ' : '') .
"make --silent --directory ${strBuildPath} test",
{bShowOutputAsync => $bLogDetail});
executeTest(
($bContainerExists ? 'docker exec -i test-build ' : 'sudo ') .
"make --silent --directory ${strBuildPath} install",
{bShowOutputAsync => $bLogDetail});
if ($bContainerExists)
{
executeTest("docker rm -f test-build"); executeTest("docker rm -f test-build");
} }
if ($strBuildVM eq $strVmHost)
{
executeTest("sudo make -C ${strBuildPath} install", {bSuppressStdErr => true});
# Load the module dynamically
require pgBackRest::LibC;
pgBackRest::LibC->import(qw(:debug));
# Do a basic test to make sure it installed correctly
if (&UVSIZE != 8)
{
confess &log(ERROR, 'UVSIZE in C library does not equal 8');
}
# Also check the version number
my $strLibCVersion =
BACKREST_VERSION =~ /dev$/ ?
substr(BACKREST_VERSION, 0, length(BACKREST_VERSION) - 3) . '.999' : BACKREST_VERSION;
if (libcVersion() ne $strLibCVersion)
{
confess &log(ERROR, $strLibCVersion . ' was expected for LibC version but found ' . libcVersion());
}
}
} }
}
# Write files to indicate the last time a build was successful # Write files to indicate the last time a build was successful
$oStorageBackRest->put($strLibCSmart); $oStorageBackRest->put($strBinSmart);
utime($lTimestampLast, $lTimestampLast, $strLibCSmart) or utime($lTimestampLast, $lTimestampLast, $strBinSmart) or
confess "unable to set time for ${strLibCSmart}" . (defined($!) ? ":$!" : ''); confess "unable to set time for ${strBinSmart}" . (defined($!) ? ":$!" : '');
}
# Build the package # Build the package
#--------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------
my $strPackagePath = "${strVagrantPath}/package";
my $strPackageSmart = "${strPackagePath}/build.timestamp";
my @stryPackageSrcPath = ('lib');
# Find the lastest modified time for additional dirs that affect the package build
foreach my $strPackageSrcPath (@stryPackageSrcPath)
{
my $hManifest = $oStorageBackRest->manifest($strPackageSrcPath);
foreach my $strFile (sort(keys(%{$hManifest})))
{
if ($hManifest->{$strFile}{type} eq 'f' && $hManifest->{$strFile}{modification_time} > $lTimestampLast)
{
$lTimestampLast = $hManifest->{$strFile}{modification_time};
}
}
}
# Rebuild if the modification time of the smart file does equal the last changes in source paths
if (!$bNoPackage &&
(!$bSmart || !$oStorageBackRest->exists($strPackageSmart) ||
$oStorageBackRest->info($strPackageSmart)->mtime < $lTimestampLast))
{
if ($bSmart)
{
&log(INFO, 'package dependencies have changed, rebuilding...');
}
executeTest("sudo rm -rf ${strPackagePath}");
}
# Loop through VMs to do the package builds
if (!$bNoPackage) if (!$bNoPackage)
{ {
my $strPackagePath = "${strVagrantPath}/package";
my $strPackageSmart = "${strPackagePath}/build.timestamp";
my @stryPackageSrcPath = ('lib');
# Find the lastest modified time for additional dirs that affect the package build
foreach my $strPackageSrcPath (@stryPackageSrcPath)
{
my $hManifest = $oStorageBackRest->manifest($strPackageSrcPath);
foreach my $strFile (sort(keys(%{$hManifest})))
{
if ($hManifest->{$strFile}{type} eq 'f' && $hManifest->{$strFile}{modification_time} > $lTimestampLast)
{
$lTimestampLast = $hManifest->{$strFile}{modification_time};
}
}
}
# Rebuild if the modification time of the smart file does not equal the last changes in source paths
if ((!$bSmart || !$oStorageBackRest->exists($strPackageSmart) ||
$oStorageBackRest->info($strPackageSmart)->mtime < $lTimestampLast))
{
if ($bSmart)
{
&log(INFO, 'package dependencies have changed, rebuilding...');
}
executeTest("sudo rm -rf ${strPackagePath}");
}
# Loop through VMs to do the package builds
my @stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm); my @stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm);
$oStorageBackRest->pathCreate($strPackagePath, {bIgnoreExists => true, bCreateParent => true}); $oStorageBackRest->pathCreate($strPackagePath, {bIgnoreExists => true, bCreateParent => true});
foreach my $strBuildVM (sort(@stryBuildVm)) foreach my $strBuildVM (@stryBuildVm)
{ {
my $strBuildPath = "${strPackagePath}/${strBuildVM}/src"; my $strBuildPath = "${strPackagePath}/${strBuildVM}/src";
@@ -1325,6 +1398,14 @@ eval
exit 0; exit 0;
} }
# Load the module dynamically
require pgBackRest::LibCAuto;
require pgBackRest::LibC;
pgBackRest::LibC->import(qw(:debug));
require XSLoader;
XSLoader::load('pgBackRest::LibC', '999');
################################################################################################################################ ################################################################################################################################
# Runs tests # Runs tests
################################################################################################################################ ################################################################################################################################

View File

@@ -156,7 +156,8 @@ eval
processBegin("${strVm} test" . (defined($strParam) ? ": ${strParam}" : '')); processBegin("${strVm} test" . (defined($strParam) ? ": ${strParam}" : ''));
executeTest( executeTest(
"${strTestExe} --vm-host=" . VM_U14 . " --vm-max=2 --vm=${strVm}" . (defined($strParam) ? " ${strParam}" : ''), "${strTestExe} --no-gen --no-ci-config --vm-host=" . VM_U14 . " --vm-max=2 --vm=${strVm}" .
(defined($strParam) ? " ${strParam}" : ''),
{bShowOutputAsync => true}); {bShowOutputAsync => true});
processEnd(); processEnd();
} }