From 1099cab8d06226eaf0682945e33d3a1444282946 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 22 Jan 2018 11:30:28 +0000 Subject: [PATCH] backport run_test.pl fixes from trunk git-svn-id: http://svn.osgeo.org/postgis/branches/2.4@16350 b70326c6-7e19-0410-871a-916f4a2858ee --- regress/run_test.pl | 77 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/regress/run_test.pl b/regress/run_test.pl index 7de5e8270..9de58cf3b 100755 --- a/regress/run_test.pl +++ b/regress/run_test.pl @@ -67,7 +67,7 @@ my $OPT_EXPECT = 0; my $OPT_EXTENSIONS = 0; my $OPT_EXTVERSION = ''; my $OPT_UPGRADE_PATH = ''; -my $OPT_UPGRADE_FROM = ''; +our $OPT_UPGRADE_FROM = ''; my $OPT_UPGRADE_TO = ''; my $VERBOSE = 0; @@ -258,6 +258,21 @@ if ( ! $libver ) exit(1); } +sub semver_lessthan +{ + my ($a,$b) = @_; + my @acomp = split(/\./, $a); + my @bcomp = split(/\./, $b); + foreach my $ac (@acomp) { + my $bc = shift(@bcomp); + return 0 if not defined($bc); # $b has less components + return 1 if ( $ac < $bc ); # $a is less than $b + return 0 if ( $ac > $bc ); # $a is not less than $b + } + # $a is equal to $b so far, if $b has more elements, + # it is bigger + return @bcomp ? 1 : 0; +} sub create_upgrade_test_objects { @@ -1291,6 +1306,9 @@ sub prepare_spatial_extensions if ( $OPT_UPGRADE_FROM ) { $sql .= " VERSION '" . $OPT_UPGRADE_FROM . "'"; } + + print "Preparing db '${DB}' using: ${sql}\n"; + $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1"; $rv = system($cmd); if ( $rv ) { @@ -1301,16 +1319,27 @@ sub prepare_spatial_extensions if ( $OPT_WITH_SFCGAL ) { - my $sql = "CREATE EXTENSION postgis_sfcgal"; - if ( $OPT_UPGRADE_FROM ) { - $sql .= " VERSION '" . $OPT_UPGRADE_FROM . "'"; - } - $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1"; - $rv = system($cmd); - if ( $rv ) { - fail "Error encountered creating EXTENSION POSTGIS_SFCGAL", $REGRESS_LOG; - die; - } + do { + my $sql = "CREATE EXTENSION postgis_sfcgal"; + if ( $OPT_UPGRADE_FROM ) { + if ( semver_lessthan($OPT_UPGRADE_FROM, "2.2.0") ) + { + print "NOTICE: skipping SFCGAL extension create " + . "as not available in version '$OPT_UPGRADE_FROM'\n"; + last; + } + $sql .= " VERSION '" . $OPT_UPGRADE_FROM . "'"; + } + + print "Preparing db '${DB}' using: ${sql}\n"; + + $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1"; + $rv = system($cmd); + if ( $rv ) { + fail "Error encountered creating EXTENSION POSTGIS_SFCGAL", $REGRESS_LOG; + die; + } + } while (0); } return 1; @@ -1442,6 +1471,13 @@ sub upgrade_spatial_extensions if ( $OPT_WITH_TOPO ) { my $sql = "ALTER EXTENSION postgis_topology UPDATE TO '${nextver}'"; + + if ( $OPT_UPGRADE_FROM eq "unpackaged" ) { + $sql = "CREATE EXTENSION postgis_topology VERSION '${nextver}' FROM unpackaged"; + } + + print "Upgrading PostGIS Topology in '${DB}' using: ${sql}\n" ; + my $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1"; my $rv = system($cmd); if ( $rv ) { @@ -1452,8 +1488,25 @@ sub upgrade_spatial_extensions if ( $OPT_WITH_SFCGAL ) { - my $sql = "ALTER EXTENSION postgis_sfcgal UPDATE TO '${nextver}'"; + my $sql; + + if ( $OPT_UPGRADE_FROM eq "unpackaged" ) { + $sql = "CREATE EXTENSION postgis_sfcgal VERSION '${nextver}' FROM unpackaged"; + } + elsif ( $OPT_UPGRADE_FROM && semver_lessthan($OPT_UPGRADE_FROM, "2.2.0") ) + { + print "NOTICE: installing SFCGAL extension on upgrade " + . "as it was not available in version '$OPT_UPGRADE_FROM'\n"; + $sql = "CREATE EXTENSION postgis_sfcgal VERSION '${nextver}'"; + } + else + { + $sql = "ALTER EXTENSION postgis_sfcgal UPDATE TO '${nextver}'"; + } $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1"; + + print "Upgrading PostGIS SFCGAL in '${DB}' using: ${sql}\n" ; + $rv = system($cmd); if ( $rv ) { fail "Error encountered creating EXTENSION POSTGIS_SFCGAL", $REGRESS_LOG; -- 2.40.0