mysql-multilib-r1.eclass 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: mysql-multilib.eclass
  4. # @MAINTAINER:
  5. # Maintainers:
  6. # - MySQL Team <mysql-bugs@gentoo.org>
  7. # - Robin H. Johnson <robbat2@gentoo.org>
  8. # - Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
  9. # - Brian Evans <grknight@gentoo.org>
  10. # @BLURB: This eclass provides common functions for mysql ebuilds
  11. # @DESCRIPTION:
  12. # The mysql-multilib-r1.eclass is the base eclass to build the mysql and
  13. # alternative projects (mariadb and percona) ebuilds.
  14. # Provider and version specific settings will be included in each ebuild.
  15. # It provides the src_unpack, src_prepare, src_configure, src_compile,
  16. # src_install, pkg_preinst, pkg_postinst, pkg_config and pkg_postrm
  17. # phase hooks.
  18. MYSQL_EXTRAS=""
  19. # @ECLASS-VARIABLE: MYSQL_EXTRAS_VER
  20. # @DESCRIPTION:
  21. # The version of the MYSQL_EXTRAS repo to use to build mysql
  22. # Use "none" to disable it's use
  23. [[ ${MY_EXTRAS_VER} == "live" ]] && MYSQL_EXTRAS="git-r3"
  24. # @ECLASS-VARIABLE: MYSQL_CMAKE_NATIVE_DEFINES
  25. # @DESCRIPTION:
  26. # An array of extra CMake arguments for native multilib builds
  27. # @ECLASS-VARIABLE: MYSQL_CMAKE_NONNATIVE_DEFINES
  28. # @DESCRIPTION:
  29. # An array of extra CMake arguments for non-native multilib builds
  30. # @ECLASS-VARIABLE: MYSQL_CMAKE_EXTRA_DEFINES
  31. # @DESCRIPTION:
  32. # An array of CMake arguments added to native and non-native
  33. # Keeping eutils in EAPI=6 for emktemp in pkg_config
  34. inherit eutils systemd flag-o-matic ${MYSQL_EXTRAS} versionator \
  35. prefix toolchain-funcs user cmake-utils multilib-minimal
  36. if [[ "${EAPI}x" == "5x" ]]; then
  37. inherit multilib mysql_fx
  38. fi
  39. #
  40. # Supported EAPI versions and export functions
  41. #
  42. case "${EAPI:-0}" in
  43. 5|6) ;;
  44. *) die "Unsupported EAPI: ${EAPI}" ;;
  45. esac
  46. EXPORT_FUNCTIONS pkg_pretend pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config
  47. #
  48. # VARIABLES:
  49. #
  50. # Shorten the path because the socket path length must be shorter than 107 chars
  51. # and we will run a mysql server during test phase
  52. S="${WORKDIR}/mysql"
  53. [[ ${MY_EXTRAS_VER} == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
  54. if [[ ${MY_EXTRAS_VER} == "live" ]]; then
  55. EGIT_REPO_URI="git://anongit.gentoo.org/proj/mysql-extras.git"
  56. EGIT_CHECKOUT_DIR=${WORKDIR}/mysql-extras
  57. EGIT_CLONE_TYPE=shallow
  58. fi
  59. # @ECLASS-VARIABLE: MYSQL_PV_MAJOR
  60. # @DESCRIPTION:
  61. # Upstream MySQL considers the first two parts of the version number to be the
  62. # major version. Upgrades that change major version should always run
  63. # mysql_upgrade.
  64. if [[ -z ${MYSQL_PV_MAJOR} ]] ; then MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})" ; fi
  65. # @ECLASS-VARIABLE: MYSQL_VERSION_ID
  66. # @DESCRIPTION:
  67. # MYSQL_VERSION_ID will be:
  68. # major * 10e6 + minor * 10e4 + micro * 10e2 + gentoo revision number, all [0..99]
  69. # This is an important part, because many of the choices the MySQL ebuild will do
  70. # depend on this variable.
  71. # In particular, the code below transforms a $PVR like "5.0.18-r3" in "5001803"
  72. # We also strip off upstream's trailing letter that they use to respin tarballs
  73. if [[ "${EAPI}x" == "5x" ]]; then
  74. MYSQL_VERSION_ID=""
  75. tpv="${PV%[a-z]}"
  76. tpv=( ${tpv//[-._]/ } ) ; tpv[3]="${PVR:${#PV}}" ; tpv[3]="${tpv[3]##*-r}"
  77. for vatom in 0 1 2 3 ; do
  78. # pad to length 2
  79. tpv[${vatom}]="00${tpv[${vatom}]}"
  80. MYSQL_VERSION_ID="${MYSQL_VERSION_ID}${tpv[${vatom}]:0-2}"
  81. done
  82. # strip leading "0" (otherwise it's considered an octal number by BASH)
  83. MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"}
  84. fi
  85. # Work out the default SERVER_URI correctly
  86. if [[ -z ${SERVER_URI} ]]; then
  87. if [[ ${PN} == "mariadb" ]]; then
  88. # Beginning with 5.5, MariaDB stopped putting beta, alpha or rc on their tarball names
  89. MARIA_FULL_PV=$(get_version_component_range 1-3)
  90. MARIA_FULL_P="${PN}-${MARIA_FULL_PV}"
  91. SERVER_URI="https://downloads.mariadb.org/interstitial/${MARIA_FULL_P}/source/${MARIA_FULL_P}.tar.gz"
  92. elif [[ ${PN} == "percona-server" ]]; then
  93. PERCONA_PN="Percona-Server"
  94. MIRROR_PV=$(get_version_component_range 1-2 ${PV})
  95. MY_PV=$(get_version_component_range 1-3 ${PV})
  96. PERCONA_RELEASE=$(get_version_component_range 4-5 ${PV})
  97. PERCONA_RC=$(get_version_component_range 6 ${PV})
  98. SERVER_URI="http://www.percona.com/redir/downloads/${PERCONA_PN}-${MIRROR_PV}/${PERCONA_PN}-${MY_PV}-${PERCONA_RC}${PERCONA_RELEASE}/source/tarball/${PN}-${MY_PV}-${PERCONA_RC}${PERCONA_RELEASE}.tar.gz"
  99. else
  100. if [[ "${PN}" == "mysql-cluster" ]] ; then
  101. URI_DIR="MySQL-Cluster"
  102. URI_FILE="mysql-cluster-gpl"
  103. else
  104. URI_DIR="MySQL"
  105. URI_FILE="mysql"
  106. fi
  107. [[ -z ${MY_PV} ]] && MY_PV="${PV//_/-}"
  108. URI_A="${URI_FILE}-${MY_PV}.tar.gz"
  109. MIRROR_PV=$(get_version_component_range 1-2 ${PV})
  110. # Recently upstream switched to an archive site, and not on mirrors
  111. SERVER_URI="http://cdn.mysql.com/Downloads/${URI_DIR}-${MIRROR_PV}/${URI_A}
  112. http://downloads.mysql.com/archives/${URI_DIR}-${MIRROR_PV}/${URI_A}"
  113. fi
  114. fi
  115. # Define correct SRC_URIs
  116. SRC_URI="${SERVER_URI}"
  117. # Gentoo patches to MySQL
  118. if [[ ${MY_EXTRAS_VER} != "live" && ${MY_EXTRAS_VER} != "none" ]]; then
  119. SRC_URI="${SRC_URI}
  120. mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
  121. https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
  122. https://dev.gentoo.org/~grknight/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
  123. https://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
  124. https://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
  125. fi
  126. DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
  127. HOMEPAGE="http://www.mysql.com/"
  128. LICENSE="GPL-2"
  129. SLOT="0/${SUBSLOT:-0}"
  130. IUSE="debug embedded extraengine jemalloc latin1 libressl +openssl
  131. +perl profiling selinux +server systemtap static static-libs tcmalloc test yassl"
  132. REQUIRED_USE="^^ ( yassl openssl libressl )"
  133. # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
  134. RESTRICT="libressl? ( test )"
  135. REQUIRED_USE="${REQUIRED_USE} !server? ( !extraengine !embedded )
  136. ?? ( tcmalloc jemalloc )
  137. static? ( !libressl !openssl yassl )"
  138. #
  139. # DEPENDENCIES:
  140. #
  141. # Be warned, *DEPEND are version-dependant
  142. # These are used for both runtime and compiletime
  143. # MULTILIB_USEDEP only set for libraries used by the client library
  144. DEPEND="
  145. kernel_linux? (
  146. sys-process/procps:0=
  147. dev-libs/libaio:0=
  148. )
  149. >=sys-apps/sed-4
  150. >=sys-apps/texinfo-4.7-r1
  151. !dev-db/mariadb-native-client[mysqlcompat]
  152. jemalloc? ( dev-libs/jemalloc:0= )
  153. tcmalloc? ( dev-util/google-perftools:0= )
  154. systemtap? ( >=dev-util/systemtap-1.3:0= )
  155. openssl? ( >=dev-libs/openssl-1.0.0:0=[${MULTILIB_USEDEP},static-libs?] )
  156. libressl? ( dev-libs/libressl:0=[${MULTILIB_USEDEP},static-libs?] )
  157. >=sys-libs/zlib-1.2.3:0=[${MULTILIB_USEDEP},static-libs?]
  158. sys-libs/ncurses:0=
  159. "
  160. # prefix: first need to implement something for #196294
  161. RDEPEND="${DEPEND}
  162. selinux? ( sec-policy/selinux-mysql )
  163. abi_x86_32? ( !app-emulation/emul-linux-x86-db[-abi_x86_32(-)] )
  164. "
  165. # Having different flavours at the same time is not a good idea
  166. for i in "mysql" "mariadb" "mariadb-galera" "percona-server" "mysql-cluster" ; do
  167. [[ ${i} == ${PN} ]] ||
  168. RDEPEND="${RDEPEND} !dev-db/${i}"
  169. done
  170. RDEPEND="${RDEPEND}
  171. server? ( !prefix? ( dev-db/mysql-init-scripts ) )
  172. !<virtual/mysql-5.6-r4"
  173. # compile-time-only
  174. # ncurses only needs multilib for compile time due to a binary that will be not installed
  175. DEPEND="${DEPEND}
  176. virtual/yacc
  177. static? ( sys-libs/ncurses[static-libs] )
  178. "
  179. # For other stuff to bring us in
  180. # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
  181. PDEPEND="${PDEPEND} perl? ( >=dev-perl/DBD-mysql-2.9004 )
  182. server? ( ~virtual/mysql-${MYSQL_PV_MAJOR}[embedded=,static=] )
  183. virtual/libmysqlclient:${SLOT}[${MULTILIB_USEDEP},static-libs=]"
  184. # my_config.h includes ABI specific data
  185. MULTILIB_WRAPPED_HEADERS=( /usr/include/mysql/my_config.h /usr/include/mysql/private/embedded_priv.h )
  186. #
  187. # EBUILD FUNCTIONS
  188. #
  189. # @FUNCTION: mysql-multilib-r1_pkg_pretend
  190. # @DESCRIPTION:
  191. # Perform some basic tests and tasks during pkg_pretend phase:
  192. mysql-multilib-r1_pkg_pretend() {
  193. if [[ ${MERGE_TYPE} != binary ]] ; then
  194. local GCC_MAJOR_SET=$(gcc-major-version)
  195. local GCC_MINOR_SET=$(gcc-minor-version)
  196. if in_iuse tokudb && use tokudb && [[ ${GCC_MAJOR_SET} -lt 4 || \
  197. ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
  198. eerror "${PN} with tokudb needs to be built with gcc-4.7 or later."
  199. eerror "Please use gcc-config to switch to gcc-4.7 or later version."
  200. die
  201. fi
  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. # @FUNCTION: mysql-multilib-r1_pkg_setup
  213. # @DESCRIPTION:
  214. # Perform some basic tests and tasks during pkg_setup phase:
  215. # die if FEATURES="test", USE="server" and not using FEATURES="userpriv"
  216. # create new user and group for mysql
  217. # warn about deprecated features
  218. mysql-multilib-r1_pkg_setup() {
  219. if has test ${FEATURES} && \
  220. use server && ! has userpriv ${FEATURES} ; then
  221. eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
  222. fi
  223. # This should come after all of the die statements
  224. enewgroup mysql 60 || die "problem adding 'mysql' group"
  225. enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
  226. }
  227. # @FUNCTION: mysql-multilib-r1_src_unpack
  228. # @DESCRIPTION:
  229. # Unpack the source code
  230. mysql-multilib-r1_src_unpack() {
  231. # Initialize the proper variables first
  232. mysql_init_vars
  233. unpack ${A}
  234. # Grab the patches
  235. [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
  236. mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
  237. }
  238. # @FUNCTION: mysql-multilib-r1_src_prepare
  239. # @DESCRIPTION:
  240. # Apply patches to the source code and remove unneeded bundled libs.
  241. mysql-multilib-r1_src_prepare() {
  242. debug-print-function ${FUNCNAME} "$@"
  243. cd "${S}"
  244. if [[ ${MY_EXTRAS_VER} != none ]]; then
  245. # Apply the patches for this MySQL version
  246. if [[ "${EAPI}x" == "5x" ]]; then
  247. EPATCH_SUFFIX="patch"
  248. mkdir -p "${EPATCH_SOURCE}" || die "Unable to create epatch directory"
  249. # Clean out old items
  250. rm -f "${EPATCH_SOURCE}"/*
  251. # Now link in right patches
  252. mysql_mv_patches
  253. # And apply
  254. epatch
  255. fi
  256. fi
  257. # last -fPIC fixup, per bug #305873
  258. i="${S}"/storage/innodb_plugin/plug.in
  259. if [[ -f ${i} ]] ; then sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}" || die ; fi
  260. rm -f "scripts/mysqlbug"
  261. if use jemalloc && [[ ${PN} != "mariadb" ]] ; then
  262. echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
  263. fi
  264. if use tcmalloc; then
  265. echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
  266. fi
  267. if in_iuse tokudb ; then
  268. # Don't build bundled xz-utils
  269. if [[ -d "${S}/storage/tokudb/ft-index" ]] ; then
  270. echo > "${S}/storage/tokudb/ft-index/cmake_modules/TokuThirdParty.cmake" || die
  271. sed -i 's/ build_lzma//' "${S}/storage/tokudb/ft-index/ft/CMakeLists.txt" || die
  272. elif [[ -d "${S}/storage/tokudb/PerconaFT" ]] ; then
  273. echo > "${S}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
  274. sed -i -e 's/ build_lzma//' -e 's/ build_snappy//' "${S}/storage/tokudb/PerconaFT/ft/CMakeLists.txt" || die
  275. sed -i -e 's/add_dependencies\(tokuportability_static_conv build_jemalloc\)//' "${S}/storage/tokudb/PerconaFT/portability/CMakeLists.txt" || die
  276. fi
  277. if [[ -d "${S}/plugin/tokudb-backup-plugin" ]] && ! use tokudb-backup-plugin ; then
  278. rm -r "${S}/plugin/tokudb-backup-plugin/Percona-TokuBackup" || die
  279. fi
  280. fi
  281. # Remove the bundled groonga if it exists
  282. # There is no CMake flag, it simply checks for existance
  283. if [[ -d "${S}"/storage/mroonga/vendor/groonga ]] ; then
  284. rm -r "${S}"/storage/mroonga/vendor/groonga || die "could not remove packaged groonga"
  285. fi
  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. if [[ "${EAPI}x" == "5x" ]] ; then
  291. epatch_user
  292. else
  293. default
  294. fi
  295. }
  296. # @FUNCTION: mysql-multilib-r1_src_configure
  297. # @DESCRIPTION:
  298. # Configure mysql to build the code for Gentoo respecting the use flags.
  299. mysql-multilib-r1_src_configure() {
  300. # Bug #114895, bug #110149
  301. filter-flags "-O" "-O[01]"
  302. append-cxxflags -felide-constructors
  303. # bug #283926, with GCC4.4, this is required to get correct behavior.
  304. append-flags -fno-strict-aliasing
  305. multilib-minimal_src_configure
  306. }
  307. multilib_src_configure() {
  308. debug-print-function ${FUNCNAME} "$@"
  309. CMAKE_BUILD_TYPE="RelWithDebInfo"
  310. # debug hack wrt #497532
  311. mycmakeargs=(
  312. -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
  313. -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
  314. -DCMAKE_INSTALL_PREFIX=${EPREFIX}/usr
  315. -DMYSQL_DATADIR=${EPREFIX}/var/lib/mysql
  316. -DSYSCONFDIR=${EPREFIX}/etc/mysql
  317. -DINSTALL_BINDIR=bin
  318. -DINSTALL_DOCDIR=share/doc/${PF}
  319. -DINSTALL_DOCREADMEDIR=share/doc/${PF}
  320. -DINSTALL_INCLUDEDIR=include/mysql
  321. -DINSTALL_INFODIR=share/info
  322. -DINSTALL_LIBDIR=$(get_libdir)
  323. -DINSTALL_ELIBDIR=$(get_libdir)/mysql
  324. -DINSTALL_MANDIR=share/man
  325. -DINSTALL_MYSQLDATADIR=${EPREFIX}/var/lib/mysql
  326. -DINSTALL_MYSQLSHAREDIR=share/mysql
  327. -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
  328. -DINSTALL_SBINDIR=sbin
  329. -DINSTALL_SCRIPTDIR=share/mysql/scripts
  330. -DINSTALL_SQLBENCHDIR=share/mysql
  331. -DINSTALL_SUPPORTFILESDIR=${EPREFIX}/usr/share/mysql
  332. -DWITH_COMMENT="Gentoo Linux ${PF}"
  333. -DWITH_UNIT_TESTS=$(usex test ON OFF)
  334. -DWITH_LIBEDIT=0
  335. -DWITH_ZLIB=system
  336. -DWITHOUT_LIBWRAP=1
  337. -DENABLED_LOCAL_INFILE=1
  338. -DMYSQL_UNIX_ADDR=${EPREFIX}/var/run/mysqld/mysqld.sock
  339. -DINSTALL_UNIX_ADDRDIR=${EPREFIX}/var/run/mysqld/mysqld.sock
  340. -DWITH_DEFAULT_COMPILER_OPTIONS=0
  341. -DWITH_DEFAULT_FEATURE_SET=0
  342. -DINSTALL_SYSTEMD_UNITDIR="$(systemd_get_systemunitdir)"
  343. -DENABLE_STATIC_LIBS=$(usex static-libs ON OFF)
  344. # The build forces this to be defined when cross-compiling. We pass it
  345. # all the time for simplicity and to make sure it is actually correct.
  346. -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
  347. )
  348. if use test ; then
  349. mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
  350. else
  351. mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
  352. fi
  353. if in_iuse systemd ; then
  354. mycmakeargs+=( -DWITH_SYSTEMD=$(usex systemd) )
  355. fi
  356. if use openssl || use libressl ; then
  357. mycmakeargs+=( -DWITH_SSL=system )
  358. else
  359. mycmakeargs+=( -DWITH_SSL=bundled )
  360. fi
  361. if ! multilib_is_native_abi ; then
  362. mycmakeargs+=( -DWITHOUT_TOOLS=1 )
  363. fi
  364. if in_iuse bindist ; then
  365. # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
  366. if multilib_is_native_abi; then
  367. mycmakeargs+=(
  368. -DWITH_READLINE=$(usex bindist 1 0)
  369. -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
  370. )
  371. else
  372. mycmakeargs+=(
  373. -DWITH_READLINE=1
  374. -DNOT_FOR_DISTRIBUTION=0
  375. )
  376. fi
  377. fi
  378. ### TODO: make this system but issues with UTF-8 prevent it
  379. mycmakeargs+=( -DWITH_EDITLINE=bundled )
  380. if multilib_is_native_abi && use server ; then
  381. if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
  382. ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
  383. ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
  384. ewarn "You MUST file bugs without these variables set."
  385. mycmakeargs+=(
  386. -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
  387. -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
  388. )
  389. elif ! use latin1 ; then
  390. mycmakeargs+=(
  391. -DDEFAULT_CHARSET=utf8
  392. -DDEFAULT_COLLATION=utf8_general_ci
  393. )
  394. else
  395. mycmakeargs+=(
  396. -DDEFAULT_CHARSET=latin1
  397. -DDEFAULT_COLLATION=latin1_swedish_ci
  398. )
  399. fi
  400. mycmakeargs+=(
  401. -DEXTRA_CHARSETS=all
  402. -DMYSQL_USER=mysql
  403. -DMYSQL_UNIX_ADDR=${EPREFIX}/var/run/mysqld/mysqld.sock
  404. -DDISABLE_SHARED=$(usex static YES NO)
  405. -DWITH_DEBUG=$(usex debug)
  406. -DWITH_EMBEDDED_SERVER=$(usex embedded)
  407. -DWITH_PROFILING=$(usex profiling)
  408. )
  409. if use static; then
  410. mycmakeargs+=( -DWITH_PIC=1 )
  411. fi
  412. if use jemalloc || use tcmalloc ; then
  413. mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
  414. fi
  415. # Storage engines
  416. mycmakeargs+=(
  417. -DWITH_ARCHIVE_STORAGE_ENGINE=1
  418. -DWITH_BLACKHOLE_STORAGE_ENGINE=1
  419. -DWITH_CSV_STORAGE_ENGINE=1
  420. -DWITH_HEAP_STORAGE_ENGINE=1
  421. -DWITH_INNOBASE_STORAGE_ENGINE=1
  422. -DWITH_MYISAMMRG_STORAGE_ENGINE=1
  423. -DWITH_MYISAM_STORAGE_ENGINE=1
  424. -DWITH_PARTITION_STORAGE_ENGINE=1
  425. )
  426. mycmakeargs+=( -DWITH_FEDERATED_STORAGE_ENGINE=$(usex extraengine) )
  427. else
  428. mycmakeargs+=(
  429. -DWITHOUT_SERVER=1
  430. -DWITHOUT_EMBEDDED_SERVER=1
  431. -DEXTRA_CHARSETS=none
  432. -DINSTALL_SQLBENCHDIR=
  433. )
  434. fi
  435. # systemtap only works on native ABI bug 530132
  436. if multilib_is_native_abi; then
  437. mycmakeargs+=( -DENABLE_DTRACE=$(usex systemtap)
  438. "${MYSQL_CMAKE_NATIVE_DEFINES[@]}" )
  439. else
  440. mycmakeargs+=( -DENABLE_DTRACE=0
  441. "${MYSQL_CMAKE_NONNATIVE_DEFINES[@]}" )
  442. fi
  443. mycmakeargs+=( "${MYSQL_CMAKE_EXTRA_DEFINES[@]}" )
  444. cmake-utils_src_configure
  445. }
  446. mysql-multilib-r1_src_compile() {
  447. local _cmake_args=( "${@}" )
  448. multilib-minimal_src_compile
  449. }
  450. multilib_src_compile() {
  451. cmake-utils_src_compile "${_cmake_args[@]}"
  452. }
  453. # @FUNCTION: mysql-multilib-r1_src_install
  454. # @DESCRIPTION:
  455. # Install mysql.
  456. mysql-multilib-r1_src_install() {
  457. # wrap the config script
  458. MULTILIB_CHOST_TOOLS=( /usr/bin/mysql_config )
  459. multilib-minimal_src_install
  460. }
  461. multilib_src_install() {
  462. debug-print-function ${FUNCNAME} "$@"
  463. cmake-utils_src_install
  464. # Make sure the vars are correctly initialized
  465. mysql_init_vars
  466. # Remove an unnecessary, private config header which will never match between ABIs and is not meant to be used
  467. if [[ -f "${D}${MY_INCLUDEDIR}/private/config.h" ]] ; then
  468. rm "${D}${MY_INCLUDEDIR}/private/config.h" || die
  469. fi
  470. if multilib_is_native_abi; then
  471. # Convenience links
  472. einfo "Making Convenience links for mysqlcheck multi-call binary"
  473. dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlanalyze"
  474. dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlrepair"
  475. dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqloptimize"
  476. # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
  477. if [[ -d "${ED}/usr/data" ]] ; then
  478. rm -Rf "${ED}/usr/data" || die
  479. fi
  480. # Unless they explicitly specific USE=test, then do not install the
  481. # testsuite. It DOES have a use to be installed, esp. when you want to do a
  482. # validation of your database configuration after tuning it.
  483. if ! use test ; then
  484. rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
  485. fi
  486. # Configuration stuff
  487. case ${MYSQL_PV_MAJOR} in
  488. 5.5) mysql_mycnf_version="5.5" ;;
  489. 5.[6-9]|6*|7*|8*|9*|10*) mysql_mycnf_version="5.6" ;;
  490. esac
  491. einfo "Building default my.cnf (${mysql_mycnf_version})"
  492. insinto "${MY_SYSCONFDIR#${EPREFIX}}"
  493. [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
  494. mycnf_src="my.cnf-${mysql_mycnf_version}"
  495. sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
  496. "${FILESDIR}/${mycnf_src}" \
  497. > "${TMPDIR}/my.cnf.ok" || die
  498. use prefix && sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' "${TMPDIR}/my.cnf.ok"
  499. if use latin1 ; then
  500. sed -i \
  501. -e "/character-set/s|utf8|latin1|g" \
  502. "${TMPDIR}/my.cnf.ok" || die
  503. fi
  504. eprefixify "${TMPDIR}/my.cnf.ok"
  505. newins "${TMPDIR}/my.cnf.ok" my.cnf
  506. if use server ; then
  507. einfo "Creating initial directories"
  508. # Empty directories ...
  509. diropts "-m0750"
  510. if [[ ${PREVIOUS_DATADIR} != "yes" ]] ; then
  511. dodir "${MY_DATADIR#${EPREFIX}}"
  512. keepdir "${MY_DATADIR#${EPREFIX}}"
  513. chown -R mysql:mysql "${D}/${MY_DATADIR}"
  514. fi
  515. diropts "-m0755"
  516. for folder in "${MY_LOGDIR#${EPREFIX}}" ; do
  517. dodir "${folder}"
  518. keepdir "${folder}"
  519. chown -R mysql:mysql "${ED}/${folder}"
  520. done
  521. einfo "Including support files and sample configurations"
  522. docinto "support-files"
  523. for script in \
  524. "${S}"/support-files/my-*.cnf.sh \
  525. "${S}"/support-files/magic \
  526. "${S}"/support-files/ndb-config-2-node.ini.sh
  527. do
  528. [[ -f $script ]] && dodoc "${script}"
  529. done
  530. docinto "scripts"
  531. for script in "${S}"/scripts/mysql* ; do
  532. [[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
  533. done
  534. fi
  535. #Remove mytop if perl is not selected
  536. [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
  537. # Percona has decided to rename libmysqlclient to libperconaserverclient
  538. # Use a symlink to preserve linkages for those who don't use mysql_config
  539. local suffix
  540. for suffix in ".so" "_r.so" ".a" "_r.a" ; do
  541. if [[ -e "${ED}/usr/$(get_libdir)/libperconaserverclient${suffix}" ]] ; then
  542. dosym libperconaserverclient${suffix} /usr/$(get_libdir)/libmysqlclient${suffix}
  543. fi
  544. done
  545. else
  546. if [[ "${PN}" == "mariadb" ]] && use server ; then
  547. insinto /usr/include/mysql/private
  548. doins "${S}"/sql/*.h
  549. fi
  550. fi
  551. }
  552. # @FUNCTION: mysql-multilib-r1_pkg_preinst
  553. # @DESCRIPTION:
  554. # Warn about ABI changes when switching providers
  555. mysql-multilib-r1_pkg_preinst() {
  556. debug-print-function ${FUNCNAME} "$@"
  557. # Here we need to see if the implementation switched client libraries
  558. # We check if this is a new instance of the package and a client library already exists
  559. local SHOW_ABI_MESSAGE
  560. if [[ -z ${REPLACING_VERSIONS} && -e "${EROOT}usr/$(get_libdir)/libmysqlclient.so" ]] ; then
  561. elog "Due to ABI changes when switching between different client libraries,"
  562. elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
  563. elog "Please run: revdep-rebuild --library libmysqlclient.so.${SUBSLOT:-18}"
  564. ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
  565. fi
  566. }
  567. # @FUNCTION: mysql-multilib-r1_pkg_postinst
  568. # @DESCRIPTION:
  569. # Run post-installation tasks:
  570. # create the dir for logfiles if non-existant
  571. # touch the logfiles and secure them
  572. # install scripts
  573. # issue required steps for optional features
  574. # issue deprecation warnings
  575. mysql-multilib-r1_pkg_postinst() {
  576. debug-print-function ${FUNCNAME} "$@"
  577. # Make sure the vars are correctly initialized
  578. mysql_init_vars
  579. # Check FEATURES="collision-protect" before removing this
  580. [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
  581. # Secure the logfiles
  582. touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
  583. chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
  584. chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
  585. # Minimal builds don't have the MySQL server
  586. if use server ; then
  587. docinto "support-files"
  588. for script in \
  589. support-files/my-*.cnf \
  590. support-files/magic \
  591. support-files/ndb-config-2-node.ini
  592. do
  593. [[ -f "${script}" ]] \
  594. && dodoc "${script}"
  595. done
  596. docinto "scripts"
  597. for script in scripts/mysql* ; do
  598. if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
  599. dodoc "${script}"
  600. fi
  601. done
  602. if in_iuse pam && use pam; then
  603. einfo
  604. elog "This install includes the PAM authentication plugin."
  605. elog "To activate and configure the PAM plugin, please read:"
  606. if [[ ${PN} == "mariadb" ]] ; then
  607. elog "https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/"
  608. elif [[ ${PN} == "percona-server" ]] ; then
  609. elog "https://www.percona.com/doc/percona-server/5.6/management/pam_plugin.html"
  610. fi
  611. einfo
  612. fi
  613. if [[ -z "${REPLACING_VERSIONS}" ]] ; then
  614. einfo
  615. elog "You might want to run:"
  616. elog "\"emerge --config =${CATEGORY}/${PF}\""
  617. elog "if this is a new install."
  618. elog
  619. elog "If you are switching server implentations, you should run the"
  620. elog "mysql_upgrade tool."
  621. einfo
  622. else
  623. einfo
  624. elog "If you are upgrading major versions, you should run the"
  625. elog "mysql_upgrade tool."
  626. einfo
  627. fi
  628. if in_iuse galera && use galera ; then
  629. einfo
  630. elog "Be sure to edit the my.cnf file to activate your cluster settings."
  631. elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
  632. elog "The first time the cluster is activated, you should add"
  633. elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
  634. elog "This option should then be removed for subsequent starts."
  635. einfo
  636. fi
  637. fi
  638. }
  639. # @FUNCTION: mysql-multilib-r1_getopt
  640. # @DESCRIPTION:
  641. # Use my_print_defaults to extract specific config options
  642. mysql-multilib-r1_getopt() {
  643. local mypd="${EROOT}"/usr/bin/my_print_defaults
  644. section="$1"
  645. flag="--${2}="
  646. "${mypd}" $section | sed -n "/^${flag}/p"
  647. }
  648. # @FUNCTION: mysql-multilib-r1_getoptval
  649. # @DESCRIPTION:
  650. # Use my_print_defaults to extract specific config options
  651. mysql-multilib-r1_getoptval() {
  652. local mypd="${EROOT}"/usr/bin/my_print_defaults
  653. local section="$1"
  654. local flag="--${2}="
  655. local extra_options="${3}"
  656. "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
  657. }
  658. # @FUNCTION: mysql-multilib-r1_pkg_config
  659. # @DESCRIPTION:
  660. # Configure mysql environment.
  661. mysql-multilib-r1_pkg_config() {
  662. debug-print-function ${FUNCNAME} "$@"
  663. local old_MY_DATADIR="${MY_DATADIR}"
  664. local old_HOME="${HOME}"
  665. # my_print_defaults needs to read stuff in $HOME/.my.cnf
  666. export HOME=${EPREFIX}/root
  667. # Make sure the vars are correctly initialized
  668. mysql_init_vars
  669. [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
  670. if [[ ! -x "${EROOT}/usr/sbin/mysqld" ]] ; then
  671. die "Minimal builds do NOT include the MySQL server"
  672. fi
  673. if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
  674. local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
  675. MY_DATADIR_s="${MY_DATADIR_s%%/}"
  676. local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
  677. old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
  678. if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
  679. if [[ -d "${MY_DATADIR_s}" ]]; then
  680. ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
  681. ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
  682. else
  683. elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
  684. mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
  685. || die "Moving MY_DATADIR failed"
  686. fi
  687. else
  688. ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
  689. if [[ -d "${MY_DATADIR_s}" ]]; then
  690. ewarn "Attempting to use ${MY_DATADIR_s}"
  691. else
  692. eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
  693. die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
  694. fi
  695. fi
  696. fi
  697. local pwd1="a"
  698. local pwd2="b"
  699. local maxtry=15
  700. if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
  701. local tmp_mysqld_password_source=
  702. for tmp_mysqld_password_source in mysql client; do
  703. einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
  704. MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password)"
  705. if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
  706. if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
  707. ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
  708. MYSQL_ROOT_PASSWORD=
  709. continue
  710. fi
  711. einfo "Found password in '${tmp_mysqld_password_source}' section!"
  712. break
  713. fi
  714. done
  715. # Sometimes --show is required to display passwords in some implementations of my_print_defaults
  716. if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
  717. MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password --show)"
  718. fi
  719. unset tmp_mysqld_password_source
  720. fi
  721. MYSQL_TMPDIR="$(mysql-multilib-r1_getoptval mysqld tmpdir)"
  722. # These are dir+prefix
  723. MYSQL_RELAY_LOG="$(mysql-multilib-r1_getoptval mysqld relay-log)"
  724. MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
  725. MYSQL_LOG_BIN="$(mysql-multilib-r1_getoptval mysqld log-bin)"
  726. MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
  727. if [[ ! -d "${ROOT}"/$MYSQL_TMPDIR ]]; then
  728. einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
  729. install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
  730. fi
  731. if [[ ! -d "${ROOT}"/$MYSQL_LOG_BIN ]]; then
  732. einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
  733. install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
  734. fi
  735. if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
  736. einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
  737. install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
  738. fi
  739. if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
  740. ewarn "You have already a MySQL database in place."
  741. ewarn "(${ROOT}/${MY_DATADIR}/*)"
  742. ewarn "Please rename or delete it if you wish to replace it."
  743. die "MySQL database already exists!"
  744. fi
  745. # Bug #213475 - MySQL _will_ object strenously if your machine is named
  746. # localhost. Also causes weird failures.
  747. [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
  748. if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
  749. einfo "Please provide a password for the mysql 'root' user now"
  750. einfo "or through the ${HOME}/.my.cnf file."
  751. ewarn "Avoid [\"'\\_%] characters in the password"
  752. read -rsp " >" pwd1 ; echo
  753. einfo "Retype the password"
  754. read -rsp " >" pwd2 ; echo
  755. if [[ "x$pwd1" != "x$pwd2" ]] ; then
  756. die "Passwords are not the same"
  757. fi
  758. MYSQL_ROOT_PASSWORD="${pwd1}"
  759. unset pwd1 pwd2
  760. fi
  761. local options
  762. local sqltmp="$(emktemp)"
  763. # Fix bug 446200. Don't reference host my.cnf, needs to come first,
  764. # see http://bugs.mysql.com/bug.php?id=31312
  765. use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
  766. local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
  767. [[ -r "${help_tables}" ]] \
  768. && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
  769. || touch "${TMPDIR}/fill_help_tables.sql"
  770. help_tables="${TMPDIR}/fill_help_tables.sql"
  771. # Figure out which options we need to disable to do the setup
  772. local helpfile="${TMPDIR}/mysqld-help"
  773. ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
  774. for opt in grant-tables host-cache name-resolve networking slave-start \
  775. federated ssl log-bin relay-log slow-query-log external-locking \
  776. ndbcluster log-slave-updates \
  777. ; do
  778. optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
  779. egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
  780. done
  781. # But some options changed names
  782. egrep -sq external-locking "${helpfile}" && \
  783. options="${options/skip-locking/skip-external-locking}"
  784. use prefix || options="${options} --user=mysql"
  785. einfo "Creating the mysql database and setting proper permissions on it ..."
  786. # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
  787. PID_DIR="${EROOT}/var/run/mysqld"
  788. if [[ ! -d "${PID_DIR}" ]]; then
  789. mkdir -p "${PID_DIR}" || die "Could not create pid directory"
  790. chown mysql:mysql "${PID_DIR}" || die "Could not set ownership on pid directory"
  791. chmod 755 "${PID_DIR}" || die "Could not set permissions on pid directory"
  792. fi
  793. pushd "${TMPDIR}" &>/dev/null
  794. # Filling timezones, see
  795. # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
  796. "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
  797. local cmd
  798. local initialize_options
  799. if [[ ${PN} == "mysql" || ${PN} == "percona-server" ]] && version_is_at_least "5.7.6" ; then
  800. # --initialize-insecure will not set root password
  801. # --initialize would set a random one in the log which we don't need as we set it ourselves
  802. cmd=( "${EROOT}usr/sbin/mysqld" )
  803. initialize_options="--initialize-insecure --init-file='${sqltmp}'"
  804. sqltmp="" # the initialize will take care of it
  805. else
  806. cmd=( "${EROOT}usr/share/mysql/scripts/mysql_install_db" )
  807. [[ -f "${cmd}" ]] || cmd=( "${EROOT}usr/bin/mysql_install_db" )
  808. if [[ -r "${help_tables}" ]] ; then
  809. cat "${help_tables}" >> "${sqltmp}"
  810. fi
  811. fi
  812. cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT}/${MY_DATADIR}" "--tmpdir=${ROOT}/${MYSQL_TMPDIR}" ${initialize_options} )
  813. einfo "Command: ${cmd[*]}"
  814. "${cmd[@]}" \
  815. >"${TMPDIR}"/mysql_install_db.log 2>&1
  816. if [ $? -ne 0 ]; then
  817. grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
  818. die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
  819. fi
  820. popd &>/dev/null
  821. [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
  822. || die "MySQL databases not installed"
  823. chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
  824. chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
  825. local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
  826. local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
  827. local mysqld="${EROOT}/usr/sbin/mysqld \
  828. ${options} \
  829. $(use prefix || echo --user=mysql) \
  830. --log-warnings=0 \
  831. --basedir=${EROOT}/usr \
  832. --datadir=${ROOT}/${MY_DATADIR} \
  833. --max_allowed_packet=8M \
  834. --net_buffer_length=16K \
  835. --default-storage-engine=MyISAM \
  836. --socket=${socket} \
  837. --pid-file=${pidfile}
  838. --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
  839. #einfo "About to start mysqld: ${mysqld}"
  840. ebegin "Starting mysqld"
  841. einfo "Command ${mysqld}"
  842. ${mysqld} &
  843. rc=$?
  844. while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
  845. maxtry=$((${maxtry}-1))
  846. echo -n "."
  847. sleep 1
  848. done
  849. eend $rc
  850. if ! [[ -S "${socket}" ]]; then
  851. die "Completely failed to start up mysqld with: ${mysqld}"
  852. fi
  853. ebegin "Setting root password"
  854. # Do this from memory, as we don't want clear text passwords in temp files
  855. local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'; FLUSH PRIVILEGES"
  856. "${EROOT}/usr/bin/mysql" \
  857. --socket=${socket} \
  858. -hlocalhost \
  859. -e "${sql}"
  860. eend $?
  861. if [[ -n "${sqltmp}" ]] ; then
  862. ebegin "Loading \"zoneinfo\", this step may require a few seconds"
  863. "${EROOT}/usr/bin/mysql" \
  864. --socket=${socket} \
  865. -hlocalhost \
  866. -uroot \
  867. --password="${MYSQL_ROOT_PASSWORD}" \
  868. mysql < "${sqltmp}"
  869. rc=$?
  870. eend $?
  871. [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
  872. fi
  873. # Stop the server and cleanup
  874. einfo "Stopping the server ..."
  875. kill $(< "${pidfile}" )
  876. rm -f "${sqltmp}"
  877. wait %1
  878. einfo "Done"
  879. }
  880. #
  881. # HELPER FUNCTIONS:
  882. #
  883. # @FUNCTION: mysql-multilib-r1_disable_test
  884. # @DESCRIPTION:
  885. # Helper function to disable specific tests.
  886. mysql-multilib-r1_disable_test() {
  887. local rawtestname testname testsuite reason mysql_disabled_file mysql_disabled_dir
  888. rawtestname="${1}" ; shift
  889. reason="${@}"
  890. ewarn "test '${rawtestname}' disabled: '${reason}'"
  891. testsuite="${rawtestname/.*}"
  892. testname="${rawtestname/*.}"
  893. for mysql_disabled_file in \
  894. ${S}/mysql-test/disabled.def \
  895. ${S}/mysql-test/t/disabled.def ; do
  896. [[ -f ${mysql_disabled_file} ]] && break
  897. done
  898. #mysql_disabled_file="${S}/mysql-test/t/disabled.def"
  899. #einfo "rawtestname=${rawtestname} testname=${testname} testsuite=${testsuite}"
  900. echo ${testname} : ${reason} >> "${mysql_disabled_file}"
  901. if [[ ( -n ${testsuite} ) && ( ${testsuite} != "main" ) ]]; then
  902. for mysql_disabled_file in \
  903. ${S}/mysql-test/suite/${testsuite}/disabled.def \
  904. ${S}/mysql-test/suite/${testsuite}/t/disabled.def \
  905. FAILED ; do
  906. [[ -f ${mysql_disabled_file} ]] && break
  907. done
  908. if [[ ${mysql_disabled_file} != "FAILED" ]]; then
  909. echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
  910. else
  911. for mysql_disabled_dir in \
  912. ${S}/mysql-test/suite/${testsuite} \
  913. ${S}/mysql-test/suite/${testsuite}/t \
  914. FAILED ; do
  915. [[ -d ${mysql_disabled_dir} ]] && break
  916. done
  917. if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
  918. echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
  919. else
  920. ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
  921. fi
  922. fi
  923. fi
  924. }
  925. # @FUNCTION: mysql-cmake_use_plugin
  926. # @DESCRIPTION:
  927. # Helper function to enable/disable plugins by use flags
  928. # cmake-utils_use_with is not enough as some references check WITH_ (0|1)
  929. # and some check WITHOUT_. Also, this can easily extend to non-storage plugins.
  930. mysql-cmake_use_plugin() {
  931. [[ -z $2 ]] && die "mysql-cmake_use_plugin <USE flag> <flag name>"
  932. if in_iuse $1 && use $1 ; then
  933. echo "-DWITH_$2=1 -DPLUGIN_$2=YES"
  934. else
  935. echo "-DWITHOUT_$2=1 -DWITH_$2=0 -DPLUGIN_$2=NO"
  936. fi
  937. }
  938. # @FUNCTION: mysql_init_vars
  939. # @DESCRIPTION:
  940. # void mysql_init_vars()
  941. # Initialize global variables
  942. # 2005-11-19 <vivo@gentoo.org>
  943. if [[ "${EAPI}x" != "5x" ]]; then
  944. mysql_init_vars() {
  945. MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
  946. MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
  947. MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
  948. MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
  949. MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
  950. MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
  951. if [[ -z "${MY_DATADIR}" ]] ; then
  952. MY_DATADIR=""
  953. if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
  954. MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
  955. | sed -ne '/datadir/s|^--datadir=||p' \
  956. | tail -n1`
  957. if [[ -z "${MY_DATADIR}" ]] ; then
  958. MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
  959. | sed -e 's/.*=\s*//' \
  960. | tail -n1`
  961. fi
  962. fi
  963. if [[ -z "${MY_DATADIR}" ]] ; then
  964. MY_DATADIR="${MY_LOCALSTATEDIR}"
  965. einfo "Using default MY_DATADIR"
  966. fi
  967. elog "MySQL MY_DATADIR is ${MY_DATADIR}"
  968. if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
  969. if [[ -e "${MY_DATADIR}" ]] ; then
  970. # If you get this and you're wondering about it, see bug #207636
  971. elog "MySQL datadir found in ${MY_DATADIR}"
  972. elog "A new one will not be created."
  973. PREVIOUS_DATADIR="yes"
  974. else
  975. PREVIOUS_DATADIR="no"
  976. fi
  977. export PREVIOUS_DATADIR
  978. fi
  979. else
  980. if [[ ${EBUILD_PHASE} == "config" ]]; then
  981. local new_MY_DATADIR
  982. new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
  983. | sed -ne '/datadir/s|^--datadir=||p' \
  984. | tail -n1`
  985. if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
  986. ewarn "MySQL MY_DATADIR has changed"
  987. ewarn "from ${MY_DATADIR}"
  988. ewarn "to ${new_MY_DATADIR}"
  989. MY_DATADIR="${new_MY_DATADIR}"
  990. fi
  991. fi
  992. fi
  993. if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
  994. MY_SOURCEDIR=${SERVER_URI##*/}
  995. MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
  996. fi
  997. export MY_SHAREDSTATEDIR MY_SYSCONFDIR
  998. export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
  999. export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR
  1000. }
  1001. fi