On Wed, Mar 9, 2016 at 1:07 AM, Andrew Dunstan <and...@dunslane.net> wrote: > Michael's patch proposes to replace the use of sed to generate probes.h with > the perl equivalent everywhere. That has the advantage that we keep to one > script to generate probes.h, but it does impose a perl dependency.
Good point. It did not occur to me that this would bring a hard dependency for non-Windows builds. Let's keep both scripts then. The attached is changed to do so. -- Michael
From d7a100dae8816ff1287ae0eee2829d2b7ce6ef47 Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@otacoo.com> Date: Tue, 8 Mar 2016 22:18:16 +0900 Subject: [PATCH 1/4] Remove dependency to psed in MSVC scripts psed has been removed from the core distribution of perl in 5.22, causing the build of Postgres to fail in the case of MSVC on Windows should at least this version of perl be used. This commit replaces the dependency with psed by an equivalent perl script, the non-MSVC build use this script as well instead of the former sed script when dtrace is not enabled in a build. --- src/backend/utils/Gen_dummy_probes.pl | 247 +++++++++++++++++++++++++++++++++ src/backend/utils/Gen_dummy_probes.sed | 23 --- src/backend/utils/Makefile | 4 +- src/tools/msvc/Solution.pm | 2 +- 4 files changed, 250 insertions(+), 26 deletions(-) create mode 100644 src/backend/utils/Gen_dummy_probes.pl delete mode 100644 src/backend/utils/Gen_dummy_probes.sed diff --git a/src/backend/utils/Gen_dummy_probes.pl b/src/backend/utils/Gen_dummy_probes.pl new file mode 100644 index 0000000..30c6d65 --- /dev/null +++ b/src/backend/utils/Gen_dummy_probes.pl @@ -0,0 +1,247 @@ +#! /usr/bin/perl -w +#------------------------------------------------------------------------- +# +# Gen_dummy_probes.pl +# Perl script that generates probes.h file when dtrace is not available +# +# Portions Copyright (c) 2008-2016, PostgreSQL Global Development Group +# +# +# IDENTIFICATION +# src/backend/utils/Gen_dummy_probes.pl +# +#------------------------------------------------------------------------- + +$0 =~ s/^.*?(\w+)[\.\w+]*$/$1/; + +use strict; +use Symbol; +use vars qw{ $isEOF $Hold %wFiles @Q $CondReg + $doAutoPrint $doOpenWrite $doPrint }; +$doAutoPrint = 1; +$doOpenWrite = 1; + +# prototypes +sub openARGV(); +sub getsARGV(;\$); +sub eofARGV(); +sub printQ(); + +# Run: the sed loop reading input and applying the script +# +sub Run() +{ + my ($h, $icnt, $s, $n); + + # hack (not unbreakable :-/) to avoid // matching an empty string + my $z = "\000"; + $z =~ /$z/; + + # Initialize. + openARGV(); + $Hold = ''; + $CondReg = 0; + $doPrint = $doAutoPrint; + CYCLE: + while (getsARGV()) + { + chomp(); + $CondReg = 0; # cleared on t + BOS:; + + # /^[ ]*probe /!d + unless (m /^[ \t]*probe /s) + { + $doPrint = 0; + goto EOS; + } + + # s/^[ ]*probe \([^(]*\)\(.*\);/\1\2/ + { + $s = s /^[ \t]*probe ([^(]*)(.*);/${1}${2}/s; + $CondReg ||= $s; + } + + # s/__/_/g + { + $s = s /__/_/sg; + $CondReg ||= $s; + } + + # y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ + { y{abcdefghijklmnopqrstuvwxyz}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}; } + + # s/^/#define TRACE_POSTGRESQL_/ + { + $s = s /^/#define TRACE_POSTGRESQL_/s; + $CondReg ||= $s; + } + + # s/([^,)]\{1,\})/(INT1)/ + { + $s = s /\([^,)]+\)/(INT1)/s; + $CondReg ||= $s; + } + + # s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/ + { + $s = s /\([^,)]+, [^,)]+\)/(INT1, INT2)/s; + $CondReg ||= $s; + } + + # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/ + { + $s = s /\([^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3)/s; + $CondReg ||= $s; + } + +# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/ + { + $s = +s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4)/s; + $CondReg ||= $s; + } + +# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/ + { + $s = +s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5)/s; + $CondReg ||= $s; + } + +# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/ + { + $s = +s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6)/s; + $CondReg ||= $s; + } + +# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/ + { + $s = +s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/s; + $CondReg ||= $s; + } + +# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/ + { + $s = +s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/s; + $CondReg ||= $s; + } + + # P + { + if (/^(.*)/) { print $1, "\n"; } + } + + # s/(.*$/_ENABLED() (0)/ + { + $s = s /\(.*$/_ENABLED() (0)/s; + $CondReg ||= $s; + } + EOS: if ($doPrint) + { + print $_, "\n"; + } + else + { + $doPrint = $doAutoPrint; + } + printQ() if @Q; + } + + exit(0); +} +Run(); + +# openARGV: open 1st input file +# +sub openARGV() +{ + unshift(@ARGV, '-') unless @ARGV; + my $file = shift(@ARGV); + open(ARG, "<$file") + || die("$0: can't open $file for reading ($!)\n"); + $isEOF = 0; +} + +# getsARGV: Read another input line into argument (default: $_). +# Move on to next input file, and reset EOF flag $isEOF. +sub getsARGV(;\$) +{ + my $argref = @_ ? shift() : \$_; + while ($isEOF || !defined($$argref = <ARG>)) + { + close(ARG); + return 0 unless @ARGV; + my $file = shift(@ARGV); + open(ARG, "<$file") + || die("$0: can't open $file for reading ($!)\n"); + $isEOF = 0; + } + 1; +} + +# eofARGV: end-of-file test +# +sub eofARGV() +{ + return @ARGV == 0 && ($isEOF = eof(ARG)); +} + +# makeHandle: Generates another file handle for some file (given by its path) +# to be written due to a w command or an s command's w flag. +sub makeHandle($) +{ + my ($path) = @_; + my $handle; + if (!exists($wFiles{$path}) || $wFiles{$path} eq '') + { + $handle = $wFiles{$path} = gensym(); + if ($doOpenWrite) + { + if (!open($handle, ">$path")) + { + die("$0: can't open $path for writing: ($!)\n"); + } + } + } + else + { + $handle = $wFiles{$path}; + } + return $handle; +} + +# printQ: Print queued output which is either a string or a reference +# to a pathname. +sub printQ() +{ + for my $q (@Q) + { + if (ref($q)) + { + # flush open w files so that reading this file gets it all + if (exists($wFiles{$$q}) && $wFiles{$$q} ne '') + { + open($wFiles{$$q}, ">>$$q"); + } + + # copy file to stdout: slow, but safe + if (open(RF, "<$$q")) + { + while (defined(my $line = <RF>)) + { + print $line; + } + close(RF); + } + } + else + { + print $q; + } + } + undef(@Q); +} diff --git a/src/backend/utils/Gen_dummy_probes.sed b/src/backend/utils/Gen_dummy_probes.sed deleted file mode 100644 index 5a79fdb..0000000 --- a/src/backend/utils/Gen_dummy_probes.sed +++ /dev/null @@ -1,23 +0,0 @@ -#------------------------------------------------------------------------- -# sed script to create dummy probes.h file when dtrace is not available -# -# Copyright (c) 2008-2016, PostgreSQL Global Development Group -# -# src/backend/utils/Gen_dummy_probes.sed -#------------------------------------------------------------------------- - -/^[ ]*probe /!d -s/^[ ]*probe \([^(]*\)\(.*\);/\1\2/ -s/__/_/g -y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ -s/^/#define TRACE_POSTGRESQL_/ -s/([^,)]\{1,\})/(INT1)/ -s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/ -s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/ -s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/ -s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/ -s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/ -s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/ -s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/ -P -s/(.*$/_ENABLED() (0)/ diff --git a/src/backend/utils/Makefile b/src/backend/utils/Makefile index 8374533..43fa255 100644 --- a/src/backend/utils/Makefile +++ b/src/backend/utils/Makefile @@ -30,7 +30,7 @@ errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl $(PERL) $(srcdir)/generate-errcodes.pl $< > $@ ifneq ($(enable_dtrace), yes) -probes.h: Gen_dummy_probes.sed +probes.h: Gen_dummy_probes.pl endif probes.h: probes.d @@ -39,7 +39,7 @@ ifeq ($(enable_dtrace), yes) sed -e 's/POSTGRESQL_/TRACE_POSTGRESQL_/g' $@.tmp >$@ rm $@.tmp else - sed -f $(srcdir)/Gen_dummy_probes.sed $< >$@ + $(PERL) $(srcdir)/Gen_dummy_probes.pl $< > $@ endif diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index c5a43f9..60bcd7e 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -313,7 +313,7 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY { print "Generating probes.h...\n"; system( -'psed -f src/backend/utils/Gen_dummy_probes.sed src/backend/utils/probes.d > src/include/utils/probes.h' +'perl src/backend/utils/Gen_dummy_probes.pl src/backend/utils/probes.d > src/include/utils/probes.h' ); } -- 2.7.2
From 5cc3b19e32e7d975d75b301c2b289de9a6655c78 Mon Sep 17 00:00:00 2001 From: John Doe <john@example.com> Date: Fri, 4 Mar 2016 21:38:24 -0800 Subject: [PATCH 2/4] Fix declaration of TIMEZONE_GLOBAL and TZNAME_GLOBAL for WIN32 When compiling the code with WIN32, those two variables were declared as timezone and tzname, while the objects present for MSVC are _timezone and _tzname. --- src/include/port.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/port.h b/src/include/port.h index cb13dd8..455f723 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -214,12 +214,12 @@ extern int pgkill(int pid, int sig); extern int pclose_check(FILE *stream); /* Global variable holding time zone information. */ -#ifndef __CYGWIN__ -#define TIMEZONE_GLOBAL timezone -#define TZNAME_GLOBAL tzname -#else +#if defined(WIN32) || defined(__CYGWIN__) #define TIMEZONE_GLOBAL _timezone #define TZNAME_GLOBAL _tzname +#else +#define TIMEZONE_GLOBAL timezone +#define TZNAME_GLOBAL tzname #endif #if defined(WIN32) || defined(__CYGWIN__) -- 2.7.2
From 73c39b3ab63bead87b77a02eed3f01194a95bb50 Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@otacoo.com> Date: Fri, 4 Mar 2016 23:10:04 +0900 Subject: [PATCH 3/4] Fix use of locales for VS 2015 lc_codepage is a flag missing from locale.h, causing this code path introduced in VS 2012 to fail. Perhaps there is a reason for this field to have been clobbered, but let's fall back to the pre-VS-2012 code parsing directly LC_TYPE to get the codepage wanted. --- src/port/chklocale.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/port/chklocale.c b/src/port/chklocale.c index a551fdc..a7d88fb 100644 --- a/src/port/chklocale.c +++ b/src/port/chklocale.c @@ -203,7 +203,16 @@ win32_langinfo(const char *ctype) { char *r = NULL; -#if (_MSC_VER >= 1700) + /* + * lc_codepage is correctly declared in Visual Studio 2012 and 2013. + * However in VS 2015 this flag is missing from locale.h, visibly this + * is an error of refactoring from Microsoft that is at the origin of + * this missing field, causing a compilation failure in this code path. + * Hence, it is more reliable to fall back to other code path grabbing + * the codepage from the ctype name itself. If VS gets back this field + * in the future, we may want to relax the use of _create_locale here. + */ +#if (_MSC_VER >= 1700) && (_MSC_VER <= 1800) _locale_t loct = NULL; loct = _create_locale(LC_CTYPE, ctype); -- 2.7.2
From 5a0d172b0679b426230174fc8452dd775fd0f226 Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@otacoo.com> Date: Fri, 4 Mar 2016 15:25:55 +0900 Subject: [PATCH 4/4] Add support for VS 2015 in MSVC scripts One can use that to compile with the latest version of Visual Studio on Windows. --- doc/src/sgml/install-windows.sgml | 8 ++++---- src/tools/msvc/MSBuildProject.pm | 23 +++++++++++++++++++++++ src/tools/msvc/Solution.pm | 26 ++++++++++++++++++++++++++ src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++-- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml index f08cca7..148180b 100644 --- a/doc/src/sgml/install-windows.sgml +++ b/doc/src/sgml/install-windows.sgml @@ -19,10 +19,10 @@ <para> There are several different ways of building PostgreSQL on <productname>Windows</productname>. The simplest way to build with - Microsoft tools is to install <productname>Visual Studio Express 2013 + Microsoft tools is to install <productname>Visual Studio Express 2015 for Windows Desktop</productname> and use the included compiler. It is also possible to build with the full - <productname>Microsoft Visual C++ 2005 to 2013</productname>. + <productname>Microsoft Visual C++ 2005 to 2015</productname>. In some cases that requires the installation of the <productname>Windows SDK</productname> in addition to the compiler. </para> @@ -77,7 +77,7 @@ <productname>Visual Studio Express</productname> or some versions of the <productname>Microsoft Windows SDK</productname>. If you do not already have a <productname>Visual Studio</productname> environment set up, the easiest - ways are to use the compilers from <productname>Visual Studio Express 2013 + ways are to use the compilers from <productname>Visual Studio Express 2015 for Windows Desktop</productname> or those in the <productname>Windows SDK 7.1</productname>, which are both free downloads from Microsoft. </para> @@ -85,7 +85,7 @@ <para> PostgreSQL is known to support compilation using the compilers shipped with <productname>Visual Studio 2005</productname> to - <productname>Visual Studio 2013</productname> (including Express editions), + <productname>Visual Studio 2015</productname> (including Express editions), as well as standalone Windows SDK releases 6.0 to 7.1. 64-bit PostgreSQL builds are only supported with <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm index 3d60b64..d7638b4 100644 --- a/src/tools/msvc/MSBuildProject.pm +++ b/src/tools/msvc/MSBuildProject.pm @@ -465,4 +465,27 @@ sub new return $self; } +package VC2015Project; + +# +# Package that encapsulates a Visual C++ 2015 project file +# + +use strict; +use warnings; +use base qw(VC2012Project); + +sub new +{ + my $classname = shift; + my $self = $classname->SUPER::_new(@_); + bless($self, $classname); + + $self->{vcver} = '14.00'; + $self->{PlatformToolset} = 'v140'; + $self->{ToolsVersion} = '14.0'; + + return $self; +} + 1; diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 60bcd7e..1181a03 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -779,6 +779,32 @@ sub new return $self; } +package VS2015Solution; + +# +# Package that encapsulates a Visual Studio 2015 solution file +# + +use Carp; +use strict; +use warnings; +use base qw(Solution); + +sub new +{ + my $classname = shift; + my $self = $classname->SUPER::_new(@_); + bless($self, $classname); + + $self->{solutionFileVersion} = '14.00'; + $self->{vcver} = '14.00'; + $self->{visualStudioName} = 'Visual Studio 2015'; + $self->{VisualStudioVersion} = '14.0.24730.2'; + $self->{MinimumVisualStudioVersion} = '10.0.40219.1'; + + return $self; +} + sub GetAdditionalHeaders { my ($self, $f) = @_; diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm index fee4684..4190ada 100644 --- a/src/tools/msvc/VSObjectFactory.pm +++ b/src/tools/msvc/VSObjectFactory.pm @@ -49,6 +49,10 @@ sub CreateSolution { return new VS2013Solution(@_); } + elsif ($visualStudioVersion eq '14.00') + { + return new VS2015Solution(@_); + } else { croak "The requested Visual Studio version is not supported."; @@ -84,6 +88,10 @@ sub CreateProject { return new VC2013Project(@_); } + elsif ($visualStudioVersion eq '14.00') + { + return new VC2015Project(@_); + } else { croak "The requested Visual Studio version is not supported."; @@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion sub _GetVisualStudioVersion { my ($major, $minor) = @_; - if ($major > 12) + if ($major > 14) { carp "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead."; - return '12.00'; + return '14.00'; } elsif ($major < 6) { -- 2.7.2
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers