From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B813D1382C5 for ; Mon, 21 Jun 2021 20:04:41 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E7D55E0817; Mon, 21 Jun 2021 20:04:40 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id BF1D3E0817 for ; Mon, 21 Jun 2021 20:04:40 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4E98933BED9 for ; Mon, 21 Jun 2021 20:04:39 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 991824A0 for ; Mon, 21 Jun 2021 20:04:37 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1624305842.85ca62da1e01820085da6cd0cb053c1f1a299dac.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qmerge.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 85ca62da1e01820085da6cd0cb053c1f1a299dac X-VCS-Branch: master Date: Mon, 21 Jun 2021 20:04:37 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 8f872e6d-b0b2-42d6-8f96-55aa3a98ce3c X-Archives-Hash: 64b1dfd232857cfc823db8639e03db58 commit: 85ca62da1e01820085da6cd0cb053c1f1a299dac Author: Fabian Groffen gentoo org> AuthorDate: Mon Jun 21 20:04:02 2021 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Mon Jun 21 20:04:02 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=85ca62da qmerge: check phase funcs against PMS whether they should be run Signed-off-by: Fabian Groffen gentoo.org> qmerge.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 17 deletions(-) diff --git a/qmerge.c b/qmerge.c index a9dbe4b..1f1bb1e 100644 --- a/qmerge.c +++ b/qmerge.c @@ -627,15 +627,61 @@ qprint_tree_node( return c; } +/* PMS 9.2 Call order */ +enum pkg_phases { + PKG_PRETEND = 1, + PKG_SETUP = 2, + /* skipping src_* */ + PKG_PREINST = 3, + PKG_POSTINST = 4, + PKG_PRERM = 5, + PKG_POSTRM = 6 +}; +#define MAX_EAPI 8 +static struct { + enum pkg_phases phase; + const char *phasestr; + unsigned char eapi[1 + MAX_EAPI]; +} phase_table[] = { + { 0, NULL, {0,0,0,0,0,0,0,0,0} }, /* align */ + /* phase EAPI: 0 1 2 3 4 5 6 7 8 */ + { PKG_PRETEND, "pkg_pretend", {0,0,0,0,1,1,1,1,1} }, /* table 9.3 */ + { PKG_SETUP, "pkg_setup", {1,1,1,1,1,1,1,1,1} }, + { PKG_PREINST, "pkg_preinst", {1,1,1,1,1,1,1,1,1} }, + { PKG_POSTINST, "pkg_postinst", {1,1,1,1,1,1,1,1,1} }, + { PKG_PRERM, "pkg_prerm", {1,1,1,1,1,1,1,1,1} }, + { PKG_POSTRM, "pkg_postrm", {1,1,1,1,1,1,1,1,1} } +}; + static void -pkg_run_func_at(int dirfd, const char *vdb_path, const char *phases, const char *func, const char *D, const char *T) +pkg_run_func_at( + int dirfd, + const char *vdb_path, + const char *phases, + enum pkg_phases phaseidx, + const char *D, + const char *T, + const char *EAPI) { + const char *func; const char *phase; - char *script; + char *script; + int eapi; + + /* EAPI officially is a string, but since the official ones are only + * numbers, we'll just go with the numbers */ + eapi = (int)strtol(EAPI, NULL, 10); + if (eapi > MAX_EAPI) + eapi = MAX_EAPI; /* let's hope latest known EAPI is closest */ + + /* see if this function should be run for the EAPI */ + if (!phase_table[phaseidx].eapi[eapi]) + return; /* This assumes no func is a substring of another func. * Today, that assumption is valid for all funcs ... * The phases are the func with the "pkg_" chopped off. */ + func = phase_table[phaseidx].phasestr; phase = func + 4; if (strstr(phases, phase) == NULL) { qprintf("--- %s\n", func); @@ -978,8 +1024,6 @@ pkg_extract_xpak_cb( } /* oh shit getting into pkg mgt here. FIXME: write a real dep resolver. */ -static char *pm_phases; -static size_t pm_phases_len; static void pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg) { @@ -991,8 +1035,6 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg) depend_atom *slotatom; FILE *fp; FILE *contents; - char *eprefix = NULL; - size_t eprefix_len = 0; char buf[1024]; char *p; char *D; @@ -1009,7 +1051,13 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg) char **cp_argv; char **cpm_argv; int tbz2size; - int replacing = 0; + int replacing = 0; + char *eprefix = NULL; + size_t eprefix_len = 0; + char *pm_phases = NULL; + size_t pm_phases_len = 0; + char *eapi = NULL; + size_t eapi_len = 0; if (!install || !mpkg || !qatom) return; @@ -1292,16 +1340,16 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg) fflush(stdout); + eat_file("vdb/EPREFIX", &eprefix, &eprefix_len); + eat_file("vdb/EAPI", &eapi, &eapi_len); eat_file("vdb/DEFINED_PHASES", &pm_phases, &pm_phases_len); + if (!pretend) { - pkg_run_func("vdb", pm_phases, "pkg_pretend", D, T); - pkg_run_func("vdb", pm_phases, "pkg_setup", D, T); - pkg_run_func("vdb", pm_phases, "pkg_preinst", D, T); + pkg_run_func("vdb", pm_phases, PKG_PRETEND, D, T, eapi); + pkg_run_func("vdb", pm_phases, PKG_SETUP, D, T, eapi); + pkg_run_func("vdb", pm_phases, PKG_PREINST, D, T, eapi); } - if (!eat_file("vdb/EPREFIX", &eprefix, &eprefix_len)) - eprefix_len = 0; - { int imagefd = open("image", O_RDONLY); size_t masklen = strlen(install_mask) + 1 + @@ -1312,7 +1360,7 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg) if (fstat(imagefd, &st) == -1) { close(imagefd); err("Cannot stat image dirfd"); - } else if (eprefix_len > 0) { + } else if (eprefix != NULL && eprefix[0] == '/') { int imagepfx = openat(imagefd, eprefix + 1, O_RDONLY); if (imagepfx != -1) { close(imagefd); @@ -1374,7 +1422,12 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg) /* run postinst */ if (!pretend) - pkg_run_func("vdb", pm_phases, "pkg_postinst", D, T); + pkg_run_func("vdb", pm_phases, PKG_POSTINST, D, T, eapi); + + if (eapi != NULL) + free(eapi); + if (pm_phases != NULL) + free(pm_phases); /* XXX: hmm, maybe we'll want to strip more ? */ unlink("vdb/environment"); @@ -1466,10 +1519,11 @@ pkg_unmerge(tree_pkg_ctx *pkg_ctx, set *keep, /* execute the pkg_prerm step */ if (!pretend) { + buf = tree_pkg_meta_get(pkg_ctx, EAPI); phases = tree_pkg_meta_get(pkg_ctx, DEFINED_PHASES); if (phases != NULL) { mkdirat(pkg_ctx->fd, "temp", 0755); - pkg_run_func_at(pkg_ctx->fd, ".", phases, "pkg_prerm", T, T); + pkg_run_func_at(pkg_ctx->fd, ".", phases, PKG_PRERM, T, T, buf); } } @@ -1602,9 +1656,10 @@ pkg_unmerge(tree_pkg_ctx *pkg_ctx, set *keep, } if (!pretend) { + buf = tree_pkg_meta_get(pkg_ctx, EAPI); phases = tree_pkg_meta_get(pkg_ctx, DEFINED_PHASES); /* execute the pkg_postrm step */ - pkg_run_func_at(pkg_ctx->fd, ".", phases, "pkg_postrm", T, T); + pkg_run_func_at(pkg_ctx->fd, ".", phases, PKG_POSTRM, T, T, buf); /* finally delete the vdb entry */ rm_rf_at(pkg_ctx->fd, ".");