Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys-apps/portage: Migrate 9999 to use Meson #32098

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions eclass/python-utils-r1.eclass
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ _python_export() {
debug-print "${FUNCNAME}: EPYTHON = ${EPYTHON}"
;;
PYTHON)
export PYTHON=${BROOT-${EPREFIX}}/usr/bin/${impl}
export PYTHON=${BROOT}/usr/bin/${impl}
debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
;;
PYTHON_SITEDIR)
Expand Down Expand Up @@ -1023,8 +1023,6 @@ python_fix_shebang() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)"
local PYTHON
_python_export "${EPYTHON}" PYTHON

local force quiet
while [[ ${@} ]]; do
Expand Down Expand Up @@ -1097,7 +1095,7 @@ python_fix_shebang() {
if [[ ! ${error} ]]; then
debug-print "${FUNCNAME}: in file ${f#${D%/}}"
debug-print "${FUNCNAME}: rewriting shebang: ${shebang}"
sed -i -e "1s@${from}@#!${PYTHON}@" "${f}" || die
sed -i -e "1s@${from}@#!${EPREFIX}/usr/bin/${EPYTHON}@" "${f}" || die
any_fixed=1
else
eerror "The file has incompatible shebang:"
Expand Down
187 changes: 58 additions & 129 deletions sys-apps/portage/portage-9999.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

EAPI=7

DISTUTILS_EXT=1
PYTHON_COMPAT=( pypy3 python3_{10..12} )
PYTHON_REQ_USE='bzip2(+),threads(+)'
SETUPTOOLS_USE_DISTUTILS=local
TMPFILES_OPTIONAL=1

inherit distutils-r1 linux-info toolchain-funcs tmpfiles prefix
inherit meson linux-info python-r1 tmpfiles

DESCRIPTION="The package management and distribution system for Gentoo"
HOMEPAGE="https://wiki.gentoo.org/wiki/Project:Portage"
Expand All @@ -28,13 +26,19 @@ fi
LICENSE="GPL-2"
SLOT="0"
IUSE="apidoc build doc gentoo-dev +ipc +native-extensions +rsync-verify selinux test xattr"
REQUIRED_USE="${PYTHON_REQUIRED_USE}"
RESTRICT="!test? ( test )"

# setuptools is still needed as a workaround for Python 3.12+ for now.
# https://github.com/mesonbuild/meson/issues/7702

BDEPEND="
dev-python/setuptools[${PYTHON_USEDEP}]
${PYTHON_DEPS}
python_targets_python3_12? ( dev-python/setuptools[${PYTHON_USEDEP}] )
chewi marked this conversation as resolved.
Show resolved Hide resolved
test? ( dev-vcs/git )
"
DEPEND="
${PYTHON_DEPS}
>=app-arch/tar-1.27
dev-lang/python-exec:2
>=sys-apps/sed-4.0.5 sys-devel/patch
Expand All @@ -51,6 +55,7 @@ DEPEND="
# Require sandbox-2.2 for bug #288863.
# For whirlpool hash, require python[ssl] (bug #425046).
RDEPEND="
${PYTHON_DEPS}
acct-user/portage
app-arch/zstd
>=app-arch/tar-1.27
Expand Down Expand Up @@ -90,154 +95,78 @@ PDEPEND="
)
"

distutils_enable_tests pytest

pkg_pretend() {
local CONFIG_CHECK="~IPC_NS ~PID_NS ~NET_NS ~UTS_NS"

if use native-extensions && tc-is-cross-compiler; then
einfo "Disabling USE=native-extensions for cross-compilation (bug #612158)"
fi

check_extra_config
}

