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

Build binaries in the test path rather than the vagrant path.

It makes more sense to build in the test path since many developers won't have a vagrant path. Anyway, it's better not to modify the vagrant path since it belongs to vagrant.

Instead of installing the binary just mount it into the container from where it was built. This saves a bit of time and space.
This commit is contained in:
David Steele
2020-03-15 10:09:27 -04:00
parent 19d975346b
commit d702249507
3 changed files with 29 additions and 64 deletions

View File

@@ -203,14 +203,16 @@ sub run
{
if ($self->{oTest}->{&TEST_VM} ne VM_NONE)
{
my $strBinPath = $self->{strTestPath} . '/bin/' . $self->{oTest}->{&TEST_VM} . '/' . PROJECT_EXE;
executeTest(
'docker run -itd -h ' . $self->{oTest}->{&TEST_VM} . "-test --name=${strImage}" .
" -v ${strHostTestPath}:${strVmTestPath}" .
($self->{oTest}->{&TEST_C} ? " -v $self->{strGCovPath}:$self->{strGCovPath}" : '') .
($self->{oTest}->{&TEST_C} ? " -v $self->{strDataPath}:$self->{strDataPath}" : '') .
" -v $self->{strBackRestBase}:$self->{strBackRestBase} " .
containerRepo() . ':' . $self->{oTest}->{&TEST_VM} .
"-test",
" -v $self->{strBackRestBase}:$self->{strBackRestBase}" .
($self->{oTest}->{&TEST_BIN_REQ} ? " -v ${strBinPath}:${strBinPath}:ro" : '') .
' ' . containerRepo() . ':' . $self->{oTest}->{&TEST_VM} . '-test',
{bSuppressStdErr => true});
}
@@ -232,12 +234,6 @@ sub run
# Build directory has been initialized
$rhBuildInit->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}} = true;
}
# If testing Perl code (or C code that calls the binary) install binary
if ($self->{oTest}->{&TEST_VM} ne VM_NONE && (!$self->{oTest}->{&TEST_C} || $self->{oTest}->{&TEST_BIN_REQ}))
{
jobInstallC($self->{strBackRestBase}, $self->{oTest}->{&TEST_VM}, $strImage);
}
}
}
@@ -379,8 +375,7 @@ sub run
}
# Determine where the project exe is located
my $strProjectExePath = $self->{oTest}->{&TEST_VM} eq VM_NONE ?
"$self->{strBackRestBase}/test/.vagrant/bin/$self->{oTest}->{&TEST_VM}/src/" . PROJECT_EXE : PROJECT_EXE;
my $strProjectExePath = "$self->{strTestPath}/bin/$self->{oTest}->{&TEST_VM}/" . PROJECT_EXE;
# Is this test running in a container?
my $strContainer = $self->{oTest}->{&TEST_VM} eq VM_NONE ? 'false' : 'true';
@@ -784,25 +779,4 @@ sub end
);
}
####################################################################################################################################
# Install C binary
####################################################################################################################################
sub jobInstallC
{
my $strBasePath = shift;
my $strVm = shift;
my $strImage = shift;
my $oVm = vmGet();
my $strBuildPath = "${strBasePath}/test/.vagrant/bin/${strVm}";
my $strBuildBinPath = "${strBuildPath}/src";
executeTest(
"docker exec -i -u root ${strImage} bash -c '" .
"cp ${strBuildBinPath}/" . PROJECT_EXE . ' /usr/bin/' . PROJECT_EXE . ' && ' .
'chmod 755 /usr/bin/' . PROJECT_EXE . "'");
}
push(@EXPORT, qw(jobInstallC));
1;

View File

