dev-db/mongodb: fix REPLACING_VERSION detection #589458
[gentoo.git] / dev-db / mongodb / mongodb-3.2.9.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6 SCONS_MIN_VERSION="2.3.0"
7 CHECKREQS_DISK_BUILD="2400M"
8 CHECKREQS_DISK_USR="512M"
9 CHECKREQS_MEMORY="1024M"
10
11 inherit eutils flag-o-matic multilib pax-utils scons-utils systemd toolchain-funcs user versionator check-reqs
12
13 MY_P=${PN}-src-r${PV/_rc/-rc}
14
15 DESCRIPTION="A high-performance, open source, schema-free document-oriented database"
16 HOMEPAGE="http://www.mongodb.org"
17 SRC_URI="https://fastdl.mongodb.org/src/${MY_P}.tar.gz"
18
19 LICENSE="AGPL-3 Apache-2.0"
20 SLOT="0"
21 KEYWORDS="~amd64 ~x86"
22 IUSE="debug kerberos libressl mms-agent ssl test +tools"
23
24 RDEPEND=">=app-arch/snappy-1.1.2
25         || ( =dev-cpp/yaml-cpp-0.5.1 >dev-cpp/yaml-cpp-0.5.2 )
26         >=dev-libs/boost-1.57[threads(+)]
27         >=dev-libs/libpcre-8.37[cxx]
28         dev-libs/snowball-stemmer
29         net-libs/libpcap
30         >=sys-libs/zlib-1.2.8
31         mms-agent? ( app-admin/mms-agent )
32         ssl? (
33                 !libressl? ( >=dev-libs/openssl-1.0.1g:0= )
34                 libressl? ( dev-libs/libressl:= )
35         )"
36 DEPEND="${RDEPEND}
37         >=sys-devel/gcc-4.8.2:*
38         sys-libs/ncurses
39         sys-libs/readline
40         debug? ( dev-util/valgrind )
41         kerberos? ( dev-libs/cyrus-sasl[kerberos] )
42         test? (
43                 dev-python/pymongo
44                 dev-python/pyyaml
45         )"
46 PDEPEND="tools? ( >=app-admin/mongo-tools-${PV} )"
47
48 S=${WORKDIR}/${MY_P}
49
50 pkg_pretend() {
51         if [[ ${REPLACING_VERSIONS} < 3.0 ]]; then
52                 ewarn "To upgrade an existing MongoDB deployment to 3.2, you must be"
53                 ewarn "running a 3.0-series release. Please update to the latest 3.0"
54                 ewarn "release before continuing if wish to keep your data."
55         fi
56 }
57
58 pkg_setup() {
59         enewgroup mongodb
60         enewuser mongodb -1 -1 /var/lib/${PN} mongodb
61
62         # Maintainer notes
63         #
64         # --use-system-tcmalloc is strongly NOT recommended:
65         # https://www.mongodb.org/about/contributors/tutorial/build-mongodb-from-source/
66
67         scons_opts=(
68                 CC="$(tc-getCC)"
69                 CXX="$(tc-getCXX)"
70
71                 --disable-warnings-as-errors
72                 --use-system-boost
73                 --use-system-pcre
74                 --use-system-snappy
75                 --use-system-stemmer
76                 --use-system-yaml
77                 --use-system-zlib
78         )
79
80         # wiredtiger not supported on 32bit platforms #572166
81         use x86 && scons_opts+=( --wiredtiger=off )
82
83         if use debug; then
84                 scons_opts+=( --dbg=on )
85         fi
86
87         if use prefix; then
88                 scons_opts+=(
89                         --cpppath="${EPREFIX}/usr/include"
90                         --libpath="${EPREFIX}/usr/$(get_libdir)"
91                 )
92         fi
93
94         if use kerberos; then
95                 scons_opts+=( --use-sasl-client )
96         fi
97
98         if use ssl; then
99                 scons_opts+=( --ssl )
100         fi
101 }
102
103 src_prepare() {
104         epatch "${FILESDIR}/${PN}-3.2.0-fix-scons.patch" \
105                 "${FILESDIR}/${PN}-3.2.4-boost-1.60.patch"
106         epatch_user
107 }
108
109 src_compile() {
110         # respect mongoDB upstream's basic recommendations
111         # see bug #536688 and #526114
112         if ! use debug; then
113                 filter-flags '-m*'
114                 filter-flags '-O?'
115         fi
116         escons "${scons_opts[@]}" core tools
117 }
118
119 src_install() {
120         escons "${scons_opts[@]}" --nostrip install --prefix="${ED}"/usr
121
122         for x in /var/{lib,log}/${PN}; do
123                 keepdir "${x}"
124                 fowners mongodb:mongodb "${x}"
125         done
126
127         doman debian/mongo*.1
128         dodoc README docs/building.md
129
130         newinitd "${FILESDIR}/${PN}.initd-r2" ${PN}
131         newconfd "${FILESDIR}/${PN}.confd-r2" ${PN}
132         newinitd "${FILESDIR}/${PN/db/s}.initd-r2" ${PN/db/s}
133         newconfd "${FILESDIR}/${PN/db/s}.confd-r2" ${PN/db/s}
134
135         insinto /etc
136         newins "${FILESDIR}/${PN}.conf-r3" ${PN}.conf
137         newins "${FILESDIR}/${PN/db/s}.conf-r2" ${PN/db/s}.conf
138
139         systemd_dounit "${FILESDIR}/${PN}.service"
140
141         insinto /etc/logrotate.d/
142         newins "${FILESDIR}/${PN}.logrotate" ${PN}
143
144         # see bug #526114
145         pax-mark emr "${ED}"/usr/bin/{mongo,mongod,mongos}
146 }
147
148 pkg_preinst() {
149         # wrt bug #461466
150         if [[ "$(get_libdir)" == "lib64" ]]; then
151                 rmdir "${ED}"/usr/lib/ &>/dev/null
152         fi
153 }
154
155 src_test() {
156         # this one test fails
157         rm jstests/core/repl_write_threads_start_param.js
158
159         ./buildscripts/resmoke.py --dbpathPrefix=test --suites core || die "Tests failed"
160 }
161
162 pkg_postinst() {
163         local v
164         for v in ${REPLACING_VERSIONS}; do
165                 if ! version_is_at_least 3.0 ${v}; then
166                         ewarn "!! IMPORTANT !!"
167                         ewarn " "
168                         ewarn "${PN} configuration files have changed !"
169                         ewarn " "
170                         ewarn "Make sure you migrate from /etc/conf.d/${PN} to the new YAML standard in /etc/${PN}.conf"
171                         ewarn "  http://docs.mongodb.org/manual/reference/configuration-options/"
172                         ewarn " "
173                         ewarn "Make sure you also follow the upgrading process :"
174                         ewarn "  http://docs.mongodb.org/master/release-notes/3.0-upgrade/"
175                         ewarn " "
176                         ewarn "MongoDB 3.0 introduces the WiredTiger storage engine."
177                         ewarn "WiredTiger is incompatible with MMAPv1 and you need to dump/reload your data if you want to use it."
178                         ewarn "Once you have your data dumped, you need to set storage.engine: wiredTiger in /etc/${PN}.conf"
179                         ewarn "  http://docs.mongodb.org/master/release-notes/3.0-upgrade/#change-storage-engine-to-wiredtiger"
180                         break
181                 fi
182         done
183
184         ewarn "Make sure to read the release notes and follow the upgrade process:"
185         ewarn "  https://docs.mongodb.org/manual/release-notes/3.2/"
186         ewarn "  https://docs.mongodb.org/master/release-notes/3.2-upgrade/"
187         ewarn
188         ewarn " Starting in 3.2, MongoDB uses the WiredTiger as the default storage engine."
189 }