1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 MY_EXTRAS_VER="20180529-0042Z"
8 JAVA_PKG_OPT_USE="jdbc"
10 # Keeping eutils in EAPI=6 for emktemp in pkg_config
12 inherit eutils systemd flag-o-matic prefix toolchain-funcs \
13 java-pkg-opt-2 user cmake-utils multilib-build
15 SRC_URI="https://downloads.mariadb.org/interstitial/${P}/source/${P}.tar.gz "
17 # Gentoo patches to MySQL
18 if [[ "${MY_EXTRAS_VER}" != "live" && "${MY_EXTRAS_VER}" != "none" ]]; then
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"
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"
37 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
38 RESTRICT="!bindist? ( bindist ) libressl? ( test )"
40 REQUIRED_USE="jdbc? ( extraengine server !static )
41 server? ( tokudb? ( jemalloc !tcmalloc ) )
42 ?? ( tcmalloc jemalloc )
43 static? ( yassl !pam )"
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"
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
52 if [[ "${MY_EXTRAS_VER}" == "live" ]] ; then
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"
59 MY_PATCH_DIR="${WORKDIR%/}/mysql-extras-${MY_EXTRAS_VER}"
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
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
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= )
87 !libressl? ( >=dev-libs/openssl-1.0.0:0= )
88 libressl? ( dev-libs/libressl:0= )
92 sys-libs/binutils-libs:0=
93 >=sys-libs/readline-4.1:0=
96 backup? ( app-arch/libarchive:0= )
97 cracklib? ( sys-libs/cracklib:0= )
99 odbc? ( dev-db/unixODBC:0= )
100 xml? ( dev-libs/libxml2:2= )
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 )
112 >=dev-libs/libpcre-8.41-r1:3=
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 ) ) )
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
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] )
131 perl? ( !dev-db/mytop
132 virtual/perl-Getopt-Long
134 virtual/perl-Term-ANSIColor
135 virtual/perl-Time-HiRes )
136 server? ( extraengine? ( jdbc? ( >=virtual/jre-1.6 ) ) )
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 ) ) ) )"
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."
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."
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."
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"
177 java-pkg-opt-2_pkg_preinst
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"
192 # Make sure the vars are correctly initialized
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}"
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/"
207 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
209 elog "You might want to run:"
210 elog "\"emerge --config =${CATEGORY}/${PF}\""
211 elog "if this is a new install."
213 elog "If you are switching server implentations, you should run the"
214 elog "mysql_upgrade tool."
218 elog "If you are upgrading major versions, you should run the"
219 elog "mysql_upgrade tool."
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."
234 # Note about configuration change
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]."
247 # Initialize the proper variables first
252 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
254 mv -f "${WORKDIR}/${P/_rc/}" "${S}" || die
259 echo > "${S%/}/plugin/${1}/CMakeLists.txt" || die
262 echo > "${S%/}/storage/${1}/CMakeLists.txt" || die
265 java-pkg-opt-2_src_prepare
266 if use tcmalloc; then
267 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
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
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}"
286 if ! use test; then # These plugins are only used during testing
287 for plugin in "${test_plugins[@]}" ; do
288 _disable_plugin "${plugin}"
290 _disable_engine test_sql_discovery
293 _disable_engine example
295 if ! use oqgraph ; then # avoids extra library checks
296 _disable_engine oqgraph
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"
304 _disable_engine mroonga
307 cmake-utils_src_prepare
311 # bug 508724 mariadb cannot use ld.gold
313 # Bug #114895, bug #110149
314 filter-flags "-O" "-O[01]"
316 append-cxxflags -felide-constructors
318 # bug #283926, with GCC4.4, this is required to get correct behavior.
319 append-flags -fno-strict-aliasing
321 CMAKE_BUILD_TYPE="RelWithDebInfo"
323 # debug hack wrt #497532
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"
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)
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=""
364 -DWITHOUT_CLIENTLIBS=YES
365 -DCLIENT_PLUGIN_DIALOG=OFF
366 -DCLIENT_PLUGIN_AUTH_GSSAPI_CLIENT=OFF
367 -DCLIENT_PLUGIN_MYSQL_CLEAR_PASSWORD=STATIC
370 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mariadb/mysql-test )
372 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
375 if ! use yassl ; then
376 mycmakeargs+=( -DWITH_SSL=system -DCLIENT_PLUGIN_SHA256_PASSWORD=STATIC )
378 mycmakeargs+=( -DWITH_SSL=bundled )
381 # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
383 -DWITH_READLINE=$(usex bindist 1 0)
384 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
385 -DENABLE_DTRACE=$(usex systemtap)
390 # Federated{,X} must be treated special otherwise they will not be built as plugins
391 if ! use extraengine ; then
393 -DPLUGIN_FEDERATED=NO
394 -DPLUGIN_FEDERATEDX=NO )
398 -DWITH_JEMALLOC=$(usex jemalloc 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)
430 # Workaround for MDEV-14524
431 use tokudb && mycmakeargs+=( -DTOKUDB_OK=1 )
434 # This is needed for the new client lib which tests a real, open server
435 mycmakeargs+=( -DSKIP_TESTS=ON )
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."
444 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
445 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
448 elif ! use latin1 ; then
450 -DDEFAULT_CHARSET=utf8
451 -DDEFAULT_COLLATION=utf8_general_ci
455 -DDEFAULT_CHARSET=latin1
456 -DDEFAULT_COLLATION=latin1_swedish_ci
462 -DDISABLE_SHARED=$(usex static YES NO)
463 -DWITH_DEBUG=$(usex debug)
464 -DWITH_EMBEDDED_SERVER=OFF
465 -DWITH_PROFILING=$(usex profiling)
469 mycmakeargs+=( -DWITH_PIC=1 )
472 if use jemalloc || use tcmalloc ; then
473 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
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
491 -DWITH_EMBEDDED_SERVER=OFF
492 -DEXTRA_CHARSETS=none
493 -DINSTALL_SQLBENCHDIR=
498 cmake-utils_src_configure
502 cmake-utils_src_compile
506 cmake-utils_src_install
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
513 # Make sure the vars are correctly initialized
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"
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
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.
531 rm -rf "${D}/${MY_SHAREDSTATEDIR}/mysql-test"
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"
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
552 sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' \
553 "${TMPDIR}/my.cnf.ok" || die
557 -e "/character-set/s|utf8|latin1|g" \
558 "${TMPDIR}/my.cnf.ok" || die
560 eprefixify "${TMPDIR}/my.cnf.ok"
561 newins "${TMPDIR}/my.cnf.ok" 50-distro-server.cnf
563 einfo "Including support files and sample configurations"
564 docinto "support-files"
567 "${S}"/support-files/magic
569 [[ -f "$script" ]] && dodoc "${script}"
573 for script in "${S}"/scripts/mysql* ; do
574 [[ ( -f "$script" ) && ( "${script%.sh}" == "${script}" ) ]] && dodoc "${script}"
578 #Remove mytop if perl is not selected
579 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
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
590 local rawtestname reason
591 rawtestname="${1}" ; shift
593 ewarn "test '${rawtestname}' disabled: '${reason}'"
594 echo ${rawtestname} : ${reason} >> "${T}/disabled.def"
597 local TESTDIR="${BUILD_DIR}/mysql-test"
599 local retstatus_tests
601 if ! use server ; then
602 einfo "Skipping server tests due to minimal build."
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"
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."
613 has usersandbox $FEATURES && ewarn "Some tests may fail with FEATURES=usersandbox"
615 einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
617 # Run CTest (test-units)
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}"
628 # create directories because mysqladmin might run out of order
629 mkdir -p "${T}"/var-tests{,/log} || die
632 pushd "${TESTDIR}" > /dev/null || die
634 touch "${T}/disabled.def"
635 # These are failing in MariaDB 10.0 for now and are believed to be
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.
643 for t in plugins.cracklib_password_check plugins.two_password_validations ; do
644 _disable_test "$t" "False positive due to varying policies"
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"
652 _disable_test main.plugin_auth "Needs client libraries built"
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"
658 popd > /dev/null || die
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
665 [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
666 [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
668 [[ -z "$failures" ]] || die "Test failures: $failures"
669 einfo "Tests successfully completed"
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"}
678 if [[ -z "${MY_DATADIR}" ]] ; then
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' \
684 if [[ -z "${MY_DATADIR}" ]] ; then
685 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
686 | sed -e 's/.*=\s*//' \
690 if [[ -z "${MY_DATADIR}" ]] ; then
691 MY_DATADIR="${MY_LOCALSTATEDIR}"
692 einfo "Using default MY_DATADIR"
694 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
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"
703 PREVIOUS_DATADIR="no"
705 export PREVIOUS_DATADIR
708 if [[ ${EBUILD_PHASE} == "config" ]]; then
710 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
711 | sed -ne '/datadir/s|^--datadir=||p' \
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}"
723 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
724 export MY_LOCALSTATEDIR MY_LOGDIR
730 local mypd="${EROOT}"/usr/bin/my_print_defaults
733 local extra_options="${3}"
734 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
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
741 # Make sure the vars are correctly initialized
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"
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%%/}"
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}"
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"
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}"
769 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
770 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
779 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
780 local tmp_mysqld_password_source=
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?)!"
792 einfo "Found password in '${tmp_mysqld_password_source}' section!"
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)"
802 unset tmp_mysqld_password_source
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%/*}
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"
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"
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"
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!"
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"
835 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
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
842 einfo "Retype the password"
843 read -rsp " >" pwd2 ; echo
845 if [[ "x$pwd1" != "x$pwd2" ]] ; then
846 die "Passwords are not the same"
848 MYSQL_ROOT_PASSWORD="${pwd1}"
853 local sqltmp="$(emktemp)"
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'"
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 \
866 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
867 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
870 einfo "Creating the mysql database and setting proper permissions on it ..."
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"
878 if [[ ! -d "${MY_DATADIR}" ]]; then
879 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
882 pushd "${TMPDIR}" &>/dev/null || die
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
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"
898 popd &>/dev/null || die
899 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
900 || die "MySQL databases not installed"
902 use prefix || options="${options} --user=mysql"
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 \
909 --basedir=${EROOT}/usr \
910 --datadir=${ROOT}/${MY_DATADIR} \
911 --max_allowed_packet=8M \
912 --net_buffer_length=16K \
914 --pid-file=${pidfile}
915 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
916 #einfo "About to start mysqld: ${mysqld}"
917 ebegin "Starting mysqld"
918 einfo "Command ${mysqld}"
921 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
922 maxtry=$((${maxtry}-1))
928 if ! [[ -S "${socket}" ]]; then
929 die "Completely failed to start up mysqld with: ${mysqld}"
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}" \
941 if [[ -n "${sqltmp}" ]] ; then
942 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
943 "${EROOT}/usr/bin/mysql" \
944 "--socket=${socket}" \
947 --password="${MYSQL_ROOT_PASSWORD}" \
951 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
954 # Stop the server and cleanup
955 einfo "Stopping the server ..."
956 kill $(< "${pidfile}" )