Windows build broken starting at da9b580d89903fee871cf54845ffa2b26bda2e11

From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Hao Lee <mixtrue(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Subject: Windows build broken starting at da9b580d89903fee871cf54845ffa2b26bda2e11
Date: 2018-05-15 15:33:26
Message-ID: BF04A27A-D132-4927-A80A-BAD18695E954@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

There was a bug report sent by Hao Lee about Windows build breakage,
"BUG #15167: error C2365: 'errcode' : redefinition; previous definition"
https://www.postgresql.org/message-id/152446498404.19807.4659286570762153837%40wrigleys.postgresql.org

Heikki was the only person who responded to Hao, AFAIK, though that
conversation did not go far. Perhaps Heikki was unable to reproduce?

Hao did not specify which commit caused the problem, so I started
bisecting to find out.

With my Windows build setup, building from master, the builds break
staring with da9b580d89903fee871cf54845ffa2b26bda2e11 committed by
Stephen on Apr 7 2018.

Build FAILED.

"D:\jenkins\workspace\trunk\dist\msi\BUILD\postgresql\pgsql.sln" (default target) (1) ->
(postgres target) ->
.\src\backend\replication\basebackup.c(1470): warning C4146: unary minus operator applied to unsigned type, result still unsigned

"D:\jenkins\workspace\trunk\dist\msi\BUILD\postgresql\pgsql.sln" (default target) (1) ->
(postgres target) ->
.\src\common\file_perm.c(18): error C2065: 'S_IRWXU' : undeclared identifier
.\src\common\file_perm.c(18): error C2099: initializer is not a constant
.\src\common\file_perm.c(19): error C2065: 'S_IRUSR' : undeclared identifier
.\src\common\file_perm.c(19): error C2065: 'S_IWUSR' : undeclared identifier
.\src\common\file_perm.c(19): error C2099: initializer is not a constant

The build breaks in a different way staring with
c37b3d08ca6873f9d4eaf24c72a90a550970cbb8 committed by Stephen later
that same day.

Microsoft (R) Build Engine Version 3.5.30729.5420
[Microsoft .NET Framework, Version 2.0.50727.8784]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 5/15/2018 5:24:08 AM.
Project "D:\jenkins\workspace\trunk\dist\msi\BUILD\postgresql\pgsql.sln" on node 0 (default targets).
Building solution configuration "Release|x64".
<http://aws-pmc-build-w2k8.int.port25.com:8282/job/trunk/ws/dist/msi/build/postgresql/src/include/utils/elog.h(131)>: error C2365: 'errcode' : redefinition; previous definition was 'typedef'
Done Building Project "D:\jenkins\workspace\trunk\dist\msi\BUILD\postgresql\pgsql.sln" (default targets) -- FAILED.

Build FAILED.

Since I am able to reproduce the problem, I'd like to help debug the
problem. I find it frustrating that the compiler is not specifying
*where* the prior typedef comes from.

My best guess at the moment is:

diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index c1f0441b08..0a3163398f 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -16,8 +16,11 @@
*
*-------------------------------------------------------------------------
*/
+#include <sys/stat.h>
+
#include "postgres.h"

+#include "common/file_perm.h"
#include "libpq/libpq-be.h"
#include "libpq/pqcomm.h"
#include "miscadmin.h"

Which makes me wonder if <sys/stat.h> on Windows declares a typedef for errcode?
The work-around in src/include/port/win32.h which attempts to deal with system
headers defining errcode looks like it won't work unless it gets included *before*
the offending system header, which appears not to be true for globals.c.

Indeed, the following change (shown here for illustrative purposes only; please
don't commit it this way) fixes the problem, at least in my build environment:

diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 9f1209323a..1622b0be62 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -16,7 +16,14 @@
*
*-------------------------------------------------------------------------
*/
+
+#if defined(_WIN32) || defined(WIN32) || defined(_MSC_VER) || defined(HAVE_CRTDEFS_H)
+#define errcode __msvc_errcode
+#include <sys/stat.h>
+#undef errcode
+#else
#include <sys/stat.h>
+#endif

#include "postgres.h"

Let me know if there are any tests you'd like me to perform to further
investigate.

mark

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Isaac Morland 2018-05-15 15:52:54 Re: Allow COPY's 'text' format to output a header
Previous Message Nikita Glukhov 2018-05-15 14:59:56 [BUGFIX] amcanbackward is not checked before building backward index paths