[postgis-tickets] r16350 - backport run_test.pl fixes from trunk

Sandro Santilli strk at kbt.io
Mon Jan 22 03:30:28 PST 2018


Author: strk
Date: 2018-01-22 03:30:28 -0800 (Mon, 22 Jan 2018)
New Revision: 16350

Modified:
   branches/2.4/regress/run_test.pl
Log:
backport run_test.pl fixes from trunk

Modified: branches/2.4/regress/run_test.pl
===================================================================
--- branches/2.4/regress/run_test.pl	2018-01-22 11:14:54 UTC (rev 16349)
+++ branches/2.4/regress/run_test.pl	2018-01-22 11:30:28 UTC (rev 16350)
@@ -67,7 +67,7 @@
 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 @@
 	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 @@
 		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 @@
 
 	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 @@
     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 @@
 
     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;



More information about the postgis-tickets mailing list