@@ -66,12 +66,12 @@ sub new
# Create the host
my $strProjectPath = dirname(dirname(abs_path($0)));
my $strBinPath = dirname(dirname($strTestPath)) . '/bin/' . testRunGet()->vm() . '/' . PROJECT_EXE;
my $strContainer = 'test-' . testRunGet()->vmId() . "-$strName";
my $self = $class->SUPER::new(
$strName, $strContainer, $$oParam{strImage}, $$oParam{strUser}, testRunGet()->vm(),
["${strProjectPath}:${strProjectPath}", "${strTestPath}:${strTestPath}"
,dirname(dirname($strTestPath)) . '/cover_db:' . dirname(dirname($strTestPath)) . '/cover_db']);
["${strProjectPath}:${strProjectPath}", "${strTestPath}:${strTestPath}", "${strBinPath}:${strBinPath}:ro"]);
bless $self, $class;
# Set test path
@@ -80,9 +80,6 @@ sub new
# Set permissions on the test path
$self->executeSimple('chown -R ' . $self->userGet() . ':'. TEST_GROUP . ' ' . $self->testPath(), undef, 'root');
# Install bin and Perl C Library
jobInstallC(testRunGet()->basePath(), $self->{strOS}, $strContainer);
# Return from function and log return values if any
return logDebugReturn
(

View File

@@ -719,8 +719,7 @@ eval
{
my $oVm = vmGet();
my $lTimestampLast;
my @stryBinSrcPath = ('src');
my $strBinPath = "${strVagrantPath}/bin";
my $strBinPath = "${strTestPath}/bin";
my $rhBinBuild = {};
# Build the binary
@@ -728,7 +727,7 @@ eval
if ($bBinRequired)
{
# Find the lastest modified time for dirs that affect the bin build
$lTimestampLast = buildLastModTime($oStorageBackRest, $strBackRestBase, \@stryBinSrcPath);
$lTimestampLast = buildLastModTime($oStorageBackRest, $strBackRestBase, ['src']);
# Loop through VMs to do the C bin builds
my $bLogDetail = $strLogLevel eq 'detail';
@@ -742,7 +741,7 @@ eval
foreach my $strBuildVM (@stryBuildVm)
{
my $strBuildPath = "${strBinPath}/${strBuildVM}/src";
my $strBuildPath = "${strBinPath}/${strBuildVM}";
my $bRebuild = !$bSmart;
$rhBinBuild->{$strBuildVM} = true;
@@ -757,9 +756,9 @@ eval
my $strBuildFlagFile = "${strBinPath}/${strBuildVM}/build.flags";
my $bBuildOptionsDiffer = buildPutDiffers($oStorageBackRest, $strBuildFlagFile, $strBuildFlags);
$bBuildOptionsDiffer |= grep(/^src\/configure|src\/Makefile.in|src\/build\.auto\.h$/, @stryModifiedList);
$bBuildOptionsDiffer |= grep(/^src\/configure|src\/Makefile.in|src\/build\.auto\.h\.in$/, @stryModifiedList);
# Rebuild if the modification time of the smart file does equal the last changes in source paths
# Rebuild if the modification time of the bin file is less than the last changes in source paths
my $strBinSmart = "${strBuildPath}/pgbackrest";
if ($bBuildOptionsDiffer ||
@@ -767,7 +766,9 @@ eval
(!$oStorageBackRest->exists($strBinSmart) ||
$oStorageBackRest->info($strBinSmart)->mtime < $lTimestampLast)))
{
&log(INFO, " bin dependencies have changed for ${strBuildVM}, rebuilding...");
&log(
INFO, " bin dependencies have changed for ${strBuildVM}, " . ($bBuildOptionsDiffer ? 're' : '') .
'building...');
$bRebuild = true;
}
@@ -780,32 +781,25 @@ eval
{
executeTest(
"docker run -itd -h test-build --name=test-build" .
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-test",
" -v ${strBackRestBase}:${strBackRestBase} -v ${strTestPath}:${strTestPath} " .
containerRepo() . ":${strBuildVM}-test",
{bSuppressStdErr => true});
}
foreach my $strBinSrcPath (@stryBinSrcPath)
if (!$bSmart || $bBuildOptionsDiffer || !$oStorageBackRest->exists("${strBuildPath}/Makefile"))
{
$oStorageBackRest->pathCreate(
"${strBinPath}/${strBuildVM}/${strBinSrcPath}", {bIgnoreExists => true, bCreateParent => true});
}
# Remove old path if it exists and save the build flags
executeTest("rm -rf ${strBuildPath}");
buildPutDiffers($oStorageBackRest, $strBuildFlagFile, $strBuildFlags);
executeTest(
"rsync -rt" . (!$bSmart || $bBuildOptionsDiffer ? " --delete-excluded" : '') .
" --include=" . join('/*** --include=', @stryBinSrcPath) . '/*** --exclude=*' .
" ${strBackRestBase}/ ${strBinPath}/${strBuildVM}");
buildPutDiffers($oStorageBackRest, $strBuildFlagFile, $strBuildFlags);
if ($bBuildOptionsDiffer || !$oStorageBackRest->exists("${strBuildPath}/Makefile"))
{
executeTest(
($strBuildVM ne VM_NONE ? 'docker exec -i test-build ' : '') .
"bash -c 'cd ${strBuildPath} && ./configure${strConfigOptions}'",
($strBuildVM ne VM_NONE ? 'docker exec -i -u ' . TEST_USER . ' test-build ' : '') .
"bash -c 'cd ${strBuildPath} && ${strBackRestBase}/src/configure${strConfigOptions}'",
{bShowOutputAsync => $bLogDetail});
}
executeTest(
($strBuildVM ne VM_NONE ? 'docker exec -i test-build ' : '') .
($strBuildVM ne VM_NONE ? 'docker exec -i -u ' . TEST_USER . ' test-build ' : '') .
"make -j ${iBuildMax}" . ($bLogDetail ? '' : ' --silent') .
" --directory ${strBuildPath} CFLAGS='${strCFlags}' LDFLAGS='${strLdFlags}'",
{bShowOutputAsync => $bLogDetail});
@@ -863,7 +857,7 @@ eval
#
# Use these commands to create a new patch (may need to modify first line):
# BRDIR=/backrest;BRVM=u18;BRPATCHFILE=${BRDIR?}/test/patch/debian-package.patch
# DBDIR=${BRDIR?}/test/.vagrant/package/${BRVM}/src/debian
# DBDIR=${BRDIR?}/test/result/package/${BRVM}/debian
# diff -Naur ${DBDIR?}.old ${DBDIR}.new > ${BRPATCHFILE?}
my $strDebianPackagePatch = "${strBackRestBase}/test/patch/debian-package.patch";
@@ -969,7 +963,7 @@ eval
#
# Use these commands to create a new patch (may need to modify first line):
# BRDIR=/backrest;BRVM=co7;BRPATCHFILE=${BRDIR?}/test/patch/rhel-package.patch
# PKDIR=${BRDIR?}/test/.vagrant/package/${BRVM}/src/SPECS
# PKDIR=${BRDIR?}/test/result/package/${BRVM}/SPECS
# diff -Naur ${PKDIR?}.old ${PKDIR}.new > ${BRPATCHFILE?}
my $strPackagePatch = "${strBackRestBase}/test/patch/rhel-package.patch";
@@ -1301,8 +1295,8 @@ eval
$strVm, $iVmId, # Vm info
$strBackRestBase, # Base backrest directory
$strTestPath, # Path where the tests will run
'/usr/bin/' . PROJECT_EXE, # Path to the backrest executable
"${strVagrantPath}/bin/" . VM_NONE . '/src/' . PROJECT_EXE, # Path to the backrest Perl storage helper
dirname($strTestPath) . "/bin/${strVm}/" . PROJECT_EXE, # Path to the pgbackrest binary
dirname($strTestPath) . "/bin/" . VM_NONE . '/' . PROJECT_EXE, # Path to the backrest Perl storage helper
$strPgVersion ne 'minimal' ? $strPgSqlBin: undef, # Pg bin path
$strPgVersion ne 'minimal' ? $strPgVersion: undef, # Pg version
$stryModule[0], $stryModuleTest[0], \@iyModuleTestRun, # Module info