Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Mon, 21 Jun 2021 20:04:41
Message-Id: 1624305842.85ca62da1e01820085da6cd0cb053c1f1a299dac.grobian@gentoo
1 commit: 85ca62da1e01820085da6cd0cb053c1f1a299dac
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Mon Jun 21 20:04:02 2021 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Mon Jun 21 20:04:02 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=85ca62da
7
8 qmerge: check phase funcs against PMS whether they should be run
9
10 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
11
12 qmerge.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++-------------
13 1 file changed, 72 insertions(+), 17 deletions(-)
14
15 diff --git a/qmerge.c b/qmerge.c
16 index a9dbe4b..1f1bb1e 100644
17 --- a/qmerge.c
18 +++ b/qmerge.c
19 @@ -627,15 +627,61 @@ qprint_tree_node(
20 return c;
21 }
22
23 +/* PMS 9.2 Call order */
24 +enum pkg_phases {
25 + PKG_PRETEND = 1,
26 + PKG_SETUP = 2,
27 + /* skipping src_* */
28 + PKG_PREINST = 3,
29 + PKG_POSTINST = 4,
30 + PKG_PRERM = 5,
31 + PKG_POSTRM = 6
32 +};
33 +#define MAX_EAPI 8
34 +static struct {
35 + enum pkg_phases phase;
36 + const char *phasestr;
37 + unsigned char eapi[1 + MAX_EAPI];
38 +} phase_table[] = {
39 + { 0, NULL, {0,0,0,0,0,0,0,0,0} }, /* align */
40 + /* phase EAPI: 0 1 2 3 4 5 6 7 8 */
41 + { PKG_PRETEND, "pkg_pretend", {0,0,0,0,1,1,1,1,1} }, /* table 9.3 */
42 + { PKG_SETUP, "pkg_setup", {1,1,1,1,1,1,1,1,1} },
43 + { PKG_PREINST, "pkg_preinst", {1,1,1,1,1,1,1,1,1} },
44 + { PKG_POSTINST, "pkg_postinst", {1,1,1,1,1,1,1,1,1} },
45 + { PKG_PRERM, "pkg_prerm", {1,1,1,1,1,1,1,1,1} },
46 + { PKG_POSTRM, "pkg_postrm", {1,1,1,1,1,1,1,1,1} }
47 +};
48 +
49 static void
50 -pkg_run_func_at(int dirfd, const char *vdb_path, const char *phases, const char *func, const char *D, const char *T)
51 +pkg_run_func_at(
52 + int dirfd,
53 + const char *vdb_path,
54 + const char *phases,
55 + enum pkg_phases phaseidx,
56 + const char *D,
57 + const char *T,
58 + const char *EAPI)
59 {
60 + const char *func;
61 const char *phase;
62 - char *script;
63 + char *script;
64 + int eapi;
65 +
66 + /* EAPI officially is a string, but since the official ones are only
67 + * numbers, we'll just go with the numbers */
68 + eapi = (int)strtol(EAPI, NULL, 10);
69 + if (eapi > MAX_EAPI)
70 + eapi = MAX_EAPI; /* let's hope latest known EAPI is closest */
71 +
72 + /* see if this function should be run for the EAPI */
73 + if (!phase_table[phaseidx].eapi[eapi])
74 + return;
75
76 /* This assumes no func is a substring of another func.
77 * Today, that assumption is valid for all funcs ...
78 * The phases are the func with the "pkg_" chopped off. */
79 + func = phase_table[phaseidx].phasestr;
80 phase = func + 4;
81 if (strstr(phases, phase) == NULL) {
82 qprintf("--- %s\n", func);
83 @@ -978,8 +1024,6 @@ pkg_extract_xpak_cb(
84 }
85
86 /* oh shit getting into pkg mgt here. FIXME: write a real dep resolver. */
87 -static char *pm_phases;
88 -static size_t pm_phases_len;
89 static void
90 pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg)
91 {
92 @@ -991,8 +1035,6 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg)
93 depend_atom *slotatom;
94 FILE *fp;
95 FILE *contents;
96 - char *eprefix = NULL;
97 - size_t eprefix_len = 0;
98 char buf[1024];
99 char *p;
100 char *D;
101 @@ -1009,7 +1051,13 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg)
102 char **cp_argv;
103 char **cpm_argv;
104 int tbz2size;
105 - int replacing = 0;
106 + int replacing = 0;
107 + char *eprefix = NULL;
108 + size_t eprefix_len = 0;
109 + char *pm_phases = NULL;
110 + size_t pm_phases_len = 0;
111 + char *eapi = NULL;
112 + size_t eapi_len = 0;
113
114 if (!install || !mpkg || !qatom)
115 return;
116 @@ -1292,16 +1340,16 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg)
117
118 fflush(stdout);
119
120 + eat_file("vdb/EPREFIX", &eprefix, &eprefix_len);
121 + eat_file("vdb/EAPI", &eapi, &eapi_len);
122 eat_file("vdb/DEFINED_PHASES", &pm_phases, &pm_phases_len);
123 +
124 if (!pretend) {
125 - pkg_run_func("vdb", pm_phases, "pkg_pretend", D, T);
126 - pkg_run_func("vdb", pm_phases, "pkg_setup", D, T);
127 - pkg_run_func("vdb", pm_phases, "pkg_preinst", D, T);
128 + pkg_run_func("vdb", pm_phases, PKG_PRETEND, D, T, eapi);
129 + pkg_run_func("vdb", pm_phases, PKG_SETUP, D, T, eapi);
130 + pkg_run_func("vdb", pm_phases, PKG_PREINST, D, T, eapi);
131 }
132
133 - if (!eat_file("vdb/EPREFIX", &eprefix, &eprefix_len))
134 - eprefix_len = 0;
135 -
136 {
137 int imagefd = open("image", O_RDONLY);
138 size_t masklen = strlen(install_mask) + 1 +
139 @@ -1312,7 +1360,7 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg)
140 if (fstat(imagefd, &st) == -1) {
141 close(imagefd);
142 err("Cannot stat image dirfd");
143 - } else if (eprefix_len > 0) {
144 + } else if (eprefix != NULL && eprefix[0] == '/') {
145 int imagepfx = openat(imagefd, eprefix + 1, O_RDONLY);
146 if (imagepfx != -1) {
147 close(imagefd);
148 @@ -1374,7 +1422,12 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg)
149
150 /* run postinst */
151 if (!pretend)
152 - pkg_run_func("vdb", pm_phases, "pkg_postinst", D, T);
153 + pkg_run_func("vdb", pm_phases, PKG_POSTINST, D, T, eapi);
154 +
155 + if (eapi != NULL)
156 + free(eapi);
157 + if (pm_phases != NULL)
158 + free(pm_phases);
159
160 /* XXX: hmm, maybe we'll want to strip more ? */
161 unlink("vdb/environment");
162 @@ -1466,10 +1519,11 @@ pkg_unmerge(tree_pkg_ctx *pkg_ctx, set *keep,
163
164 /* execute the pkg_prerm step */
165 if (!pretend) {
166 + buf = tree_pkg_meta_get(pkg_ctx, EAPI);
167 phases = tree_pkg_meta_get(pkg_ctx, DEFINED_PHASES);
168 if (phases != NULL) {
169 mkdirat(pkg_ctx->fd, "temp", 0755);
170 - pkg_run_func_at(pkg_ctx->fd, ".", phases, "pkg_prerm", T, T);
171 + pkg_run_func_at(pkg_ctx->fd, ".", phases, PKG_PRERM, T, T, buf);
172 }
173 }
174
175 @@ -1602,9 +1656,10 @@ pkg_unmerge(tree_pkg_ctx *pkg_ctx, set *keep,
176 }
177
178 if (!pretend) {
179 + buf = tree_pkg_meta_get(pkg_ctx, EAPI);
180 phases = tree_pkg_meta_get(pkg_ctx, DEFINED_PHASES);
181 /* execute the pkg_postrm step */
182 - pkg_run_func_at(pkg_ctx->fd, ".", phases, "pkg_postrm", T, T);
183 + pkg_run_func_at(pkg_ctx->fd, ".", phases, PKG_POSTRM, T, T, buf);
184
185 /* finally delete the vdb entry */
186 rm_rf_at(pkg_ctx->fd, ".");