2b801329cf67d9b91972f7cbabb59c6dde3f7411
[gentoo.git] / sys-apps / portage / portage-2.3.99-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=5
5
6 DISTUTILS_USE_SETUPTOOLS=no
7 PYTHON_COMPAT=( pypy3 python3_6 python3_7 python3_8 )
8 PYTHON_REQ_USE='bzip2(+),threads(+)'
9
10 inherit distutils-r1 linux-info systemd prefix
11
12 DESCRIPTION="Portage is the package management and distribution system for Gentoo"
13 HOMEPAGE="https://wiki.gentoo.org/wiki/Project:Portage"
14
15 LICENSE="GPL-2"
16 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
17 SLOT="0"
18 IUSE="apidoc build doc gentoo-dev +ipc +native-extensions +rsync-verify selinux xattr"
19
20 DEPEND="!build? ( $(python_gen_impl_dep 'ssl(+)') )
21         >=app-arch/tar-1.27
22         dev-lang/python-exec:2
23         >=sys-apps/sed-4.0.5 sys-devel/patch
24         doc? ( app-text/xmlto ~app-text/docbook-xml-dtd-4.4 )
25         apidoc? (
26                 dev-python/sphinx
27                 dev-python/sphinx-epytext
28         )"
29 # Require sandbox-2.2 for bug #288863.
30 # For whirlpool hash, require python[ssl] (bug #425046).
31 # For compgen, require bash[readline] (bug #445576).
32 # app-portage/gemato goes without PYTHON_USEDEP since we're calling
33 # the executable.
34 RDEPEND="
35         >=app-arch/tar-1.27
36         dev-lang/python-exec:2
37         !build? (
38                 >=sys-apps/sed-4.0.5
39                 app-shells/bash:0[readline]
40                 >=app-admin/eselect-1.2
41                 rsync-verify? (
42                         >=app-portage/gemato-14[${PYTHON_USEDEP}]
43                         >=app-crypt/openpgp-keys-gentoo-release-20180706
44                         >=app-crypt/gnupg-2.2.4-r2[ssl(-)]
45                 )
46         )
47         elibc_FreeBSD? ( sys-freebsd/freebsd-bin )
48         elibc_glibc? ( >=sys-apps/sandbox-2.2 )
49         elibc_musl? ( >=sys-apps/sandbox-2.2 )
50         elibc_uclibc? ( >=sys-apps/sandbox-2.2 )
51         kernel_linux? ( sys-apps/util-linux )
52         >=app-misc/pax-utils-0.1.17
53         selinux? ( >=sys-libs/libselinux-2.0.94[python,${PYTHON_USEDEP}] )
54         xattr? ( kernel_linux? (
55                 >=sys-apps/install-xattr-0.3
56         ) )
57         !<app-admin/logrotate-3.8.0
58         !<app-portage/gentoolkit-0.4.6
59         !<app-portage/repoman-2.3.10"
60 PDEPEND="
61         !build? (
62                 >=net-misc/rsync-2.6.4
63                 userland_GNU? ( >=sys-apps/coreutils-6.4 )
64         )"
65 # coreutils-6.4 rdep is for date format in emerge-webrsync #164532
66 # NOTE: FEATURES=installsources requires debugedit and rsync
67
68 SRC_ARCHIVES="https://dev.gentoo.org/~zmedico/portage/archives"
69
70 prefix_src_archives() {
71         local x y
72         for x in ${@}; do
73                 for y in ${SRC_ARCHIVES}; do
74                         echo ${y}/${x}
75                 done
76         done
77 }
78
79 TARBALL_PV=${PV}
80 SRC_URI="mirror://gentoo/${PN}-${TARBALL_PV}.tar.bz2
81         $(prefix_src_archives ${PN}-${TARBALL_PV}.tar.bz2)"
82
83 pkg_pretend() {
84         local CONFIG_CHECK="~IPC_NS ~PID_NS ~NET_NS"
85
86         check_extra_config
87 }
88
89 python_prepare_all() {
90         distutils-r1_python_prepare_all
91
92         # Apply 03efd1125214
93         sed -e '50s|"EMERGE_FROM", "EPREFIX",|"EMERGE_FROM", "ENV_UNSET", "EPREFIX",|' -i lib/portage/package/ebuild/_config/special_env_vars.py || die
94
95         sed -e "s:^VERSION = \"HEAD\"$:VERSION = \"${PV}\":" -i lib/portage/__init__.py || die
96
97         if use gentoo-dev; then
98                 einfo "Disabling --dynamic-deps by default for gentoo-dev..."
99                 sed -e 's:\("--dynamic-deps", \)\("y"\):\1"n":' \
100                         -i lib/_emerge/create_depgraph_params.py || \
101                         die "failed to patch create_depgraph_params.py"
102
103                 einfo "Enabling additional FEATURES for gentoo-dev..."
104                 echo 'FEATURES="${FEATURES} strict-keepdir"' \
105                         >> cnf/make.globals || die
106         fi
107
108         if use native-extensions; then
109                 printf "[build_ext]\nportage-ext-modules=true\n" >> \
110                         setup.cfg || die
111         fi
112
113         if ! use ipc ; then
114                 einfo "Disabling ipc..."
115                 sed -e "s:_enable_ipc_daemon = True:_enable_ipc_daemon = False:" \
116                         -i lib/_emerge/AbstractEbuildProcess.py || \
117                         die "failed to patch AbstractEbuildProcess.py"
118         fi
119
120         if use xattr && use kernel_linux ; then
121                 einfo "Adding FEATURES=xattr to make.globals ..."
122                 echo -e '\nFEATURES="${FEATURES} xattr"' >> cnf/make.globals \
123                         || die "failed to append to make.globals"
124         fi
125
126         if use build || ! use rsync-verify; then
127                 sed -e '/^sync-rsync-verify-metamanifest/s|yes|no|' \
128                         -e '/^sync-webrsync-verify-signature/s|yes|no|' \
129                         -i cnf/repos.conf || die "sed failed"
130         fi
131
132         if [[ -n ${EPREFIX} ]] ; then
133                 einfo "Setting portage.const.EPREFIX ..."
134                 hprefixify -e "s|^(EPREFIX[[:space:]]*=[[:space:]]*\").*|\1${EPREFIX}\"|" \
135                         -w "/_BINARY/" lib/portage/const.py
136
137                 einfo "Prefixing shebangs ..."
138                 while read -r -d $'\0' ; do
139                         local shebang=$(head -n1 "$REPLY")
140                         if [[ ${shebang} == "#!"* && ! ${shebang} == "#!${EPREFIX}/"* ]] ; then
141                                 sed -i -e "1s:.*:#!${EPREFIX}${shebang:2}:" "$REPLY" || \
142                                         die "sed failed"
143                         fi
144                 done < <(find . -type f ! -name etc-update -print0)
145
146                 einfo "Adjusting make.globals, repos.conf and etc-update ..."
147                 hprefixify cnf/{make.globals,repos.conf} bin/etc-update
148
149                 if use prefix-guest ; then
150                         sed -e "s|^\(main-repo = \).*|\\1gentoo_prefix|" \
151                                 -e "s|^\\[gentoo\\]|[gentoo_prefix]|" \
152                                 -e "s|^\(sync-uri = \).*|\\1rsync://rsync.prefix.bitzolder.nl/gentoo-portage-prefix|" \
153                                 -i cnf/repos.conf || die "sed failed"
154                 fi
155
156                 einfo "Adding FEATURES=force-prefix to make.globals ..."
157                 echo -e '\nFEATURES="${FEATURES} force-prefix"' >> cnf/make.globals \
158                         || die "failed to append to make.globals"
159         fi
160
161         cd "${S}/cnf" || die
162         if [ -f "make.conf.example.${ARCH}".diff ]; then
163                 patch make.conf.example "make.conf.example.${ARCH}".diff || \
164                         die "Failed to patch make.conf.example"
165         else
166                 eerror ""
167                 eerror "Portage does not have an arch-specific configuration for this arch."
168                 eerror "Please notify the arch maintainer about this issue. Using generic."
169                 eerror ""
170         fi
171 }
172
173 python_compile_all() {
174         local targets=()
175         use doc && targets+=( docbook )
176         use apidoc && targets+=( apidoc )
177
178         if [[ ${targets[@]} ]]; then
179                 esetup.py "${targets[@]}"
180         fi
181 }
182
183 python_test() {
184         esetup.py test
185 }
186
187 python_install() {
188         # Install sbin scripts to bindir for python-exec linking
189         # they will be relocated in pkg_preinst()
190         distutils-r1_python_install \
191                 --system-prefix="${EPREFIX}/usr" \
192                 --bindir="$(python_get_scriptdir)" \
193                 --docdir="${EPREFIX}/usr/share/doc/${PF}" \
194                 --htmldir="${EPREFIX}/usr/share/doc/${PF}/html" \
195                 --portage-bindir="${EPREFIX}/usr/lib/portage/${EPYTHON}" \
196                 --sbindir="$(python_get_scriptdir)" \
197                 --sysconfdir="${EPREFIX}/etc" \
198                 "${@}"
199 }
200
201 python_install_all() {
202         distutils-r1_python_install_all
203
204         local targets=()
205         use doc && targets+=(
206                 install_docbook
207                 --htmldir="${EPREFIX}/usr/share/doc/${PF}/html"
208         )
209         use apidoc && targets+=(
210                 install_apidoc
211                 --htmldir="${EPREFIX}/usr/share/doc/${PF}/html"
212         )
213
214         # install docs
215         if [[ ${targets[@]} ]]; then
216                 esetup.py "${targets[@]}"
217         fi
218
219         systemd_dotmpfilesd "${FILESDIR}"/portage-ccache.conf
220
221         # Due to distutils/python-exec limitations
222         # these must be installed to /usr/bin.
223         local sbin_relocations='archive-conf dispatch-conf emaint env-update etc-update fixpackages regenworld'
224         einfo "Moving admin scripts to the correct directory"
225         dodir /usr/sbin
226         for target in ${sbin_relocations}; do
227                 einfo "Moving /usr/bin/${target} to /usr/sbin/${target}"
228                 mv "${ED}usr/bin/${target}" "${ED}usr/sbin/${target}" || die "sbin scripts move failed!"
229         done
230 }
231
232 pkg_preinst() {
233         python_setup
234         local sitedir=$(python_get_sitedir)
235         [[ -d ${D%/}${sitedir} ]] || die "${D%/}${sitedir}: No such directory"
236         env -u DISTDIR \
237                 -u PORTAGE_OVERRIDE_EPREFIX \
238                 -u PORTAGE_REPOSITORIES \
239                 -u PORTDIR \
240                 -u PORTDIR_OVERLAY \
241                 PYTHONPATH="${D%/}${sitedir}${PYTHONPATH:+:${PYTHONPATH}}" \
242                 "${PYTHON}" -m portage._compat_upgrade.default_locations || die
243
244         # elog dir must exist to avoid logrotate error for bug #415911.
245         # This code runs in preinst in order to bypass the mapping of
246         # portage:portage to root:root which happens after src_install.
247         keepdir /var/log/portage/elog
248         # This is allowed to fail if the user/group are invalid for prefix users.
249         if chown portage:portage "${ED}"var/log/portage{,/elog} 2>/dev/null ; then
250                 chmod g+s,ug+rwx "${ED}"var/log/portage{,/elog}
251         fi
252
253         if has_version "<${CATEGORY}/${PN}-2.3.77"; then
254                 elog "The emerge --autounmask option is now disabled by default, except for"
255                 elog "portions of behavior which are controlled by the --autounmask-use and"
256                 elog "--autounmask-license options. For backward compatibility, previous"
257                 elog "behavior of --autounmask=y and --autounmask=n is entirely preserved."
258                 elog "Users can get the old behavior simply by adding --autounmask to the"
259                 elog "make.conf EMERGE_DEFAULT_OPTS variable. For the rationale for this"
260                 elog "change, see https://bugs.gentoo.org/658648."
261         fi
262 }