python_prepare_all() {
distutils-r1_python_prepare_all

if [[ ${PV} != 9999 ]] ; then
sed -e "s:^VERSION = \"HEAD\"$:VERSION = \"${PV}\":" -i lib/portage/__init__.py || die
fi

if use gentoo-dev; then
einfo "Disabling --dynamic-deps by default for gentoo-dev..."
sed -e 's:\("--dynamic-deps", \)\("y"\):\1"n":' \
-i lib/_emerge/create_depgraph_params.py || \
die "failed to patch create_depgraph_params.py"

einfo "Enabling additional FEATURES for gentoo-dev..."
echo 'FEATURES="${FEATURES} ipc-sandbox network-sandbox strict-keepdir warn-on-large-env"' \
>> cnf/make.globals || die
fi
src_prepare() {
default

if use native-extensions && ! tc-is-cross-compiler; then
printf "[build_ext]\nportage_ext_modules=true\n" >> \
setup.cfg || die
fi

if ! use ipc ; then
einfo "Disabling ipc..."
sed -e "s:_enable_ipc_daemon = True:_enable_ipc_daemon = False:" \
-i lib/_emerge/AbstractEbuildProcess.py || \
die "failed to patch AbstractEbuildProcess.py"
fi

if use xattr && use kernel_linux ; then
einfo "Adding FEATURES=xattr to make.globals ..."
echo -e '\nFEATURES="${FEATURES} xattr"' >> cnf/make.globals \
|| die "failed to append to make.globals"
fi

if use build || ! use rsync-verify; then
sed -e '/^sync-rsync-verify-metamanifest/s|yes|no|' \
-e '/^sync-webrsync-verify-signature/s|yes|no|' \
if use prefix-guest; then
sed -e "s|^\(main-repo = \).*|\\1gentoo_prefix|" \
-e "s|^\\[gentoo\\]|[gentoo_prefix]|" \
-e "s|^\(sync-uri = \).*|\\1rsync://rsync.prefix.bitzolder.nl/gentoo-portage-prefix|" \
-i cnf/repos.conf || die "sed failed"
fi
}

if [[ -n ${EPREFIX} ]] ; then
einfo "Setting portage.const.EPREFIX ..."
hprefixify -e "s|^(EPREFIX[[:space:]]*=[[:space:]]*\").*|\1${EPREFIX}\"|" \
-w "/_BINARY/" lib/portage/const.py

einfo "Prefixing shebangs ..."
> "${T}/shebangs" || die
while read -r -d $'\0' ; do
local shebang=$(head -n1 "$REPLY")
if [[ ${shebang} == "#!"* && ! ${shebang} == "#!${EPREFIX}/"* ]] ; then
echo "${REPLY}" >> "${T}/shebangs" || die
fi
done < <(find . -type f -executable ! -name etc-update -print0)

if [[ -s ${T}/shebangs ]]; then
xargs sed -i -e "1s:^#!:#!${EPREFIX}:" < "${T}/shebangs" || die "sed failed"
fi

einfo "Adjusting make.globals, repos.conf and etc-update ..."
hprefixify cnf/{make.globals,repos.conf} bin/etc-update
src_configure() {
local code_only=false
python_foreach_impl my_src_configure
}

if use prefix-guest ; then
sed -e "s|^\(main-repo = \).*|\\1gentoo_prefix|" \
-e "s|^\\[gentoo\\]|[gentoo_prefix]|" \
-e "s|^\(sync-uri = \).*|\\1rsync://rsync.prefix.bitzolder.nl/gentoo-portage-prefix|" \
-i cnf/repos.conf || die "sed failed"
fi
fi
my_src_configure() {
local emesonargs=(
-Dcode-only=${code_only}
-Deprefix="${EPREFIX}"
-Dportage-bindir="${EPREFIX}/usr/lib/portage/${EPYTHON}"
-Ddocdir="${EPREFIX}/usr/share/doc/${PF}"
$(meson_use doc)
$(meson_use apidoc)
$(meson_use native-extensions)
$(meson_use gentoo-dev)
$(meson_use ipc)
$(meson_use xattr)
)

cd "${S}/cnf" || die
if [[ -f "make.conf.example.${ARCH}".diff ]] ; then
patch make.conf.example "make.conf.example.${ARCH}".diff || \
die "Failed to patch make.conf.example"
if use build; then
emesonargs+=( -Drsync-verify=false )
else
eerror ""
eerror "Portage does not have an arch-specific configuration for this arch."
eerror "Please notify the arch maintainer about this issue. Using generic."
eerror ""
emesonargs+=( $(meson_use rsync-verify) )
fi
}

python_compile_all() {
local targets=()
use doc && targets+=( docbook )
use apidoc && targets+=( apidoc )

if [[ ${targets[@]} ]]; then
esetup.py "${targets[@]}"
fi
meson_src_configure
code_only=true
}

python_install() {
# Install sbin scripts to bindir for python-exec linking
# they will be relocated in pkg_preinst()
distutils-r1_python_install \
--system-prefix="${EPREFIX}/usr" \
--bindir="$(python_get_scriptdir)" \
--docdir="${EPREFIX}/usr/share/doc/${PF}" \
--htmldir="${EPREFIX}/usr/share/doc/${PF}/html" \
--portage-bindir="${EPREFIX}/usr/lib/portage/${EPYTHON}" \
--sbindir="$(python_get_scriptdir)" \
--sysconfdir="${EPREFIX}/etc" \
"${@}"
src_compile() {
python_foreach_impl meson_src_compile
}

python_install_all() {
distutils-r1_python_install_all
src_install() {
python_foreach_impl my_src_install
dotmpfiles "${FILESDIR}"/portage-{ccache,tmpdir}.conf

local targets=()
use doc && targets+=(
install_docbook
--htmldir="${EPREFIX}/usr/share/doc/${PF}/html"
)
use apidoc && targets+=(
install_apidoc
--htmldir="${EPREFIX}/usr/share/doc/${PF}/html"
)
local scripts
mapfile -t scripts < <(awk '/^#!.*python/ {print FILENAME} {nextfile}' "${ED}"/usr/{bin,sbin}/* || die)
python_replicate_script "${scripts[@]}"
}

# install docs
if [[ ${targets[@]} ]]; then
esetup.py "${targets[@]}"
fi
my_src_install() {
local pydirs=(
"${D}$(python_get_sitedir)"
"${D}/usr/lib/portage/${EPYTHON}"
)

dotmpfiles "${FILESDIR}"/portage-{ccache,tmpdir}.conf
meson_src_install
python_optimize "${pydirs[@]}"
python_fix_shebang "${pydirs[@]}"
}

# Due to distutils/python-exec limitations
# these must be installed to /usr/bin.
local sbin_relocations='archive-conf dispatch-conf emaint env-update etc-update fixpackages regenworld'
einfo "Moving admin scripts to the correct directory"
dodir /usr/sbin
for target in ${sbin_relocations}; do
einfo "Moving /usr/bin/${target} to /usr/sbin/${target}"
mv "${ED}/usr/bin/${target}" "${ED}/usr/sbin/${target}" || die "sbin scripts move failed!"
done
src_test() {
python_foreach_impl meson_src_test --no-rebuild --verbose
}

pkg_preinst() {
Expand Down