dev-db/mariadb: stable 10.1.31-r1 for ppc, bug #647082
[gentoo.git] / dev-db / mariadb / mariadb-10.3.7.ebuild
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5 MY_EXTRAS_VER="20180529-0042Z"
6 SUBSLOT="18"
7
8 JAVA_PKG_OPT_USE="jdbc"
9
10 # Keeping eutils in EAPI=6 for emktemp in pkg_config
11
12 inherit eutils systemd flag-o-matic prefix toolchain-funcs \
13         java-pkg-opt-2 user cmake-utils multilib-build
14
15 SRC_URI="https://downloads.mariadb.org/interstitial/${P}/source/${P}.tar.gz "
16
17 # Gentoo patches to MySQL
18 if [[ "${MY_EXTRAS_VER}" != "live" && "${MY_EXTRAS_VER}" != "none" ]]; then
19         SRC_URI="${SRC_URI}
20                 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
21                 https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
22                 https://dev.gentoo.org/~grknight/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
23                 https://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
24                 https://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
25 fi
26
27 HOMEPAGE="http://mariadb.org/"
28 DESCRIPTION="An enhanced, drop-in replacement for MySQL"
29 LICENSE="GPL-2 LGPL-2.1+"
30 SLOT="0/${SUBSLOT:-0}"
31 IUSE="+backup bindist client-libs cracklib debug extraengine galera innodb-lz4
32         innodb-lzo innodb-snappy jdbc jemalloc kerberos latin1 libressl mroonga
33         numa odbc oqgraph pam +perl profiling rocksdb selinux +server sphinx
34         sst-rsync sst-mariabackup sst-xtrabackup static static-libs systemd systemtap tcmalloc
35         test tokudb xml yassl"
36
37 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
38 RESTRICT="!bindist? ( bindist ) libressl? ( test )"
39
40 REQUIRED_USE="jdbc? ( extraengine server !static )
41         server? ( tokudb? ( jemalloc !tcmalloc ) )
42         ?? ( tcmalloc jemalloc )
43         static? ( yassl !pam )"
44
45 # REMEMBER: also update eclass/mysql*.eclass before committing!
46 KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ia64 ~ppc64 ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~x64-macos ~x86-macos ~x64-solaris ~x86-solaris"
47
48 # Shorten the path because the socket path length must be shorter than 107 chars
49 # and we will run a mysql server during test phase
50 S="${WORKDIR}/mysql"
51
52 if [[ "${MY_EXTRAS_VER}" == "live" ]] ; then
53         inherit git-r3
54         EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/mysql-extras.git"
55         EGIT_CHECKOUT_DIR="${WORKDIR%/}/mysql-extras"
56         EGIT_CLONE_TYPE=shallow
57         MY_PATCH_DIR="${WORKDIR%/}/mysql-extras"
58 else
59         MY_PATCH_DIR="${WORKDIR%/}/mysql-extras-${MY_EXTRAS_VER}"
60 fi
61
62 PATCHES=(
63         "${MY_PATCH_DIR}"/20015_all_mariadb-pkgconfig-location.patch
64         "${MY_PATCH_DIR}"/20018_all_mariadb-10.2.16-without-clientlibs-tools.patch
65         "${MY_PATCH_DIR}"/20024_all_mariadb-10.2.6-mysql_st-regression.patch
66         "${MY_PATCH_DIR}"/20025_all_mariadb-10.2.6-gssapi-detect.patch
67         "${MY_PATCH_DIR}"/20035_all_mariadb-10.3-atomic-detection.patch
68 )
69
70 # Be warned, *DEPEND are version-dependant
71 # These are used for both runtime and compiletime
72 # MULTILIB_USEDEP only set for libraries used by the client library
73 COMMON_DEPEND="
74         kernel_linux? (
75                 sys-process/procps:0=
76                 dev-libs/libaio:0=
77         )
78         >=sys-apps/sed-4
79         >=sys-apps/texinfo-4.7-r1
80         jemalloc? ( dev-libs/jemalloc:0= )
81         tcmalloc? ( dev-util/google-perftools:0= )
82         systemtap? ( >=dev-util/systemtap-1.3:0= )
83         >=sys-libs/zlib-1.2.3:0=
84         kerberos? ( virtual/krb5 )
85         yassl? ( net-libs/gnutls:0= )
86         !yassl? (
87                 !libressl? ( >=dev-libs/openssl-1.0.0:0= )
88                 libressl? ( dev-libs/libressl:0= )
89         )
90         sys-libs/ncurses:0=
91         !bindist? (
92                 sys-libs/binutils-libs:0=
93                 >=sys-libs/readline-4.1:0=
94         )
95         server? (
96                 backup? ( app-arch/libarchive:0= )
97                 cracklib? ( sys-libs/cracklib:0= )
98                 extraengine? (
99                         odbc? ( dev-db/unixODBC:0= )
100                         xml? ( dev-libs/libxml2:2= )
101                 )
102                 innodb-lz4? ( app-arch/lz4 )
103                 innodb-lzo? ( dev-libs/lzo )
104                 innodb-snappy? ( app-arch/snappy )
105                 mroonga? ( app-text/groonga-normalizer-mysql >=app-text/groonga-7.0.4 )
106                 numa? ( sys-process/numactl )
107                 oqgraph? ( >=dev-libs/boost-1.40.0:0= dev-libs/judy:0= )
108                 pam? ( virtual/pam:0= )
109                 systemd? ( sys-apps/systemd:= )
110                 tokudb? ( app-arch/snappy )
111         )
112         >=dev-libs/libpcre-8.41-r1:3=
113 "
114 DEPEND="virtual/yacc
115         static? ( sys-libs/ncurses[static-libs] )
116         || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
117         server? ( extraengine? ( jdbc? ( >=virtual/jdk-1.6 ) ) )
118         ${COMMON_DEPEND}"
119 RDEPEND="selinux? ( sec-policy/selinux-mysql )
120         !dev-db/mysql !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
121         server? ( !prefix? ( dev-db/mysql-init-scripts ) )
122         !<virtual/mysql-5.6-r11
123         ${COMMON_DEPEND}
124         server? ( galera? (
125                 sys-apps/iproute2
126                 =sys-cluster/galera-25*
127                 sst-rsync? ( sys-process/lsof )
128                 sst-mariabackup? ( net-misc/socat[ssl] )
129                 sst-xtrabackup? ( net-misc/socat[ssl] )
130         ) )
131         perl? ( !dev-db/mytop
132                 virtual/perl-Getopt-Long
133                 dev-perl/TermReadKey
134                 virtual/perl-Term-ANSIColor
135                 virtual/perl-Time-HiRes )
136         server? ( extraengine? ( jdbc? ( >=virtual/jre-1.6 ) ) )
137 "
138 # For other stuff to bring us in
139 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
140 # percona-xtrabackup-bin causes a circular dependency if DBD-mysql is not already installed
141 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )
142          dev-db/mariadb-connector-c[${MULTILIB_USEDEP},static-libs?] dev-db/mysql-connector-c[${MULTILIB_USEDEP},static-libs?]
143          server? ( ~virtual/mysql-5.6[static=]
144                  galera? ( sst-xtrabackup? ( || ( >=dev-db/percona-xtrabackup-bin-2.2.4 dev-db/percona-xtrabackup ) ) ) )"
145
146 pkg_setup() {
147         if [[ ${MERGE_TYPE} != binary ]] ; then
148                 local GCC_MAJOR_SET=$(gcc-major-version)
149                 local GCC_MINOR_SET=$(gcc-minor-version)
150                 if use tokudb && [[ ${GCC_MAJOR_SET} -lt 4 || \
151                         ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
152                         eerror "${PN} with tokudb needs to be built with gcc-4.7 or later."
153                         eerror "Please use gcc-config to switch to gcc-4.7 or later version."
154                         die
155                 fi
156                 # Bug 565584.  InnoDB now requires atomic functions introduced with gcc-4.7 on
157                 # non x86{,_64} arches
158                 if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
159                         ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
160                         eerror "${PN} needs to be built with gcc-4.7 or later."
161                         eerror "Please use gcc-config to switch to gcc-4.7 or later version."
162                         die
163                 fi
164         fi
165         java-pkg-opt-2_pkg_setup
166         if has test ${FEATURES} && \
167                 use server && ! has userpriv ${FEATURES} ; then
168                         eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
169         fi
170
171         # This should come after all of the die statements
172         enewgroup mysql 60 || die "problem adding 'mysql' group"
173         enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
174 }
175
176 pkg_preinst() {
177         java-pkg-opt-2_pkg_preinst
178
179         # Here we need to see if the implementation switched client libraries
180         # We check if this is a new instance of the package and a client library already exists
181         local SHOW_ABI_MESSAGE libpath
182         if [[ -z ${REPLACING_VERSIONS} && -e "${EROOT}usr/$(get_libdir)/libmysqlclient.so" ]] ; then
183                 libpath=$(readlink "${EROOT}usr/$(get_libdir)/libmysqlclient.so")
184                 elog "Due to ABI changes when switching between different client libraries,"
185                 elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
186                 elog "Please run: revdep-rebuild --library ${libpath}"
187                 ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
188         fi
189 }
190
191 pkg_postinst() {
192         # Make sure the vars are correctly initialized
193         mysql_init_vars
194
195         # Create log directory securely if it does not exist
196         [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
197
198         if use server ; then
199                 if use pam; then
200                         einfo
201                         elog "This install includes the PAM authentication plugin."
202                         elog "To activate and configure the PAM plugin, please read:"
203                         elog "https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/"
204                         einfo
205                 fi
206
207                 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
208                         einfo
209                         elog "You might want to run:"
210                         elog "\"emerge --config =${CATEGORY}/${PF}\""
211                         elog "if this is a new install."
212                         elog
213                         elog "If you are switching server implentations, you should run the"
214                         elog "mysql_upgrade tool."
215                         einfo
216                 else
217                         einfo
218                         elog "If you are upgrading major versions, you should run the"
219                         elog "mysql_upgrade tool."
220                         einfo
221                 fi
222
223                 if use galera ; then
224                         einfo
225                         elog "Be sure to edit the my.cnf file to activate your cluster settings."
226                         elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
227                         elog "The first time the cluster is activated, you should add"
228                         elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
229                         elog "This option should then be removed for subsequent starts."
230                         einfo
231                 fi
232         fi
233
234         # Note about configuration change
235         einfo
236         elog "This version of mariadb reorganizes the configuration from a single my.cnf"
237         elog "to several files in /etc/mysql/${PN}.d."
238         elog "Please backup any changes you made to /etc/mysql/my.cnf"
239         elog "and add them as a new file under /etc/mysql/${PN}.d with a .cnf extension."
240         elog "You may have as many files as needed and they are read alphabetically."
241         elog "Be sure the options have the appropitate section headers, i.e. [mysqld]."
242         einfo
243 }
244
245 src_unpack() {
246
247         # Initialize the proper variables first
248         mysql_init_vars
249
250         unpack ${A}
251         # Grab the patches
252         [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
253
254         mv -f "${WORKDIR}/${P/_rc/}" "${S}" || die
255 }
256
257 src_prepare() {
258         _disable_plugin() {
259                 echo > "${S%/}/plugin/${1}/CMakeLists.txt" || die
260         }
261         _disable_engine() {
262                 echo > "${S%/}/storage/${1}/CMakeLists.txt" || die
263         }
264
265         java-pkg-opt-2_src_prepare
266         if use tcmalloc; then
267                 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
268         fi
269
270         # Don't build bundled xz-utils for tokudb
271         echo > "${S}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
272         sed -i -e 's/ build_lzma//' -e 's/ build_snappy//' "${S}/storage/tokudb/PerconaFT/ft/CMakeLists.txt" || die
273         sed -i -e 's/add_dependencies\(tokuportability_static_conv build_jemalloc\)//' "${S}/storage/tokudb/PerconaFT/portability/CMakeLists.txt" || die
274
275         local plugin
276         local server_plugins=( handler_socket auth_socket feedback metadata_lock_info
277                                 locale_info qc_info server_audit sql_errlog )
278         local test_plugins=( audit_null auth_examples daemon_example fulltext
279                                 debug_key_management example_key_management versioning )
280         if ! use server; then # These plugins are for the server
281                 for plugin in "${server_plugins[@]}" ; do
282                         _disable_plugin "${plugin}"
283                 done
284         fi
285
286         if ! use test; then # These plugins are only used during testing
287                 for plugin in "${test_plugins[@]}" ; do
288                         _disable_plugin "${plugin}"
289                 done
290                 _disable_engine test_sql_discovery
291         fi
292
293         _disable_engine example
294
295         if ! use oqgraph ; then # avoids extra library checks
296                 _disable_engine oqgraph
297         fi
298
299         if use mroonga ; then
300                 # Remove the bundled groonga
301                 # There is no CMake flag, it simply checks for existance
302                 rm -r "${S}"/storage/mroonga/vendor/groonga || die "could not remove packaged groonga"
303         else
304                 _disable_engine mroonga
305         fi
306
307         cmake-utils_src_prepare
308 }
309
310 src_configure(){
311         # bug 508724 mariadb cannot use ld.gold
312         tc-ld-disable-gold
313         # Bug #114895, bug #110149
314         filter-flags "-O" "-O[01]"
315
316         append-cxxflags -felide-constructors
317
318         # bug #283926, with GCC4.4, this is required to get correct behavior.
319         append-flags -fno-strict-aliasing
320
321         CMAKE_BUILD_TYPE="RelWithDebInfo"
322
323         # debug hack wrt #497532
324         mycmakeargs=(
325                 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
326                 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
327                 -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
328                 -DMYSQL_DATADIR="${EPREFIX}/var/lib/mysql"
329                 -DSYSCONFDIR="${EPREFIX}/etc/mysql"
330                 -DINSTALL_BINDIR=bin
331                 -DINSTALL_DOCDIR=share/doc/${PF}
332                 -DINSTALL_DOCREADMEDIR=share/doc/${PF}
333                 -DINSTALL_INCLUDEDIR=include/mysql
334                 -DINSTALL_INFODIR=share/info
335                 -DINSTALL_LIBDIR=$(get_libdir)
336                 -DINSTALL_MANDIR=share/man
337                 -DINSTALL_MYSQLSHAREDIR=share/mariadb
338                 -DINSTALL_PLUGINDIR=$(get_libdir)/mariadb/plugin
339                 -DINSTALL_SCRIPTDIR=share/mariadb/scripts
340                 -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
341                 -DINSTALL_SBINDIR=sbin
342                 -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mariadb"
343                 -DWITH_COMMENT="Gentoo Linux ${PF}"
344                 -DWITH_UNIT_TESTS=$(usex test ON OFF)
345                 -DWITH_LIBEDIT=0
346                 -DWITH_ZLIB=system
347                 -DWITHOUT_LIBWRAP=1
348                 -DENABLED_LOCAL_INFILE=1
349                 -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
350                 -DINSTALL_UNIX_ADDRDIR="${EPREFIX}/var/run/mysqld/mysqld.sock"
351                 -DWITH_DEFAULT_COMPILER_OPTIONS=0
352                 -DWITH_DEFAULT_FEATURE_SET=0
353                 -DINSTALL_SYSTEMD_UNITDIR="$(systemd_get_systemunitdir)"
354                 # The build forces this to be defined when cross-compiling.  We pass it
355                 # all the time for simplicity and to make sure it is actually correct.
356                 -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
357                 -DPKG_CONFIG_EXECUTABLE="${EPREFIX}/usr/bin/$(tc-getPKG_CONFIG)"
358                 -DPLUGIN_AUTH_GSSAPI=$(usex kerberos DYNAMIC NO)
359                 -DAUTH_GSSAPI_PLUGIN_TYPE=$(usex kerberos DYNAMIC OFF)
360                 -DCONC_WITH_EXTERNAL_ZLIB=YES
361                 -DWITH_EXTERNAL_ZLIB=YES
362                 -DSUFFIX_INSTALL_DIR=""
363                 -DWITH_UNITTEST=OFF
364                 -DWITHOUT_CLIENTLIBS=YES
365                 -DCLIENT_PLUGIN_DIALOG=OFF
366                 -DCLIENT_PLUGIN_AUTH_GSSAPI_CLIENT=OFF
367                 -DCLIENT_PLUGIN_MYSQL_CLEAR_PASSWORD=STATIC
368         )
369         if use test ; then
370                 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mariadb/mysql-test )
371         else
372                 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
373         fi
374
375         if ! use yassl ; then
376                 mycmakeargs+=( -DWITH_SSL=system -DCLIENT_PLUGIN_SHA256_PASSWORD=STATIC )
377         else
378                 mycmakeargs+=( -DWITH_SSL=bundled )
379         fi
380
381         # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
382         mycmakeargs+=(
383                 -DWITH_READLINE=$(usex bindist 1 0)
384                 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
385                 -DENABLE_DTRACE=$(usex systemtap)
386         )
387
388         if use server ; then
389
390                 # Federated{,X} must be treated special otherwise they will not be built as plugins
391                 if ! use extraengine ; then
392                         mycmakeargs+=(
393                                 -DPLUGIN_FEDERATED=NO
394                                 -DPLUGIN_FEDERATEDX=NO )
395                 fi
396
397                 mycmakeargs+=(
398                         -DWITH_JEMALLOC=$(usex jemalloc system)
399                         -DWITH_PCRE=system
400                         -DPLUGIN_OQGRAPH=$(usex oqgraph DYNAMIC NO)
401                         -DPLUGIN_SPHINX=$(usex sphinx YES NO)
402                         -DPLUGIN_TOKUDB=$(usex tokudb YES NO)
403                         -DPLUGIN_AUTH_PAM=$(usex pam YES NO)
404                         -DPLUGIN_CRACKLIB_PASSWORD_CHECK=$(usex cracklib YES NO)
405                         -DPLUGIN_CASSANDRA=NO
406                         -DPLUGIN_SEQUENCE=$(usex extraengine YES NO)
407                         -DPLUGIN_SPIDER=$(usex extraengine YES NO)
408                         -DPLUGIN_CONNECT=$(usex extraengine YES NO)
409                         -DCONNECT_WITH_MYSQL=1
410                         -DCONNECT_WITH_LIBXML2=$(usex xml)
411                         -DCONNECT_WITH_ODBC=$(usex odbc)
412                         -DCONNECT_WITH_JDBC=$(usex jdbc)
413                         # Build failure and autodep wrt bug 639144
414                         -DCONNECT_WITH_MONGO=OFF
415                         -DWITH_WSREP=$(usex galera)
416                         -DWITH_INNODB_LZ4=$(usex innodb-lz4 ON OFF)
417                         -DWITH_INNODB_LZO=$(usex innodb-lzo ON OFF)
418                         -DWITH_INNODB_SNAPPY=$(usex innodb-snappy ON OFF)
419                         -DPLUGIN_MROONGA=$(usex mroonga DYNAMIC NO)
420                         -DPLUGIN_AUTH_GSSAPI=$(usex kerberos DYNAMIC NO)
421                         -DWITH_MARIABACKUP=$(usex backup ON OFF)
422                         -DWITH_LIBARCHIVE=$(usex backup ON OFF)
423                         -DINSTALL_SQLBENCHDIR=""
424                         -DPLUGIN_ROCKSDB=$(usex rocksdb DYNAMIC NO)
425                         # systemd is only linked to for server notification
426                         -DWITH_SYSTEMD=$(usex systemd yes no)
427                         -DWITH_NUMA=$(usex numa ON OFF)
428                 )
429
430                 # Workaround for MDEV-14524
431                 use tokudb && mycmakeargs+=( -DTOKUDB_OK=1 )
432
433                 if use test ; then
434                         # This is needed for the new client lib which tests a real, open server
435                         mycmakeargs+=( -DSKIP_TESTS=ON )
436                 fi
437
438                 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
439                         ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
440                         ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
441                         ewarn "You MUST file bugs without these variables set."
442
443                         mycmakeargs+=(
444                                 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
445                                 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
446                         )
447
448                 elif ! use latin1 ; then
449                         mycmakeargs+=(
450                                 -DDEFAULT_CHARSET=utf8
451                                 -DDEFAULT_COLLATION=utf8_general_ci
452                         )
453                 else
454                         mycmakeargs+=(
455                                 -DDEFAULT_CHARSET=latin1
456                                 -DDEFAULT_COLLATION=latin1_swedish_ci
457                         )
458                 fi
459                 mycmakeargs+=(
460                         -DEXTRA_CHARSETS=all
461                         -DMYSQL_USER=mysql
462                         -DDISABLE_SHARED=$(usex static YES NO)
463                         -DWITH_DEBUG=$(usex debug)
464                         -DWITH_EMBEDDED_SERVER=OFF
465                         -DWITH_PROFILING=$(usex profiling)
466                 )
467
468                 if use static; then
469                         mycmakeargs+=( -DWITH_PIC=1 )
470                 fi
471
472                 if use jemalloc || use tcmalloc ; then
473                         mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
474                 fi
475
476                 # Storage engines
477                 mycmakeargs+=(
478                         -DWITH_ARCHIVE_STORAGE_ENGINE=1
479                         -DWITH_BLACKHOLE_STORAGE_ENGINE=1
480                         -DWITH_CSV_STORAGE_ENGINE=1
481                         -DWITH_HEAP_STORAGE_ENGINE=1
482                         -DWITH_INNOBASE_STORAGE_ENGINE=1
483                         -DWITH_MYISAMMRG_STORAGE_ENGINE=1
484                         -DWITH_MYISAM_STORAGE_ENGINE=1
485                         -DWITH_PARTITION_STORAGE_ENGINE=1
486                 )
487
488         else
489                 mycmakeargs+=(
490                         -DWITHOUT_SERVER=1
491                         -DWITH_EMBEDDED_SERVER=OFF
492                         -DEXTRA_CHARSETS=none
493                         -DINSTALL_SQLBENCHDIR=
494                         -DWITH_SYSTEMD=no
495                 )
496         fi
497
498         cmake-utils_src_configure
499 }
500
501 src_compile() {
502         cmake-utils_src_compile
503 }
504
505 src_install() {
506         cmake-utils_src_install
507
508         # Remove an unnecessary, private config header which will never match between ABIs and is not meant to be used
509         if [[ -f "${ED}/usr/include/mysql/server/private/config.h" ]] ; then
510                 rm "${ED}/usr/include/mysql/server/private/config.h" || die
511         fi
512
513         # Make sure the vars are correctly initialized
514         mysql_init_vars
515
516         # Convenience links
517         einfo "Making Convenience links for mysqlcheck multi-call binary"
518         dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
519         dosym "mysqlcheck" "/usr/bin/mysqlrepair"
520         dosym "mysqlcheck" "/usr/bin/mysqloptimize"
521
522         # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
523         if [[ -d "${ED}/usr/data" ]] ; then
524                 rm -Rf "${ED}/usr/data" || die
525         fi
526
527         # Unless they explicitly specific USE=test, then do not install the
528         # testsuite. It DOES have a use to be installed, esp. when you want to do a
529         # validation of your database configuration after tuning it.
530         if ! use test ; then
531                 rm -rf "${D}/${MY_SHAREDSTATEDIR}/mysql-test"
532         fi
533
534         # Configuration stuff
535         einfo "Building default configuration ..."
536         insinto "${MY_SYSCONFDIR#${EPREFIX}}"
537         [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
538         cp "${FILESDIR}/my.cnf-10.2" "${TMPDIR}/my.cnf" || die
539         eprefixify "${TMPDIR}/my.cnf"
540         doins "${TMPDIR}/my.cnf"
541         insinto "${MY_SYSCONFDIR#${EPREFIX}}/mariadb.d"
542         cp "${FILESDIR}/my.cnf.distro-client" "${TMPDIR}/50-distro-client.cnf" || die
543         eprefixify "${TMPDIR}/50-distro-client.cnf"
544         doins "${TMPDIR}/50-distro-client.cnf"
545
546         if use server ; then
547                 mycnf_src="my.cnf.distro-server"
548                 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
549                         "${FILESDIR}/${mycnf_src}" \
550                         > "${TMPDIR}/my.cnf.ok" || die
551                 if use prefix ; then
552                         sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' \
553                                 "${TMPDIR}/my.cnf.ok" || die
554                 fi
555                 if use latin1 ; then
556                         sed -i \
557                                 -e "/character-set/s|utf8|latin1|g" \
558                                 "${TMPDIR}/my.cnf.ok" || die
559                 fi
560                 eprefixify "${TMPDIR}/my.cnf.ok"
561                 newins "${TMPDIR}/my.cnf.ok" 50-distro-server.cnf
562
563                 einfo "Including support files and sample configurations"
564                 docinto "support-files"
565                 local script
566                 for script in \
567                         "${S}"/support-files/magic
568                 do
569                         [[ -f "$script" ]] && dodoc "${script}"
570                 done
571
572                 docinto "scripts"
573                 for script in "${S}"/scripts/mysql* ; do
574                         [[ ( -f "$script" ) && ( "${script%.sh}" == "${script}" ) ]] && dodoc "${script}"
575                 done
576         fi
577
578         #Remove mytop if perl is not selected
579         [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
580 }
581
582 # Official test instructions:
583 # USE='extraengine perl server' \
584 # FEATURES='test userpriv -usersandbox' \
585 # ebuild mariadb-X.X.XX.ebuild \
586 # digest clean package
587 src_test() {
588
589         _disable_test() {
590                 local rawtestname reason
591                 rawtestname="${1}" ; shift
592                 reason="${@}"
593                 ewarn "test '${rawtestname}' disabled: '${reason}'"
594                 echo ${rawtestname} : ${reason} >> "${T}/disabled.def"
595         }
596
597         local TESTDIR="${BUILD_DIR}/mysql-test"
598         local retstatus_unit
599         local retstatus_tests
600
601         if ! use server ; then
602                 einfo "Skipping server tests due to minimal build."
603                 return 0
604         fi
605
606         # Bug #213475 - MySQL _will_ object strenously if your machine is named
607         # localhost. Also causes weird failures.
608         [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
609
610         if [[ $UID -eq 0 ]]; then
611                 die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
612         fi
613         has usersandbox $FEATURES && ewarn "Some tests may fail with FEATURES=usersandbox"
614
615         einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
616
617         # Run CTest (test-units)
618         cmake-utils_src_test
619         retstatus_unit=$?
620
621         # Ensure that parallel runs don't die
622         export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
623         # Enable parallel testing, auto will try to detect number of cores
624         # You may set this by hand.
625         # The default maximum is 8 unless MTR_MAX_PARALLEL is increased
626         export MTR_PARALLEL="${MTR_PARALLEL:-auto}"
627
628         # create directories because mysqladmin might run out of order
629         mkdir -p "${T}"/var-tests{,/log} || die
630
631         # Run mysql tests
632         pushd "${TESTDIR}" > /dev/null || die
633
634         touch "${T}/disabled.def"
635         # These are failing in MariaDB 10.0 for now and are believed to be
636         # false positives:
637         #
638         # main.mysql_client_test, main.mysql_client_test_nonblock
639         # main.mysql_client_test_comp:
640         # segfaults at random under Portage only, suspect resource limits.
641
642         local t
643         for t in plugins.cracklib_password_check plugins.two_password_validations ; do
644                 _disable_test  "$t" "False positive due to varying policies"
645         done
646
647         for t in main.mysql_client_test main.mysql_client_test_nonblock \
648                 main.mysql_client_test_comp rpl.rpl_extra_col_master_myisam ; do
649                         _disable_test  "$t" "False positives in Gentoo"
650         done
651
652         _disable_test main.plugin_auth "Needs client libraries built"
653
654         # run mysql-test tests
655         perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
656         retstatus_tests=$?
657
658         popd > /dev/null || die
659
660         # Cleanup is important for these testcases.
661         pkill -9 -f "${S}/ndb" 2>/dev/null
662         pkill -9 -f "${S}/sql" 2>/dev/null
663
664         local failures=""
665         [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
666         [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
667
668         [[ -z "$failures" ]] || die "Test failures: $failures"
669         einfo "Tests successfully completed"
670 }
671
672 mysql_init_vars() {
673         MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mariadb"}
674         MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
675         MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
676         MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
677
678         if [[ -z "${MY_DATADIR}" ]] ; then
679                 MY_DATADIR=""
680                 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
681                         MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
682                                 | sed -ne '/datadir/s|^--datadir=||p' \
683                                 | tail -n1`
684                         if [[ -z "${MY_DATADIR}" ]] ; then
685                                 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
686                                 | sed -e 's/.*=\s*//' \
687                                 | tail -n1`
688                         fi
689                 fi
690                 if [[ -z "${MY_DATADIR}" ]] ; then
691                         MY_DATADIR="${MY_LOCALSTATEDIR}"
692                         einfo "Using default MY_DATADIR"
693                 fi
694                 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
695
696                 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
697                         if [[ -e "${MY_DATADIR}" ]] ; then
698                                 # If you get this and you're wondering about it, see bug #207636
699                                 elog "MySQL datadir found in ${MY_DATADIR}"
700                                 elog "A new one will not be created."
701                                 PREVIOUS_DATADIR="yes"
702                         else
703                                 PREVIOUS_DATADIR="no"
704                         fi
705                         export PREVIOUS_DATADIR
706                 fi
707         else
708                 if [[ ${EBUILD_PHASE} == "config" ]]; then
709                         local new_MY_DATADIR
710                         new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
711                                 | sed -ne '/datadir/s|^--datadir=||p' \
712                                 | tail -n1`
713
714                         if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
715                                 ewarn "MySQL MY_DATADIR has changed"
716                                 ewarn "from ${MY_DATADIR}"
717                                 ewarn "to ${new_MY_DATADIR}"
718                                 MY_DATADIR="${new_MY_DATADIR}"
719                         fi
720                 fi
721         fi
722
723         export MY_SHAREDSTATEDIR MY_SYSCONFDIR
724         export MY_LOCALSTATEDIR MY_LOGDIR
725         export MY_DATADIR
726 }
727
728 pkg_config() {
729         _getoptval() {
730                 local mypd="${EROOT}"/usr/bin/my_print_defaults
731                 local section="$1"
732                 local flag="--${2}="
733                 local extra_options="${3}"
734                 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
735         }
736         local old_MY_DATADIR="${MY_DATADIR}"
737         local old_HOME="${HOME}"
738         # my_print_defaults needs to read stuff in $HOME/.my.cnf
739         export HOME=${EPREFIX}/root
740
741         # Make sure the vars are correctly initialized
742         mysql_init_vars
743
744         [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
745         if [[ ! -x "${EROOT}/usr/sbin/mysqld" ]] ; then
746                 die "Minimal builds do NOT include the MySQL server"
747         fi
748
749         if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
750                 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
751                 MY_DATADIR_s="${MY_DATADIR_s%%/}"
752                 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
753                 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
754
755                 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
756                         if [[ -d "${MY_DATADIR_s}" ]]; then
757                                 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
758                                 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
759                         else
760                                 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
761                                 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
762                                 || die "Moving MY_DATADIR failed"
763                         fi
764                 else
765                         ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
766                         if [[ -d "${MY_DATADIR_s}" ]]; then
767                                 ewarn "Attempting to use ${MY_DATADIR_s}"
768                         else
769                                 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
770                                 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
771                         fi
772                 fi
773         fi
774
775         local pwd1="a"
776         local pwd2="b"
777         local maxtry=15
778
779         if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
780                 local tmp_mysqld_password_source=
781
782                 for tmp_mysqld_password_source in mysql client; do
783                         einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
784                         MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
785                         if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
786                                 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
787                                         ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
788                                         MYSQL_ROOT_PASSWORD=
789                                         continue
790                                 fi
791
792                                 einfo "Found password in '${tmp_mysqld_password_source}' section!"
793                                 break
794                         fi
795                 done
796
797                 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
798                 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
799                         MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
800                 fi
801
802                 unset tmp_mysqld_password_source
803         fi
804         MYSQL_TMPDIR="$(_getoptval mysqld tmpdir)"
805         # These are dir+prefix
806         MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log)"
807         MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
808         MYSQL_LOG_BIN="$(_getoptval mysqld log-bin)"
809         MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
810
811         if [[ ! -d "${ROOT}/$MYSQL_TMPDIR" ]]; then
812                 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
813                 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_TMPDIR"
814         fi
815         if [[ ! -d "${ROOT}/$MYSQL_LOG_BIN" ]]; then
816                 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
817                 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_LOG_BIN"
818         fi
819         if [[ ! -d "${EROOT}/$MYSQL_RELAY_LOG" ]]; then
820                 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
821                 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_RELAY_LOG"
822         fi
823
824         if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
825                 ewarn "You have already a MySQL database in place."
826                 ewarn "(${ROOT}/${MY_DATADIR}/*)"
827                 ewarn "Please rename or delete it if you wish to replace it."
828                 die "MySQL database already exists!"
829         fi
830
831         # Bug #213475 - MySQL _will_ object strenously if your machine is named
832         # localhost. Also causes weird failures.
833         [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
834
835         if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
836
837                 einfo "Please provide a password for the mysql 'root' user now"
838                 einfo "or through the ${HOME}/.my.cnf file."
839                 ewarn "Avoid [\"'\\_%] characters in the password"
840                 read -rsp "    >" pwd1 ; echo
841
842                 einfo "Retype the password"
843                 read -rsp "    >" pwd2 ; echo
844
845                 if [[ "x$pwd1" != "x$pwd2" ]] ; then
846                         die "Passwords are not the same"
847                 fi
848                 MYSQL_ROOT_PASSWORD="${pwd1}"
849                 unset pwd1 pwd2
850         fi
851
852         local options
853         local sqltmp="$(emktemp)"
854
855         # Fix bug 446200. Don't reference host my.cnf, needs to come first,
856         # see http://bugs.mysql.com/bug.php?id=31312
857         use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
858
859         # Figure out which options we need to disable to do the setup
860         local helpfile="${TMPDIR}/mysqld-help"
861         "${EROOT}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
862         for opt in grant-tables host-cache name-resolve networking slave-start \
863                 federated ssl log-bin relay-log slow-query-log external-locking \
864                 log-slave-updates \
865                 ; do
866                 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
867                 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
868         done
869
870         einfo "Creating the mysql database and setting proper permissions on it ..."
871
872         # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
873         PID_DIR="${EROOT}/var/run/mysqld"
874         if [[ ! -d "${PID_DIR}" ]]; then
875                 install -d -m 755 -o mysql -g mysql "${PID_DIR}" || die "Could not create pid directory"
876         fi
877
878         if [[ ! -d "${MY_DATADIR}" ]]; then
879                 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
880         fi
881
882         pushd "${TMPDIR}" &>/dev/null || die
883
884         # Filling timezones, see
885         # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
886         "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
887
888         local cmd=( "${EROOT}usr/share/mariadb/scripts/mysql_install_db" )
889         [[ -f "${cmd}" ]] || cmd=( "${EROOT}usr/bin/mysql_install_db" )
890         cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT}/${MY_DATADIR}" "--tmpdir=${ROOT}/${MYSQL_TMPDIR}" )
891         einfo "Command: ${cmd[*]}"
892         su -s /bin/sh -c "${cmd[*]}" mysql \
893                 >"${TMPDIR}"/mysql_install_db.log 2>&1
894         if [ $? -ne 0 ]; then
895                 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
896                 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
897         fi
898         popd &>/dev/null || die
899         [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
900         || die "MySQL databases not installed"
901
902         use prefix || options="${options} --user=mysql"
903
904         local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
905         local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
906         local mysqld="${EROOT}/usr/sbin/mysqld \
907                 ${options} \
908                 --log-warnings=0 \
909                 --basedir=${EROOT}/usr \
910                 --datadir=${ROOT}/${MY_DATADIR} \
911                 --max_allowed_packet=8M \
912                 --net_buffer_length=16K \
913                 --socket=${socket} \
914                 --pid-file=${pidfile}
915                 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
916         #einfo "About to start mysqld: ${mysqld}"
917         ebegin "Starting mysqld"
918         einfo "Command ${mysqld}"
919         ${mysqld} &
920         rc=$?
921         while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
922                 maxtry=$((${maxtry}-1))
923                 echo -n "."
924                 sleep 1
925         done
926         eend $rc
927
928         if ! [[ -S "${socket}" ]]; then
929                 die "Completely failed to start up mysqld with: ${mysqld}"
930         fi
931
932         ebegin "Setting root password"
933         # Do this from memory, as we don't want clear text passwords in temp files
934         local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'; FLUSH PRIVILEGES"
935         "${EROOT}/usr/bin/mysql" \
936                 "--socket=${socket}" \
937                 -hlocalhost \
938                 -e "${sql}"
939         eend $?
940
941         if [[ -n "${sqltmp}" ]] ; then
942                 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
943                 "${EROOT}/usr/bin/mysql" \
944                         "--socket=${socket}" \
945                         -hlocalhost \
946                         -uroot \
947                         --password="${MYSQL_ROOT_PASSWORD}" \
948                         mysql < "${sqltmp}"
949                 rc=$?
950                 eend $?
951                 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
952         fi
953
954         # Stop the server and cleanup
955         einfo "Stopping the server ..."
956         kill $(< "${pidfile}" )
957         rm -f "${sqltmp}"
958         wait %1
959         einfo "Done"
960 }