Commit b8cc8f94 authored by Tom Lane's avatar Tom Lane

Support BSD and e2fsprogs UUID libraries alongside OSSP UUID library.

Allow the contrib/uuid-ossp extension to be built atop any one of these
three popular UUID libraries.  (The extension's name is now arguably a
misnomer, but we'll keep it the same so as not to cause unnecessary
compatibility issues for users.)

We would not normally consider a change like this post-beta1, but the issue
has been forced by our upgrade to autoconf 2.69, whose more rigorous header
checks are causing OSSP's header files to be rejected on some platforms.
It's been foreseen for some time that we'd have to move away from depending
on OSSP UUID due to lack of upstream maintenance, so this is a down payment
on that problem.

While at it, add some simple regression tests, in hopes of catching any
major incompatibilities between the three implementations.

Matteo Beccati, with some further hacking by me
parent 616afee1
This diff is collapsed.
...@@ -694,10 +694,38 @@ PGAC_ARG_BOOL(with, libedit-preferred, no, ...@@ -694,10 +694,38 @@ PGAC_ARG_BOOL(with, libedit-preferred, no,
# #
# OSSP UUID library # UUID library
# #
PGAC_ARG_BOOL(with, ossp-uuid, no, [build contrib/uuid-ossp, requires OSSP UUID library]) # There are at least three UUID libraries in common use: the FreeBSD/NetBSD
AC_SUBST(with_ossp_uuid) # library, the e2fsprogs libuuid (now part of util-linux-ng), and the OSSP
# UUID library. More than one of these might be present on a given platform,
# so we make the user say which one she wants.
#
PGAC_ARG_REQ(with, uuid, [LIB], [build contrib/uuid-ossp using LIB (bsd,e2fs,ossp)])
if test x"$with_uuid" = x"" ; then
with_uuid=no
fi
PGAC_ARG_BOOL(with, ossp-uuid, no, [obsolete spelling of --with-uuid=ossp])
if test "$with_ossp_uuid" = yes ; then
with_uuid=ossp
fi
if test "$with_uuid" = bsd ; then
AC_DEFINE([HAVE_UUID_BSD], 1, [Define to 1 if you have BSD UUID support.])
UUID_EXTRA_OBJS="md5.o sha1.o"
elif test "$with_uuid" = e2fs ; then
AC_DEFINE([HAVE_UUID_E2FS], 1, [Define to 1 if you have E2FS UUID support.])
UUID_EXTRA_OBJS="md5.o sha1.o"
elif test "$with_uuid" = ossp ; then
AC_DEFINE([HAVE_UUID_OSSP], 1, [Define to 1 if you have OSSP UUID support.])
UUID_EXTRA_OBJS=""
elif test "$with_uuid" = no ; then
UUID_EXTRA_OBJS=""
else
AC_MSG_ERROR([--with-uuid must specify one of bsd, e2fs, or ossp])
fi
AC_SUBST(with_uuid)
AC_SUBST(UUID_EXTRA_OBJS)
# #
...@@ -948,14 +976,26 @@ if test "$with_selinux" = yes; then ...@@ -948,14 +976,26 @@ if test "$with_selinux" = yes; then
fi fi
# for contrib/uuid-ossp # for contrib/uuid-ossp
if test "$with_ossp_uuid" = yes ; then if test "$with_uuid" = bsd ; then
# On BSD, the UUID functions are in libc
AC_CHECK_FUNC(uuid_to_string,
[UUID_LIBS=""],
[AC_MSG_ERROR([BSD UUID functions are not present])])
elif test "$with_uuid" = e2fs ; then
# On OS X, the UUID functions are in libc
AC_CHECK_FUNC(uuid_generate,
[UUID_LIBS=""],
[AC_CHECK_LIB(uuid, uuid_generate,
[UUID_LIBS="-luuid"],
[AC_MSG_ERROR([library 'uuid' is required for E2FS UUID])])])
elif test "$with_uuid" = ossp ; then
AC_CHECK_LIB(ossp-uuid, uuid_export, AC_CHECK_LIB(ossp-uuid, uuid_export,
[OSSP_UUID_LIBS="-lossp-uuid"], [UUID_LIBS="-lossp-uuid"],
[AC_CHECK_LIB(uuid, uuid_export, [AC_CHECK_LIB(uuid, uuid_export,
[OSSP_UUID_LIBS="-luuid"], [UUID_LIBS="-luuid"],
[AC_MSG_ERROR([library 'ossp-uuid' or 'uuid' is required for OSSP-UUID])])]) [AC_MSG_ERROR([library 'ossp-uuid' or 'uuid' is required for OSSP UUID])])])
fi fi
AC_SUBST(OSSP_UUID_LIBS) AC_SUBST(UUID_LIBS)
## ##
...@@ -1075,10 +1115,27 @@ if test "$with_bonjour" = yes ; then ...@@ -1075,10 +1115,27 @@ if test "$with_bonjour" = yes ; then
fi fi
# for contrib/uuid-ossp # for contrib/uuid-ossp
if test "$with_ossp_uuid" = yes ; then if test "$with_uuid" = bsd ; then
AC_CHECK_HEADERS(ossp/uuid.h, [], [ AC_CHECK_HEADERS(uuid.h,
AC_CHECK_HEADERS(uuid.h, [], [AC_EGREP_HEADER([uuid_to_string], uuid.h, [],
[AC_MSG_ERROR([header file <ossp/uuid.h> or <uuid.h> is required for OSSP-UUID])])]) [AC_MSG_ERROR([header file <uuid.h> does not match BSD UUID library])])],
[AC_MSG_ERROR([header file <uuid.h> is required for BSD UUID])])
elif test "$with_uuid" = e2fs ; then
AC_CHECK_HEADERS(uuid/uuid.h,
[AC_EGREP_HEADER([uuid_generate], uuid/uuid.h, [],
[AC_MSG_ERROR([header file <uuid/uuid.h> does not match E2FS UUID library])])],
[AC_CHECK_HEADERS(uuid.h,
[AC_EGREP_HEADER([uuid_generate], uuid.h, [],
[AC_MSG_ERROR([header file <uuid.h> does not match E2FS UUID library])])],
[AC_MSG_ERROR([header file <uuid/uuid.h> or <uuid.h> is required for E2FS UUID])])])
elif test "$with_uuid" = ossp ; then
AC_CHECK_HEADERS(ossp/uuid.h,
[AC_EGREP_HEADER([uuid_export], ossp/uuid.h, [],
[AC_MSG_ERROR([header file <ossp/uuid.h> does not match OSSP UUID library])])],
[AC_CHECK_HEADERS(uuid.h,
[AC_EGREP_HEADER([uuid_export], uuid.h, [],
[AC_MSG_ERROR([header file <uuid.h> does not match OSSP UUID library])])],
[AC_MSG_ERROR([header file <ossp/uuid.h> or <uuid.h> is required for OSSP UUID])])])
fi fi
if test "$PORTNAME" = "win32" ; then if test "$PORTNAME" = "win32" ; then
......
...@@ -64,7 +64,7 @@ else ...@@ -64,7 +64,7 @@ else
ALWAYS_SUBDIRS += sslinfo ALWAYS_SUBDIRS += sslinfo
endif endif
ifeq ($(with_ossp_uuid),yes) ifneq ($(with_uuid),no)
SUBDIRS += uuid-ossp SUBDIRS += uuid-ossp
else else
ALWAYS_SUBDIRS += uuid-ossp ALWAYS_SUBDIRS += uuid-ossp
......
/md5.c
/sha1.c
# Generated subdirectories
/log/
/results/
/tmp_check/
# contrib/uuid-ossp/Makefile # contrib/uuid-ossp/Makefile
MODULE_big = uuid-ossp MODULE_big = uuid-ossp
OBJS = uuid-ossp.o OBJS = uuid-ossp.o $(UUID_EXTRA_OBJS)
EXTENSION = uuid-ossp EXTENSION = uuid-ossp
DATA = uuid-ossp--1.0.sql uuid-ossp--unpackaged--1.0.sql DATA = uuid-ossp--1.0.sql uuid-ossp--unpackaged--1.0.sql
SHLIB_LINK += $(OSSP_UUID_LIBS) REGRESS = uuid_ossp
SHLIB_LINK += $(UUID_LIBS)
# We copy some needed files verbatim from pgcrypto
pgcrypto_src = $(top_srcdir)/contrib/pgcrypto
PG_CPPFLAGS = -I$(pgcrypto_src)
EXTRA_CLEAN = md5.c sha1.c
ifdef USE_PGXS ifdef USE_PGXS
PG_CONFIG = pg_config PG_CONFIG = pg_config
...@@ -18,3 +27,6 @@ top_builddir = ../.. ...@@ -18,3 +27,6 @@ top_builddir = ../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk include $(top_srcdir)/contrib/contrib-global.mk
endif endif
md5.c sha1.c: % : $(pgcrypto_src)/%
rm -f $@ && $(LN_S) $< .
CREATE EXTENSION "uuid-ossp";
SELECT uuid_nil();
uuid_nil
--------------------------------------
00000000-0000-0000-0000-000000000000
(1 row)
SELECT uuid_ns_dns();
uuid_ns_dns
--------------------------------------
6ba7b810-9dad-11d1-80b4-00c04fd430c8
(1 row)
SELECT uuid_ns_url();
uuid_ns_url
--------------------------------------
6ba7b811-9dad-11d1-80b4-00c04fd430c8
(1 row)
SELECT uuid_ns_oid();
uuid_ns_oid
--------------------------------------
6ba7b812-9dad-11d1-80b4-00c04fd430c8
(1 row)
SELECT uuid_ns_x500();
uuid_ns_x500
--------------------------------------
6ba7b814-9dad-11d1-80b4-00c04fd430c8
(1 row)
SELECT uuid_generate_v1() < uuid_generate_v1();
?column?
----------
t
(1 row)
SELECT uuid_generate_v1() < uuid_generate_v1mc();
?column?
----------
t
(1 row)
SELECT substr(uuid_generate_v1()::text, 25) = substr(uuid_generate_v1()::text, 25);
?column?
----------
t
(1 row)
SELECT substr(uuid_generate_v1()::text, 25) <> substr(uuid_generate_v1mc()::text, 25);
?column?
----------
t
(1 row)
SELECT substr(uuid_generate_v1mc()::text, 25) <> substr(uuid_generate_v1mc()::text, 25);
?column?
----------
t
(1 row)
SELECT ('x' || substr(uuid_generate_v1mc()::text, 25, 2))::bit(8) & '00000011';
?column?
----------
00000011
(1 row)
SELECT uuid_generate_v3(uuid_ns_dns(), 'www.widgets.com');
uuid_generate_v3
--------------------------------------
3d813cbb-47fb-32ba-91df-831e1593ac29
(1 row)
SELECT uuid_generate_v5(uuid_ns_dns(), 'www.widgets.com');
uuid_generate_v5
--------------------------------------
21f7f8de-8051-5b89-8680-0195ef798b6a
(1 row)
SELECT uuid_generate_v4()::text ~ '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$';
?column?
----------
t
(1 row)
SELECT uuid_generate_v4() <> uuid_generate_v4();
?column?
----------
t
(1 row)
CREATE EXTENSION "uuid-ossp";
SELECT uuid_nil();
SELECT uuid_ns_dns();
SELECT uuid_ns_url();
SELECT uuid_ns_oid();
SELECT uuid_ns_x500();
SELECT uuid_generate_v1() < uuid_generate_v1();
SELECT uuid_generate_v1() < uuid_generate_v1mc();
SELECT substr(uuid_generate_v1()::text, 25) = substr(uuid_generate_v1()::text, 25);
SELECT substr(uuid_generate_v1()::text, 25) <> substr(uuid_generate_v1mc()::text, 25);
SELECT substr(uuid_generate_v1mc()::text, 25) <> substr(uuid_generate_v1mc()::text, 25);
SELECT ('x' || substr(uuid_generate_v1mc()::text, 25, 2))::bit(8) & '00000011';
SELECT uuid_generate_v3(uuid_ns_dns(), 'www.widgets.com');
SELECT uuid_generate_v5(uuid_ns_dns(), 'www.widgets.com');
SELECT uuid_generate_v4()::text ~ '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$';
SELECT uuid_generate_v4() <> uuid_generate_v4();
This diff is collapsed.
...@@ -869,17 +869,46 @@ su - postgres ...@@ -869,17 +869,46 @@ su - postgres
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--with-uuid=<replaceable>LIBRARY</replaceable></option></term>
<listitem>
<para>
Build the <![%standalone-include[uuid-ossp]]>
<![%standalone-ignore[<xref linkend="uuid-ossp">]]> module
(which provides functions to generate UUIDs), using the specified
UUID library.<indexterm><primary>UUID</primary></indexterm>
<replaceable>LIBRARY</replaceable> must be one of:
</para>
<itemizedlist>
<listitem>
<para>
<option>bsd</> to use the UUID functions found in FreeBSD, NetBSD,
and some other BSD-derived systems
</para>
</listitem>
<listitem>
<para>
<option>e2fs</> to use the UUID library created by
the <literal>e2fsprogs</> project; this library is present in most
Linux systems and in Mac OS X, and can be obtained for other
platforms as well
</para>
</listitem>
<listitem>
<para>
<option>ossp</> to use the <ulink
url="http://www.ossp.org/pkg/lib/uuid/">OSSP UUID library</ulink>
</para>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--with-ossp-uuid</option></term> <term><option>--with-ossp-uuid</option></term>
<listitem> <listitem>
<para> <para>
Build components using the <ulink Obsolete equivalent of <literal>--with-uuid=ossp</literal>.
url="http://www.ossp.org/pkg/lib/uuid/">OSSP UUID
library</ulink>. Specifically, build the
<![%standalone-include[uuid-ossp]]>
<![%standalone-ignore[<xref linkend="uuid-ossp">]]> module,
which provides functions to generate
UUIDs.<indexterm><primary>UUID</primary></indexterm>
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -13,20 +13,6 @@ ...@@ -13,20 +13,6 @@
are also functions to produce certain special UUID constants. are also functions to produce certain special UUID constants.
</para> </para>
<para>
This module depends on the OSSP UUID library, which can be found at
<ulink url="http://www.ossp.org/pkg/lib/uuid/"></ulink>.
</para>
<note>
<para>
The OSSP UUID library is not well maintained, and is becoming increasingly
difficult to port to newer platforms. If you only need randomly-generated
(version 4) UUIDs, consider using the <function>gen_random_uuid()</>
function from the <xref linkend="pgcrypto"> module instead.
</para>
</note>
<sect2> <sect2>
<title><literal>uuid-ossp</literal> Functions</title> <title><literal>uuid-ossp</literal> Functions</title>
...@@ -172,6 +158,39 @@ SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org'); ...@@ -172,6 +158,39 @@ SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');
</table> </table>
</sect2> </sect2>
<sect2>
<title>Building <filename>uuid-ossp</></title>
<para>
Historically this module depended on the OSSP UUID library, which accounts
for the module's name. While the OSSP UUID library can still be found
at <ulink url="http://www.ossp.org/pkg/lib/uuid/"></ulink>, it is not well
maintained, and is becoming increasingly difficult to port to newer
platforms. <filename>uuid-ossp</> can now be built without the OSSP
library on some platforms. On FreeBSD, NetBSD, and some other BSD-derived
platforms, suitable UUID creation functions are included in the
core <filename>libc</> library. On Linux, Mac OS X, and some other
platforms, suitable functions are provided in the <filename>libuuid</>
library, which originally came from the <literal>e2fsprogs</> project
(though on modern Linux it is considered part
of <literal>util-linux-ng</>). When invoking <filename>configure</>,
specify <option>--with-uuid=bsd</option> to use the BSD functions,
or <option>--with-uuid=e2fs</option> to
use <literal>e2fsprogs</>' <filename>libuuid</>, or
<option>--with-uuid=ossp</option> to use the OSSP UUID library.
More than one of these libraries might be available on a particular
machine, so <filename>configure</> does not automatically choose one.
</para>
<note>
<para>
If you only need randomly-generated (version 4) UUIDs,
consider using the <function>gen_random_uuid()</> function
from the <xref linkend="pgcrypto"> module instead.
</para>
</note>
</sect2>
<sect2> <sect2>
<title>Author</title> <title>Author</title>
......
...@@ -163,11 +163,11 @@ with_perl = @with_perl@ ...@@ -163,11 +163,11 @@ with_perl = @with_perl@
with_python = @with_python@ with_python = @with_python@
with_tcl = @with_tcl@ with_tcl = @with_tcl@
with_openssl = @with_openssl@ with_openssl = @with_openssl@
with_ossp_uuid = @with_ossp_uuid@
with_selinux = @with_selinux@ with_selinux = @with_selinux@
with_libxml = @with_libxml@ with_libxml = @with_libxml@
with_libxslt = @with_libxslt@ with_libxslt = @with_libxslt@
with_system_tzdata = @with_system_tzdata@ with_system_tzdata = @with_system_tzdata@
with_uuid = @with_uuid@
with_zlib = @with_zlib@ with_zlib = @with_zlib@
enable_rpath = @enable_rpath@ enable_rpath = @enable_rpath@
enable_nls = @enable_nls@ enable_nls = @enable_nls@
...@@ -240,7 +240,8 @@ DLLWRAP = @DLLWRAP@ ...@@ -240,7 +240,8 @@ DLLWRAP = @DLLWRAP@
LIBS = @LIBS@ LIBS = @LIBS@
LDAP_LIBS_FE = @LDAP_LIBS_FE@ LDAP_LIBS_FE = @LDAP_LIBS_FE@
LDAP_LIBS_BE = @LDAP_LIBS_BE@ LDAP_LIBS_BE = @LDAP_LIBS_BE@
OSSP_UUID_LIBS = @OSSP_UUID_LIBS@ UUID_LIBS = @UUID_LIBS@
UUID_EXTRA_OBJS = @UUID_EXTRA_OBJS@
LD = @LD@ LD = @LD@
with_gnu_ld = @with_gnu_ld@ with_gnu_ld = @with_gnu_ld@
ld_R_works = @ld_R_works@ ld_R_works = @ld_R_works@
......
...@@ -602,9 +602,21 @@ ...@@ -602,9 +602,21 @@
/* Define to 1 if you have the <utime.h> header file. */ /* Define to 1 if you have the <utime.h> header file. */
#undef HAVE_UTIME_H #undef HAVE_UTIME_H
/* Define to 1 if you have BSD UUID support. */
#undef HAVE_UUID_BSD
/* Define to 1 if you have E2FS UUID support. */
#undef HAVE_UUID_E2FS
/* Define to 1 if you have the <uuid.h> header file. */ /* Define to 1 if you have the <uuid.h> header file. */
#undef HAVE_UUID_H #undef HAVE_UUID_H
/* Define to 1 if you have OSSP UUID support. */
#undef HAVE_UUID_OSSP
/* Define to 1 if you have the <uuid/uuid.h> header file. */
#undef HAVE_UUID_UUID_H
/* Define to 1 if you have the `vsnprintf' function. */ /* Define to 1 if you have the `vsnprintf' function. */
#undef HAVE_VSNPRINTF #undef HAVE_VSNPRINTF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment