From: Paul Ramsey Date: Sat, 11 Feb 2012 05:14:39 +0000 (+0000) Subject: Report SVN revision in PostGIS_Full_Version (#1518) X-Git-Tag: 2.0.0alpha5~43 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d7ee7ac970b8a98f5a5a2aab13d77f5fbe129af;p=postgis Report SVN revision in PostGIS_Full_Version (#1518) git-svn-id: http://svn.osgeo.org/postgis/trunk@9155 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/GNUmakefile.in b/GNUmakefile.in index 2fdf77bd4..2e133d56e 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -19,7 +19,7 @@ all install uninstall noop clean distclean check: echo "PostGIS was built successfully. Ready to install."; \ fi -all: +all: postgis_svn_revision.h install: all @@ -178,6 +178,9 @@ authors.git: authors.svn svnrebase: authors.git git svn rebase --authors-file authors.git +postgis_svn_revision.h: .FORCE + $(PERL) utils/svn_repo_revision.pl + .PHONY: utils liblwgeom ChangeLog.svn raster .FORCE: diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 4883cb7d6..75d16ccdc 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -36,6 +36,7 @@ Datum postgis_autocache_bbox(PG_FUNCTION_ARGS); Datum postgis_scripts_released(PG_FUNCTION_ARGS); Datum postgis_version(PG_FUNCTION_ARGS); Datum postgis_lib_version(PG_FUNCTION_ARGS); +Datum postgis_svn_version(PG_FUNCTION_ARGS); Datum postgis_libxml_version(PG_FUNCTION_ARGS); Datum postgis_lib_build_date(PG_FUNCTION_ARGS); Datum LWGEOM_length2d_linestring(PG_FUNCTION_ARGS); @@ -145,6 +146,20 @@ Datum postgis_lib_version(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(result); } +PG_FUNCTION_INFO_V1(postgis_svn_version); +Datum postgis_svn_version(PG_FUNCTION_ARGS) +{ + static int rev = POSTGIS_SVN_REVISION; + char ver[32]; + if ( rev > 0 ) + { + snprintf(ver, 32, "%d", rev); + PG_RETURN_TEXT_P(cstring2text(ver)); + } + else + PG_RETURN_NULL(); +} + PG_FUNCTION_INFO_V1(postgis_lib_build_date); Datum postgis_lib_build_date(PG_FUNCTION_ARGS) { diff --git a/postgis/postgis.sql.in.c b/postgis/postgis.sql.in.c index 5f80804ba..502041406 100644 --- a/postgis/postgis.sql.in.c +++ b/postgis/postgis.sql.in.c @@ -2315,6 +2315,10 @@ CREATE OR REPLACE FUNCTION postgis_geos_version() RETURNS text AS 'MODULE_PATHNAME' LANGUAGE 'C' IMMUTABLE; +CREATE OR REPLACE FUNCTION postgis_svn_version() RETURNS text + AS 'MODULE_PATHNAME' + LANGUAGE 'C' IMMUTABLE; + CREATE OR REPLACE FUNCTION postgis_libxml_version() RETURNS text AS 'MODULE_PATHNAME' LANGUAGE 'C' IMMUTABLE; @@ -2355,6 +2359,7 @@ BEGIN SELECT postgis_uses_stats() INTO usestats; SELECT postgis_scripts_installed() INTO dbproc; SELECT postgis_scripts_released() INTO relproc; + select postgis_svn_version() INTO svnver; fullver = 'POSTGIS="' || libver || '"'; @@ -2373,6 +2378,10 @@ BEGIN IF libxmlver IS NOT NULL THEN fullver = fullver || ' LIBXML="' || libxmlver || '"'; END IF; + + IF svnver IS NOT NULL THEN + fullver = fullver || ' SVN_REVISION=' || svnver; + END IF; IF usestats THEN fullver = fullver || ' USE_STATS'; diff --git a/postgis_config.h.in b/postgis_config.h.in index 59193191d..edf1d08d1 100644 --- a/postgis_config.h.in +++ b/postgis_config.h.in @@ -1,5 +1,7 @@ /* postgis_config.h.in. Generated from configure.ac by autoheader. */ +#include "postgis_svn_revision.h" + /* Define to 1 if translation of program messages to the user's native language is requested. */ #undef ENABLE_NLS diff --git a/utils/svn_repo_revision.pl b/utils/svn_repo_revision.pl index 3c2cfdc0c..46f84332a 100644 --- a/utils/svn_repo_revision.pl +++ b/utils/svn_repo_revision.pl @@ -5,26 +5,30 @@ $ENV{"LC_ALL"} = "C"; use Cwd; my $cwd = &Cwd::cwd(); -my $svn_exe = `which svn`; +my $svn_exe = `which svnn`; -my $target = "local"; +my $svn_revision = 0; +my $defn_string = $defn_string_start . $svn_revision; +my $rev_file = "postgis_svn_revision.h"; $target = $ARGV[0] if $ARGV[0]; # Don't muck with things if you can't find svn if ( ! $svn_exe ) { - if ( ! -f "svnrevision.h" ) { - die "Couldn't find svn exectable or svnrevision.h, cannot continue.\n"; + if ( ! -f $rev_file ) { + &write_defn(0); + exit(0); } else { exit(0); } }; -# Don't muck with thinks if you aren't in an svn repository +# Don't muck with things if you aren't in an svn repository if ( $target eq "local" && ! -d ".svn" ) { - if ( ! -f "svnrevision.h" ) { - die "Couldn't find or generate svnrevision.h, cannot continue.\n"; + if ( ! -f $rev_file ) { + &write_defn(0); + exit(0); } else { exit(0); @@ -40,11 +44,22 @@ if ( $target eq "local" ) { } if ( $svn_info =~ /Last Changed Rev: (\d+)/ ) { - my $rev = $1; - open(OUT,">$cwd/svnrevision.h"); - print OUT "#define SVNREV $rev\n"; - close(OUT); + &write_defn($1); } else { - die "Unable to find revision in svn info\n"; + if ( ! -f $rev_file ) { + &write_defn(0); + exit(0); + } + else { + exit(0); + } +} + +sub write_defn { + my $rev = shift; + my $string = "#define POSTGIS_SVN_REVISION $rev\n"; + open(OUT,">$rev_file"); + print OUT $string; + close(OUT); }