media-video/ffmpeg: stable 4.2.3 for sparc, bug #719940
[gentoo.git] / dev-db / mysql / mysql-5.7.29.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5 MY_EXTRAS_VER="20200125-1945Z"
6
7 CMAKE_MAKEFILE_GENERATOR=emake
8
9 # Keeping eutils in EAPI=6 for emktemp in pkg_config
10
11 inherit cmake-utils eutils flag-o-matic linux-info \
12         prefix toolchain-funcs multilib-minimal
13
14 SRC_URI="https://cdn.mysql.com/Downloads/MySQL-5.7/${PN}-boost-${PV}.tar.gz
15         https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-${PV}.tar.gz
16         http://downloads.mysql.com/archives/MySQL-5.7/${PN}-boost-${PV}.tar.gz"
17
18 # Gentoo patches to MySQL
19 if [[ "${MY_EXTRAS_VER}" != "live" && "${MY_EXTRAS_VER}" != "none" ]] ; then
20         SRC_URI="${SRC_URI}
21                 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
22                 https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
23 fi
24
25 HOMEPAGE="https://www.mysql.com/"
26 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
27 LICENSE="GPL-2"
28 SLOT="0/18"
29 IUSE="cjk client-libs cracklib debug experimental jemalloc latin1 libressl numa +perl profiling
30         selinux +server static static-libs systemtap tcmalloc test"
31
32 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
33 RESTRICT="!test? ( test ) libressl? ( test )"
34
35 REQUIRED_USE="?? ( tcmalloc jemalloc )"
36
37 KEYWORDS="amd64 arm ~arm64 ~hppa ~ia64 ~mips ~ppc ppc64 ~s390 ~sparc x86 ~amd64-linux ~x86-linux ~x64-macos ~x86-macos ~x64-solaris ~x86-solaris"
38
39 # Shorten the path because the socket path length must be shorter than 107 chars
40 # and we will run a mysql server during test phase
41 S="${WORKDIR}/mysql"
42
43 if [[ "${MY_EXTRAS_VER}" == "live" ]] ; then
44         inherit git-r3
45         EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/mysql-extras.git"
46         EGIT_CHECKOUT_DIR="${WORKDIR}/mysql-extras"
47         EGIT_CLONE_TYPE=shallow
48         MY_PATCH_DIR="${WORKDIR}/mysql-extras"
49 else
50         MY_PATCH_DIR="${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}"
51 fi
52
53 PATCHES=(
54         "${MY_PATCH_DIR}"/20001_all_fix-minimal-build-cmake-mysql-5.7.23.patch
55         "${MY_PATCH_DIR}"/20007_all_cmake-debug-werror-5.7.patch
56         "${MY_PATCH_DIR}"/20009_all_mysql_myodbc_symbol_fix-5.7.10.patch
57         "${MY_PATCH_DIR}"/20018_all_mysql-5.7.29-without-clientlibs-tools.patch
58         "${MY_PATCH_DIR}"/20018_all_mysql-5.7.29-fix-libressl-support.patch
59         "${MY_PATCH_DIR}"/20018_all_mysql-5.7.23-fix-grant_user_lock-a-root.patch
60         "${MY_PATCH_DIR}"/20018_all_mysql-5.7.23-round-off-test-values-for-same-output-on-all-architectures.patch
61         "${MY_PATCH_DIR}"/20018_all_mysql-5.7.25-fix-build-without-server.patch
62 )
63
64 # Be warned, *DEPEND are version-dependant
65 # These are used for both runtime and compiletime
66 # MULTILIB_USEDEP only set for libraries used by the client library
67 COMMON_DEPEND="net-misc/curl:=
68         >=sys-apps/sed-4
69         >=sys-apps/texinfo-4.7-r1
70         sys-libs/ncurses:0=
71         client-libs? ( >=sys-libs/zlib-1.2.3:0=[${MULTILIB_USEDEP},static-libs?] )
72         !client-libs? (
73                 dev-db/mysql-connector-c[${MULTILIB_USEDEP},static-libs?]
74                 >=sys-libs/zlib-1.2.3:0=
75         )
76         jemalloc? ( dev-libs/jemalloc:0= )
77         kernel_linux? (
78                 dev-libs/libaio:0=
79                 sys-process/procps:0=
80         )
81         server? (
82                 >=app-arch/lz4-0_p131:=
83                 cjk? ( app-text/mecab:= )
84                 experimental? (
85                         dev-libs/libevent:=
86                         dev-libs/protobuf:=
87                         net-libs/libtirpc:=
88                 )
89                 numa? ( sys-process/numactl )
90         )
91         systemtap? ( >=dev-util/systemtap-1.3:0= )
92         tcmalloc? ( dev-util/google-perftools:0= )
93         client-libs? (
94                 !libressl? ( >=dev-libs/openssl-1.0.0:0=[${MULTILIB_USEDEP},static-libs?] )
95                 libressl? ( dev-libs/libressl:0=[${MULTILIB_USEDEP},static-libs?] )
96         )
97         !client-libs? (
98                 !libressl? ( >=dev-libs/openssl-1.0.0:0= )
99                 libressl? ( dev-libs/libressl:0= )
100         )
101 "
102 DEPEND="${COMMON_DEPEND}
103         || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
104         dev-libs/protobuf
105         virtual/yacc
106         server? (
107                 dev-libs/libevent
108                 experimental? ( net-libs/rpcsvc-proto )
109         )
110         static? ( sys-libs/ncurses[static-libs] )
111         test? (
112                 acct-group/mysql acct-user/mysql
113                 dev-perl/JSON
114         )
115 "
116 RDEPEND="${COMMON_DEPEND}
117         !dev-db/mariadb !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
118         client-libs? ( !dev-db/mariadb-connector-c[mysqlcompat] !dev-db/mysql-connector-c dev-libs/protobuf:= )
119         selinux? ( sec-policy/selinux-mysql )
120         server? (
121                 !prefix? (
122                         acct-group/mysql acct-user/mysql
123                         dev-db/mysql-init-scripts
124                 )
125         )
126 "
127 # For other stuff to bring us in
128 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
129 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
130
131 mysql_init_vars() {
132         MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
133         MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
134         MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
135         MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
136
137         if [[ -z "${MY_DATADIR}" ]] ; then
138                 MY_DATADIR=""
139                 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
140                         MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
141                                 | sed -ne '/datadir/s|^--datadir=||p' \
142                                 | tail -n1`
143                         if [[ -z "${MY_DATADIR}" ]] ; then
144                                 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
145                                 | sed -e 's/.*=\s*//' \
146                                 | tail -n1`
147                         fi
148                 fi
149                 if [[ -z "${MY_DATADIR}" ]] ; then
150                         MY_DATADIR="${MY_LOCALSTATEDIR}"
151                         einfo "Using default MY_DATADIR"
152                 fi
153                 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
154
155                 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
156                         if [[ -e "${MY_DATADIR}" ]] ; then
157                                 # If you get this and you're wondering about it, see bug #207636
158                                 elog "MySQL datadir found in ${MY_DATADIR}"
159                                 elog "A new one will not be created."
160                                 PREVIOUS_DATADIR="yes"
161                         else
162                                 PREVIOUS_DATADIR="no"
163                         fi
164                         export PREVIOUS_DATADIR
165                 fi
166         else
167                 if [[ ${EBUILD_PHASE} == "config" ]] ; then
168                         local new_MY_DATADIR
169                         new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
170                                 | sed -ne '/datadir/s|^--datadir=||p' \
171                                 | tail -n1`
172
173                         if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]] ; then
174                                 ewarn "MySQL MY_DATADIR has changed"
175                                 ewarn "from ${MY_DATADIR}"
176                                 ewarn "to ${new_MY_DATADIR}"
177                                 MY_DATADIR="${new_MY_DATADIR}"
178                         fi
179                 fi
180         fi
181
182         export MY_SHAREDSTATEDIR MY_SYSCONFDIR
183         export MY_LOCALSTATEDIR MY_LOGDIR
184         export MY_DATADIR
185 }
186
187 pkg_pretend() {
188         if use numa ; then
189                 local CONFIG_CHECK="~NUMA"
190
191                 local WARNING_NUMA="This package expects NUMA support in kernel which this system does not have at the moment;"
192                 WARNING_NUMA+=" Either expect runtime errors, enable NUMA support in kernel or rebuild the package without NUMA support"
193
194                 check_extra_config
195         fi
196 }
197
198 pkg_setup() {
199         if [[ ${MERGE_TYPE} != binary ]] ; then
200                 local GCC_MAJOR_SET=$(gcc-major-version)
201                 local GCC_MINOR_SET=$(gcc-minor-version)
202                 # Bug 565584: InnoDB now requires atomic functions introduced with gcc-4.7 on
203                 # non x86{,_64} arches
204                 if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
205                         ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
206                         eerror "${PN} needs to be built with gcc-4.7 or later."
207                         eerror "Please use gcc-config to switch to gcc-4.7 or later version."
208                         die
209                 fi
210         fi
211
212         if has test ${FEATURES} && \
213                 use server && ! has userpriv ${FEATURES} ; then
214                         eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
215         fi
216 }
217
218 pkg_preinst() {
219         # Here we need to see if the implementation switched client libraries
220         # We check if this is a new instance of the package and a client library already exists
221         local SHOW_ABI_MESSAGE libpath
222         if use client-libs && [[ -z ${REPLACING_VERSIONS} && -e "${EROOT}usr/$(get_libdir)/libmysqlclient.so" ]] ; then
223                 libpath=$(readlink "${EROOT}usr/$(get_libdir)/libmysqlclient.so")
224                 elog "Due to ABI changes when switching between different client libraries,"
225                 elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
226                 elog "Please run: revdep-rebuild --library ${libpath}"
227                 ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
228         fi
229 }
230
231 pkg_postinst() {
232         # Make sure the vars are correctly initialized
233         mysql_init_vars
234
235         # Create log directory securely if it does not exist
236         [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
237
238         if use server ; then
239                 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
240                         einfo
241                         elog "You might want to run:"
242                         elog "\"emerge --config =${CATEGORY}/${PF}\""
243                         elog "if this is a new install."
244                         elog
245                         elog "If you are switching server implentations, you should run the"
246                         elog "mysql_upgrade tool."
247                         einfo
248                 else
249                         einfo
250                         elog "If you are upgrading major versions, you should run the"
251                         elog "mysql_upgrade tool."
252                         einfo
253                 fi
254         fi
255
256         # Note about configuration change
257         einfo
258         elog "This version of ${PN} reorganizes the configuration from a single my.cnf"
259         elog "to several files in /etc/mysql/mysql.d."
260         elog "Please backup any changes you made to /etc/mysql/my.cnf"
261         elog "and add them as a new file under /etc/mysql/mysql.d with a .cnf extension."
262         elog "You may have as many files as needed and they are read alphabetically."
263         elog "Be sure the options have the appropriate section headers, i.e. [mysqld]."
264         einfo
265 }
266
267 src_unpack() {
268         unpack ${A}
269         # Grab the patches
270         [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
271
272         mv -f "${WORKDIR}/${P}" "${S}" || die
273 }
274
275 src_prepare() {
276         cmake-utils_src_prepare
277
278         if use jemalloc ; then
279                 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
280         fi
281
282         if use tcmalloc ; then
283                 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt" || die
284         fi
285
286         # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
287         if [[ -d "${S}/support-files/SELinux" ]] ; then
288                 echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
289         fi
290
291         # Remove bundled libs so we cannot accidentally use them
292         # We keep extra/lz4 directory because we use extra/lz4/xxhash.c via sql/CMakeLists.txt:394
293         rm -rv \
294                 "${S}"/extra/protobuf \
295                 "${S}"/extra/libevent \
296                 "${S}"/zlib \
297                 || die
298
299         # Don't clash with dev-db/mysql-connector-c
300         rm \
301                 man/my_print_defaults.1 \
302                 man/perror.1 \
303                 man/zlib_decompress.1 \
304                 || die
305
306         if use libressl ; then
307                 sed -i 's/OPENSSL_MAJOR_VERSION STREQUAL "1"/OPENSSL_MAJOR_VERSION STREQUAL "2"/' \
308                         "${S}/cmake/ssl.cmake" || die
309         fi
310
311         sed -i 's~ADD_SUBDIRECTORY(storage/ndb)~~' CMakeLists.txt || die
312 }
313
314 src_configure() {
315         # Bug #114895, bug #110149
316         filter-flags "-O" "-O[01]"
317
318         append-cxxflags -felide-constructors
319
320         # bug #283926, with GCC4.4, this is required to get correct behavior.
321         append-flags -fno-strict-aliasing
322
323         if use client-libs ; then
324                 multilib-minimal_src_configure
325         else
326                 multilib_src_configure
327         fi
328 }
329
330 multilib_src_configure() {
331         debug-print-function ${FUNCNAME} "$@"
332
333         if ! multilib_is_native_abi && ! use client-libs ; then
334                 return
335         fi
336
337         CMAKE_BUILD_TYPE="RelWithDebInfo"
338
339         # debug hack wrt #497532
340         mycmakeargs=(
341                 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
342                 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
343                 -DMYSQL_DATADIR="${EPREFIX}/var/lib/mysql"
344                 -DSYSCONFDIR="${EPREFIX}/etc/mysql"
345                 -DINSTALL_BINDIR=bin
346                 -DINSTALL_DOCDIR=share/doc/${PF}
347                 -DINSTALL_DOCREADMEDIR=share/doc/${PF}
348                 -DINSTALL_INCLUDEDIR=include/mysql
349                 -DINSTALL_INFODIR=share/info
350                 -DINSTALL_LIBDIR=$(get_libdir)
351                 -DINSTALL_MANDIR=share/man
352                 -DINSTALL_MYSQLSHAREDIR=share/mysql
353                 -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
354                 -DINSTALL_SCRIPTDIR=share/mysql/scripts
355                 -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
356                 -DINSTALL_SBINDIR=sbin
357                 -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mysql"
358                 -DCOMPILATION_COMMENT="Gentoo Linux ${PF}"
359                 -DWITH_UNIT_TESTS=$(usex test ON OFF)
360                 ### TODO: make this system but issues with UTF-8 prevent it
361                 -DWITH_EDITLINE=bundled
362                 -DWITH_ZLIB=system
363                 -DWITH_SSL=system
364                 -DWITH_LIBWRAP=0
365                 -DENABLED_LOCAL_INFILE=1
366                 -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
367                 -DWITH_DEFAULT_COMPILER_OPTIONS=0
368                 -DWITH_DEFAULT_FEATURE_SET=0
369                 # The build forces this to be defined when cross-compiling. We pass it
370                 # all the time for simplicity and to make sure it is actually correct.
371                 -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
372                 -DWITH_CURL=system
373                 -DWITH_BOOST="${S}/boost"
374         )
375         if use test ; then
376                 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
377         else
378                 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
379         fi
380
381         if ! use client-libs ; then
382                 mycmakeargs+=( -DWITHOUT_CLIENTLIBS=YES )
383         fi
384
385         # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
386         # systemtap only works on native ABI, bug 530132
387         if multilib_is_native_abi ; then
388                 mycmakeargs+=(
389                         -DENABLE_DTRACE=$(usex systemtap)
390                 )
391         else
392                 mycmakeargs+=(
393                         -DWITHOUT_TOOLS=1
394                         -DWITH_READLINE=1
395                         -DENABLE_DTRACE=0
396                 )
397         fi
398
399         if multilib_is_native_abi && use server ; then
400                 mycmakeargs+=(
401                         -DWITH_LIBEVENT=system
402                         -DWITH_LZ4=system
403                         -DWITH_PROTOBUF=system
404                         -DWITH_MECAB=$(usex cjk system OFF)
405                         -DWITH_NUMA=$(usex numa ON OFF)
406                         -DWITH_RAPID=$(usex experimental ON OFF)
407                 )
408
409                 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]] ; then
410                         ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
411                         ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
412                         ewarn "You MUST file bugs without these variables set."
413
414                         mycmakeargs+=(
415                                 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
416                                 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
417                         )
418                 elif ! use latin1 ; then
419                         mycmakeargs+=(
420                                 -DDEFAULT_CHARSET=utf8
421                                 -DDEFAULT_COLLATION=utf8_general_ci
422                         )
423                 else
424                         mycmakeargs+=(
425                                 -DDEFAULT_CHARSET=latin1
426                                 -DDEFAULT_COLLATION=latin1_swedish_ci
427                         )
428                 fi
429
430                 mycmakeargs+=(
431                         -DEXTRA_CHARSETS=all
432                         -DDISABLE_SHARED=$(usex static YES NO)
433                         -DWITH_DEBUG=$(usex debug)
434                         -DWITH_EMBEDDED_SERVER=OFF
435                 )
436
437                 if use profiling ; then
438                         # Setting to OFF doesn't work: Once set, profiling options will be added
439                         # to `mysqld --help` output via sql/sys_vars.cc causing
440                         # "main.mysqld--help-notwin" test to fail
441                         mycmakeargs+=( -DENABLED_PROFILING=ON )
442                 fi
443
444                 if use static ; then
445                         mycmakeargs+=( -DWITH_PIC=1 )
446                 fi
447
448                 # Storage engines
449                 mycmakeargs+=(
450                         -DWITH_EXAMPLE_STORAGE_ENGINE=0
451                         -DWITH_ARCHIVE_STORAGE_ENGINE=1
452                         -DWITH_BLACKHOLE_STORAGE_ENGINE=1
453                         -DWITH_CSV_STORAGE_ENGINE=1
454                         -DWITH_FEDERATED_STORAGE_ENGINE=1
455                         -DWITH_HEAP_STORAGE_ENGINE=1
456                         -DWITH_INNOBASE_STORAGE_ENGINE=1
457                         -DWITH_INNODB_MEMCACHED=0
458                         -DWITH_MYISAMMRG_STORAGE_ENGINE=1
459                         -DWITH_MYISAM_STORAGE_ENGINE=1
460                         -DWITH_PARTITION_STORAGE_ENGINE=1
461                 )
462
463         else
464                 mycmakeargs+=(
465                         -DWITHOUT_SERVER=1
466                         -DWITH_EMBEDDED_SERVER=OFF
467                         -DEXTRA_CHARSETS=none
468                 )
469         fi
470
471         cmake-utils_src_configure
472 }
473
474 src_compile() {
475         if use client-libs ; then
476                 multilib-minimal_src_compile
477         else
478                 multilib_src_compile
479         fi
480 }
481
482 multilib_src_compile() {
483         cmake-utils_src_compile
484 }
485
486 # Official test instructions:
487 # ulimit -n 16500 && \
488 # USE='latin1 perl server' \
489 # FEATURES='test userpriv -usersandbox' \
490 # ebuild mysql-X.X.XX.ebuild \
491 # digest clean package
492 src_test() {
493         _disable_test() {
494                 local rawtestname reason
495                 rawtestname="${1}" ; shift
496                 reason="${@}"
497                 ewarn "test '${rawtestname}' disabled: '${reason}'"
498                 echo ${rawtestname} : ${reason} >> "${T}/disabled.def"
499         }
500
501         local TESTDIR="${BUILD_DIR}/mysql-test"
502         local retstatus_unit
503         local retstatus_tests
504
505         if ! use server ; then
506                 einfo "Skipping server tests due to minimal build."
507                 return 0
508         fi
509
510         # Bug #213475 - MySQL _will_ object strenously if your machine is named
511         # localhost. Also causes weird failures.
512         [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
513
514         if [[ $UID -eq 0 ]] ; then
515                 die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
516         fi
517         has usersandbox $FEATURES && ewarn "Some tests may fail with FEATURES=usersandbox"
518
519         einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
520
521         # Run CTest (test-units)
522         cmake-utils_src_test
523         retstatus_unit=$?
524
525         # Ensure that parallel runs don't die
526         export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
527         # Enable parallel testing, auto will try to detect number of cores
528         # You may set this by hand.
529         # The default maximum is 8 unless MTR_MAX_PARALLEL is increased
530         export MTR_PARALLEL="${MTR_PARALLEL:-auto}"
531
532         # create directories because mysqladmin might run out of order
533         mkdir -p "${T}"/var-tests{,/log} || die
534
535         # Run mysql tests
536         pushd "${TESTDIR}" &>/dev/null || die
537
538         touch "${T}/disabled.def"
539         # These are failing in MySQL 5.7 for now and are believed to be
540         # false positives:
541         #
542         local t
543
544         for t in auth_sec.keyring_udf ; do
545                         _disable_test "$t" "False positives in Gentoo"
546         done
547
548         # Unstable tests
549         # - main.xa_prepared_binlog_off: https://bugs.mysql.com/bug.php?id=83340
550         # - rpl.rpl_innodb_info_tbl_slave_tmp_tbl_mismatch: https://bugs.mysql.com/bug.php?id=89223
551         # - rpl.rpl_non_direct_stm_mixing_engines: MDEV-14489
552         for t in \
553                 main.xa_prepared_binlog_off \
554                 rpl.rpl_innodb_info_tbl_slave_tmp_tbl_mismatch \
555                 rpl.rpl_non_direct_stm_mixing_engines \
556         ; do
557                 _disable_test "$t" "Unstable test"
558         done
559
560         for t in \
561                 gis.geometry_class_attri_prop \
562                 gis.geometry_property_function_issimple \
563                 gis.gis_bugs_crashes \
564                 gis.spatial_op_testingfunc_mix \
565                 gis.spatial_analysis_functions_buffer \
566                 gis.spatial_analysis_functions_distance \
567                 gis.spatial_utility_function_distance_sphere \
568                 gis.spatial_utility_function_simplify \
569                 gis.spatial_analysis_functions_centroid \
570         ; do
571                 _disable_test "$t" "Known rounding error with latest AMD processors"
572         done
573
574         if use numa && use kernel_linux ; then
575                 # bug 584880
576                 if ! linux_config_exists || ! linux_chkconfig_present NUMA ; then
577                         for t in sys_vars.innodb_numa_interleave_basic ; do
578                                 _disable_test "$t" "Test $t requires system with NUMA support"
579                         done
580                 fi
581         fi
582
583         if ! use latin1 ; then
584                 # The following tests will fail if DEFAULT_CHARSET
585                 # isn't set to latin1:
586                 for t in \
587                         binlog.binlog_mysqlbinlog_filter \
588                         binlog.binlog_xa_prepared_disconnect \
589                         funcs_1.is_columns_mysql \
590                         funcs_1.is_tables_mysql \
591                         funcs_1.is_triggers \
592                         innodb.innodb_pagesize_max_recordsize \
593                         innodb.innodb-system-table-view \
594                         innodb.mysqldump_max_recordsize \
595                         main.mysql_client_test \
596                         main.mysqld--help-notwin \
597                         main.type_string \
598                         main.information_schema \
599                         perfschema.binlog_edge_mix \
600                         perfschema.binlog_edge_stmt \
601                         rpl.rpl_xa_survive_disconnect \
602                         rpl.rpl_xa_survive_disconnect_lsu_off \
603                         rpl.rpl_xa_survive_disconnect_table \
604                 ; do
605                         _disable_test "$t" "Requires DEFAULT_CHARSET=latin1 but USE=-latin1 is set"
606                 done
607         fi
608
609         if has_version '>=dev-libs/openssl-1.1.1' ; then
610                 # Tests are expecting <openssl-1.1.1 default cipher
611                 for t in \
612                         auth_sec.cert_verify \
613                         auth_sec.mysql_ssl_connection \
614                         auth_sec.openssl_cert_generation \
615                         auth_sec.ssl_auto_detect \
616                         auth_sec.ssl_mode \
617                         auth_sec.tls \
618                         binlog.binlog_grant_alter_user \
619                         encryption.innodb_onlinealter_encryption \
620                         main.grant_alter_user_qa \
621                         main.grant_user_lock_qa \
622                         main.mysql_ssl_default \
623                         main.openssl_1 \
624                         main.plugin_auth_sha256_tls \
625                         main.ssl \
626                         main.ssl_8k_key \
627                         main.ssl_bug75311 \
628                         main.ssl_ca \
629                         main.ssl_cipher \
630                         main.ssl_compress \
631                         main.ssl_crl \
632                         main.ssl_ecdh \
633                         main.ssl_verify_identity \
634                         x.connection_tls_version \
635                         x.connection_openssl \
636                 ; do
637                         _disable_test  "$t" "Requires <dev-libs/openssl-1.1.1"
638                 done
639         fi
640
641         # Try to increase file limits to increase test coverage
642         if ! ulimit -n 16500 1>/dev/null 2>&1 ; then
643                 # Upper limit comes from parts.partition_* tests
644                 ewarn "For maximum test coverage please raise open file limit to 16500 (ulimit -n 16500) before calling the package manager."
645
646                 if ! ulimit -n 4162 1>/dev/null 2>&1 ; then
647                         # Medium limit comes from '[Warning] Buffered warning: Could not increase number of max_open_files to more than 3000 (request: 4162)'
648                         ewarn "For medium test coverage please raise open file limit to 4162 (ulimit -n 4162) before calling the package manager."
649
650                         if ! ulimit -n 3000 1>/dev/null 2>&1 ; then
651                                 ewarn "For minimum test coverage please raise open file limit to 3000 (ulimit -n 3000) before calling the package manager."
652                         else
653                                 einfo "Will run test suite with open file limit set to 3000 (minimum test coverage)."
654                         fi
655                 else
656                         einfo "Will run test suite with open file limit set to 4162 (medium test coverage)."
657                 fi
658         else
659                 einfo "Will run test suite with open file limit set to 16500 (best test coverage)."
660         fi
661
662         # run mysql-test tests
663         perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
664         retstatus_tests=$?
665
666         popd &>/dev/null || die
667
668         # Cleanup is important for these testcases.
669         pkill -9 -f "${S}/ndb" 2>/dev/null
670         pkill -9 -f "${S}/sql" 2>/dev/null
671
672         local failures=""
673         [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
674         [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
675
676         [[ -z "$failures" ]] || die "Test failures: $failures"
677         einfo "Tests successfully completed"
678 }
679
680 src_install() {
681         local MULTILIB_WRAPPED_HEADERS
682         local MULTILIB_CHOST_TOOLS
683         if use client-libs ; then
684                 # headers with ABI specific data
685                 MULTILIB_WRAPPED_HEADERS=(
686                         /usr/include/mysql/server/my_config.h
687                         /usr/include/mysql/server/mysql_version.h )
688
689                 # wrap the config scripts
690                 MULTILIB_CHOST_TOOLS=( /usr/bin/mysql_config )
691                 multilib-minimal_src_install
692         else
693                 multilib_src_install
694                 multilib_src_install_all
695         fi
696 }
697
698 # Intentionally override eclass function
699 multilib_src_install() {
700
701         cmake-utils_src_install
702
703         # Kill old libmysqclient_r symlinks if they exist. Time to fix what depends on them.
704         find "${D}" -name 'libmysqlclient_r.*' -type l -delete || die
705 }
706
707 multilib_src_install_all() {
708         # Make sure the vars are correctly initialized
709         mysql_init_vars
710
711         # Convenience links
712         einfo "Making Convenience links for mysqlcheck multi-call binary"
713         dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
714         dosym "mysqlcheck" "/usr/bin/mysqlrepair"
715         dosym "mysqlcheck" "/usr/bin/mysqloptimize"
716
717         # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
718         if [[ -d "${ED}/usr/data" ]] ; then
719                 rm -Rf "${ED}/usr/data" || die
720         fi
721
722         # Unless they explicitly specific USE=test, then do not install the
723         # testsuite. It DOES have a use to be installed, esp. when you want to do a
724         # validation of your database configuration after tuning it.
725         if ! use test ; then
726                 rm -rf "${D}/${MY_SHAREDSTATEDIR}/mysql-test"
727         fi
728
729         # Configuration stuff
730         einfo "Building default configuration ..."
731         insinto "${MY_SYSCONFDIR#${EPREFIX}}"
732         [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
733         cp "${FILESDIR}/my.cnf-5.7" "${TMPDIR}/my.cnf" || die
734         eprefixify "${TMPDIR}/my.cnf"
735         doins "${TMPDIR}/my.cnf"
736         insinto "${MY_SYSCONFDIR#${EPREFIX}}/mysql.d"
737         cp "${FILESDIR}/my.cnf.distro-client" "${TMPDIR}/50-distro-client.cnf" || die
738         eprefixify "${TMPDIR}/50-distro-client.cnf"
739         doins "${TMPDIR}/50-distro-client.cnf"
740
741         if use server ; then
742                 mycnf_src="my.cnf.distro-server"
743                 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
744                         "${FILESDIR}/${mycnf_src}" \
745                         > "${TMPDIR}/my.cnf.ok" || die
746
747                 if use prefix ; then
748                         sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' \
749                                 "${TMPDIR}/my.cnf.ok" || die
750                 fi
751
752                 if use latin1 ; then
753                         sed -i \
754                                 -e "/character-set/s|utf8|latin1|g" \
755                                 "${TMPDIR}/my.cnf.ok" || die
756                 fi
757
758                 eprefixify "${TMPDIR}/my.cnf.ok"
759
760                 newins "${TMPDIR}/my.cnf.ok" 50-distro-server.cnf
761         fi
762
763         #Remove mytop if perl is not selected
764         [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
765 }
766
767 pkg_config() {
768         _getoptval() {
769                 local mypd="${EROOT%/}"/usr/bin/my_print_defaults
770                 local section="$1"
771                 local flag="--${2}="
772                 local extra_options="${3}"
773                 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
774         }
775         local old_MY_DATADIR="${MY_DATADIR}"
776         local old_HOME="${HOME}"
777         # my_print_defaults needs to read stuff in $HOME/.my.cnf
778         export HOME=${EPREFIX}/root
779
780         # Make sure the vars are correctly initialized
781         mysql_init_vars
782
783         [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
784         if [[ ! -x "${EROOT%/}/usr/sbin/mysqld" ]] ; then
785                 die "Minimal builds do NOT include the MySQL server"
786         fi
787
788         if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]] ; then
789                 local MY_DATADIR_s="${ROOT%/}/${MY_DATADIR}"
790                 MY_DATADIR_s="${MY_DATADIR_s%%/}"
791                 local old_MY_DATADIR_s="${ROOT%/}/${old_MY_DATADIR}"
792                 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
793
794                 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]] ; then
795                         if [[ -d "${MY_DATADIR_s}" ]] ; then
796                                 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
797                                 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
798                         else
799                                 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
800                                 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
801                                 || die "Moving MY_DATADIR failed"
802                         fi
803                 else
804                         ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
805                         if [[ -d "${MY_DATADIR_s}" ]] ; then
806                                 ewarn "Attempting to use ${MY_DATADIR_s}"
807                         else
808                                 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
809                                 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
810                         fi
811                 fi
812         fi
813
814         local pwd1="a"
815         local pwd2="b"
816         local maxtry=15
817
818         if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
819                 local tmp_mysqld_password_source=
820
821                 for tmp_mysqld_password_source in mysql client ; do
822                         einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
823                         MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
824                         if [[ -n "${MYSQL_ROOT_PASSWORD}" ]] ; then
825                                 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]] ; then
826                                         ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
827                                         MYSQL_ROOT_PASSWORD=
828                                         continue
829                                 fi
830
831                                 einfo "Found password in '${tmp_mysqld_password_source}' section!"
832                                 break
833                         fi
834                 done
835
836                 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
837                 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]] ; then
838                         MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
839                 fi
840
841                 unset tmp_mysqld_password_source
842         fi
843         MYSQL_TMPDIR="$(_getoptval mysqld tmpdir)"
844         # These are dir+prefix
845         MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log)"
846         MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
847         MYSQL_LOG_BIN="$(_getoptval mysqld log-bin)"
848         MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
849
850         if [[ ! -d "${EROOT%/}/$MYSQL_TMPDIR" ]] ; then
851                 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
852                 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_TMPDIR"
853         fi
854
855         if [[ ! -d "${EROOT%/}/$MYSQL_LOG_BIN" ]] ; then
856                 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
857                 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_LOG_BIN"
858         fi
859
860         if [[ ! -d "${EROOT%/}/$MYSQL_RELAY_LOG" ]] ; then
861                 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
862                 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_RELAY_LOG"
863         fi
864
865         if [[ -d "${ROOT%/}/${MY_DATADIR}/mysql" ]] ; then
866                 ewarn "You have already a MySQL database in place."
867                 ewarn "(${ROOT%/}/${MY_DATADIR}/*)"
868                 ewarn "Please rename or delete it if you wish to replace it."
869                 die "MySQL database already exists!"
870         fi
871
872         # Bug #213475 - MySQL _will_ object strenously if your machine is named
873         # localhost. Also causes weird failures.
874         [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
875
876         if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
877
878                 einfo "Please provide a password for the mysql 'root' user now"
879                 einfo "or through the ${HOME}/.my.cnf file."
880                 ewarn "Avoid [\"'\\_%] characters in the password"
881                 read -rsp "    >" pwd1 ; echo
882
883                 einfo "Retype the password"
884                 read -rsp "    >" pwd2 ; echo
885
886                 if [[ "x$pwd1" != "x$pwd2" ]] ; then
887                         die "Passwords are not the same"
888                 fi
889                 MYSQL_ROOT_PASSWORD="${pwd1}"
890                 unset pwd1 pwd2
891         fi
892
893         local options
894         local sqltmp="$(emktemp)"
895
896         # Fix bug 446200. Don't reference host my.cnf, needs to come first,
897         # see http://bugs.mysql.com/bug.php?id=31312
898         use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
899
900         # Figure out which options we need to disable to do the setup
901         local helpfile="${TMPDIR%/}/mysqld-help"
902         "${EROOT%/}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
903         for opt in host-cache name-resolve networking slave-start \
904                 federated ssl log-bin relay-log slow-query-log external-locking \
905                 log-slave-updates \
906                 ; do
907                 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
908                 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
909         done
910
911         einfo "Creating the mysql database and setting proper permissions on it ..."
912
913         # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
914         PID_DIR="${EROOT%/}/var/run/mysqld"
915         if [[ ! -d "${PID_DIR}" ]] ; then
916                 install -d -m 755 -o mysql -g mysql "${PID_DIR}" || die "Could not create pid directory"
917         fi
918
919         if [[ ! -d "${MY_DATADIR}" ]] ; then
920                 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
921         fi
922
923         pushd "${TMPDIR}" &>/dev/null || die
924
925         # Filling timezones, see
926         # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
927         echo "USE mysql;" >"${sqltmp}"
928         "${EROOT%/}/usr/bin/mysql_tzinfo_to_sql" "${EROOT%/}/usr/share/zoneinfo" >> "${sqltmp}" 2>/dev/null
929         chown mysql "${sqltmp}" || die
930
931         # --initialize-insecure will not set root password
932         # --initialize would set a random one in the log which we don't need as we set it ourselves
933         local cmd=( "${EROOT%/}/usr/sbin/mysqld" "--initialize-insecure" "--init-file='${sqltmp}'" )
934         cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT%/}${MY_DATADIR}" "--tmpdir=${ROOT%/}${MYSQL_TMPDIR}" )
935         einfo "Command: ${cmd[*]}"
936         su -s /bin/sh -c "${cmd[*]}" mysql \
937                 >"${TMPDIR%/}"/mysql_install_db.log 2>&1
938         if [[ $? -ne 0 ]] ; then
939                 grep -B5 -A999 -i "ERROR" "${TMPDIR%/}"/mysql_install_db.log 1>&2
940                 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR%/}/mysql_install_db.log"
941         fi
942         popd &>/dev/null || die
943         [[ -f "${ROOT%/}/${MY_DATADIR}/mysql/user.frm" ]] \
944         || die "MySQL databases not installed"
945
946         use prefix || options="${options} --user=mysql"
947
948         local socket="${EROOT%/}/var/run/mysqld/mysqld${RANDOM}.sock"
949         local pidfile="${EROOT%/}/var/run/mysqld/mysqld${RANDOM}.pid"
950         local mysqld="${EROOT%/}/usr/sbin/mysqld \
951                 ${options} \
952                 $(use prefix || echo --user=mysql) \
953                 --log-warnings=0 \
954                 --basedir=${EROOT%/}/usr \
955                 --datadir=${ROOT%/}/${MY_DATADIR} \
956                 --max_allowed_packet=8M \
957                 --net_buffer_length=16K \
958                 --socket=${socket} \
959                 --pid-file=${pidfile} \
960                 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
961         #einfo "About to start mysqld: ${mysqld}"
962         ebegin "Starting mysqld"
963         einfo "Command ${mysqld}"
964         ${mysqld} &
965         rc=$?
966         while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
967                 maxtry=$((${maxtry}-1))
968                 echo -n "."
969                 sleep 1
970         done
971         eend $rc
972
973         if ! [[ -S "${socket}" ]] ; then
974                 die "Completely failed to start up mysqld with: ${mysqld}"
975         fi
976
977         ebegin "Setting root password"
978         # Do this from memory, as we don't want clear text passwords in temp files
979         local sql="ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${MYSQL_ROOT_PASSWORD}'"
980         "${EROOT%/}/usr/bin/mysql" \
981                 --no-defaults \
982                 "--socket=${socket}" \
983                 -hlocalhost \
984                 -e "${sql}"
985         eend $?
986
987         # Stop the server and cleanup
988         einfo "Stopping the server ..."
989         kill $(< "${pidfile}" )
990         rm -f "${sqltmp}"
991         wait %1
992         einfo "Done"
993 }