Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH v2] Support disabling docompress for binary package builds
Date: Sun, 04 Nov 2018 09:20:36
Message-Id: 20181104092014.5307-1-mgorny@gentoo.org
1 Add FEATURES=binpkg-docompress that can be used whether docompress
2 compression is performed before or after creating binary packages. With
3 the feature enabled (the default), the current behavior of storing
4 compressed files in binpkg is preserved. With it disabled, uncompressed
5 files are stored inside binary package and are compressed when
6 installing.
7
8 Storing uncompressed files in binary packages has two advantages:
9
10 1. Avoids the double-compression penalty, effectively improving binary
11 package compression speed and compression ratio.
12
13 2. Allows the same packages to be reused on systems with different
14 docompress configurations.
15
16 The option is roughly backwards compatible. Old Portage versions will
17 install packages created with FEATURES=-binpkg-docompress correctly,
18 albeit without compression. Portage with FEATURES=binpkg-docompress
19 should install old binpackages semi-correctly, potentially recompressing
20 them (and throwing already-compressed warnings on format mismatch).
21 The new behavior is left off by default to avoid those problems.
22
23 Signed-off-by: Michał Górny <mgorny@g.o>
24 ---
25 bin/misc-functions.sh | 43 +++++++++++++++++++++++---
26 bin/phase-functions.sh | 2 +-
27 cnf/make.globals | 2 +-
28 lib/portage/const.py | 1 +
29 lib/portage/dbapi/vartree.py | 12 +++++++
30 lib/portage/package/ebuild/doebuild.py | 4 ++-
31 man/ebuild.1 | 5 +++
32 man/make.conf.5 | 6 ++++
33 8 files changed, 68 insertions(+), 7 deletions(-)
34
35 Changes in v2:
36 * added .instprepped file logic,
37 * added instprep -> install dependency,
38 * documented in ebuild.1.
39
40 I've tested this thoroughly via ebuild(1) and emerge(1).
41
42 diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
43 index db7aaed5a..3b3a5e09c 100755
44 --- a/bin/misc-functions.sh
45 +++ b/bin/misc-functions.sh
46 @@ -109,10 +109,13 @@ install_qa_check() {
47
48 [[ -d ${ED%/}/usr/share/info ]] && prepinfo
49
50 - # Apply compression.
51 - "${PORTAGE_BIN_PATH}"/ecompress --queue "${PORTAGE_DOCOMPRESS[@]}"
52 - "${PORTAGE_BIN_PATH}"/ecompress --ignore "${PORTAGE_DOCOMPRESS_SKIP[@]}"
53 - "${PORTAGE_BIN_PATH}"/ecompress --dequeue
54 + # If binpkg-docompress is enabled, apply compression before creating
55 + # the binary package.
56 + if has binpkg-docompress ${FEATURES}; then
57 + "${PORTAGE_BIN_PATH}"/ecompress --queue "${PORTAGE_DOCOMPRESS[@]}"
58 + "${PORTAGE_BIN_PATH}"/ecompress --ignore "${PORTAGE_DOCOMPRESS_SKIP[@]}"
59 + "${PORTAGE_BIN_PATH}"/ecompress --dequeue
60 + fi
61
62 export STRIP_MASK
63 if ___eapi_has_dostrip; then
64 @@ -160,6 +163,38 @@ install_qa_check() {
65 rm -f "${ED%/}"/usr/share/info/dir{,.gz,.bz2} || die "rm failed!"
66 }
67
68 +__dyn_instprep() {
69 + if [[ -e ${PORTAGE_BUILDDIR}/.instprepped ]] ; then
70 + __vecho ">>> It appears that '$PF' is already instprepped; skipping."
71 + __vecho ">>> Remove '${PORTAGE_BUILDDIR}/.instprepped' to force instprep."
72 + return 0
73 + fi
74 +
75 + if has chflags ${FEATURES}; then
76 + # Save all the file flags for restoration afterwards.
77 + mtree -c -p "${ED}" -k flags > "${T}/bsdflags.mtree"
78 + # Remove all the file flags so that we can do anything necessary.
79 + chflags -R noschg,nouchg,nosappnd,nouappnd "${ED}"
80 + chflags -R nosunlnk,nouunlnk "${ED}" 2>/dev/null
81 + fi
82 +
83 + # If binpkg-docompress is disabled, we need to apply compression
84 + # before installing.
85 + if ! has binpkg-docompress ${FEATURES}; then
86 + "${PORTAGE_BIN_PATH}"/ecompress --queue "${PORTAGE_DOCOMPRESS[@]}"
87 + "${PORTAGE_BIN_PATH}"/ecompress --ignore "${PORTAGE_DOCOMPRESS_SKIP[@]}"
88 + "${PORTAGE_BIN_PATH}"/ecompress --dequeue
89 + fi
90 +
91 + if has chflags ${FEATURES}; then
92 + # Restore all the file flags that were saved earlier on.
93 + mtree -U -e -p "${ED}" -k flags < "${T}/bsdflags.mtree" &> /dev/null
94 + fi
95 +
96 + >> "${PORTAGE_BUILDDIR}/.instprepped" || \
97 + die "Failed to create ${PORTAGE_BUILDDIR}/.instprepped"
98 +}
99 +
100 preinst_qa_check() {
101 postinst_qa_check preinst
102 }
103 diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
104 index 51b480bfb..d8ebf3d3e 100644
105 --- a/bin/phase-functions.sh
106 +++ b/bin/phase-functions.sh
107 @@ -288,7 +288,7 @@ __dyn_clean() {
108
109 if [[ $EMERGE_FROM = binary ]] || ! has keepwork $FEATURES; then
110 rm -f "$PORTAGE_BUILDDIR"/.{ebuild_changed,logid,pretended,setuped,unpacked,prepared} \
111 - "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged} \
112 + "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged,instprepped} \
113 "$PORTAGE_BUILDDIR"/.die_hooks \
114 "$PORTAGE_BUILDDIR"/.ipc_{in,out,lock} \
115 "$PORTAGE_BUILDDIR"/.exit_status
116 diff --git a/cnf/make.globals b/cnf/make.globals
117 index 04a708af8..72b567e98 100644
118 --- a/cnf/make.globals
119 +++ b/cnf/make.globals
120 @@ -50,7 +50,7 @@ RESUMECOMMAND_SSH=${FETCHCOMMAND_SSH}
121 FETCHCOMMAND_SFTP="bash -c \"x=\\\${2#sftp://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port= ; eval \\\"declare -a ssh_opts=(\\\${3})\\\" ; exec sftp \\\${port:+-P \\\${port}} \\\"\\\${ssh_opts[@]}\\\" \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" sftp \"\${DISTDIR}/\${FILE}\" \"\${URI}\" \"\${PORTAGE_SSH_OPTS}\""
122
123 # Default user options
124 -FEATURES="assume-digests binpkg-logs
125 +FEATURES="assume-digests binpkg-docompress binpkg-logs
126 config-protect-if-modified distlocks ebuild-locks
127 fixlafiles merge-sync multilib-strict news
128 parallel-fetch preserve-libs protect-owned
129 diff --git a/lib/portage/const.py b/lib/portage/const.py
130 index 7f84bf0e9..a343fc040 100644
131 --- a/lib/portage/const.py
132 +++ b/lib/portage/const.py
133 @@ -122,6 +122,7 @@ EBUILD_PHASES = (
134 )
135 SUPPORTED_FEATURES = frozenset([
136 "assume-digests",
137 + "binpkg-docompress",
138 "binpkg-logs",
139 "binpkg-multi-instance",
140 "buildpkg",
141 diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py
142 index c16fdfe88..fd8aaeb8e 100644
143 --- a/lib/portage/dbapi/vartree.py
144 +++ b/lib/portage/dbapi/vartree.py
145 @@ -3719,6 +3719,7 @@ class dblink(object):
146
147 This function does the following:
148
149 + calls doebuild(mydo=instprep)
150 calls get_ro_checker to retrieve a function for checking whether Portage
151 will write to a read-only filesystem, then runs it against the directory list
152 calls self._preserve_libs if FEATURES=preserve-libs
153 @@ -3768,6 +3769,17 @@ class dblink(object):
154 level=logging.ERROR, noiselevel=-1)
155 return 1
156
157 + # run instprep internal phase
158 + doebuild_environment(myebuild, "instprep",
159 + settings=self.settings, db=mydbapi)
160 + phase = EbuildPhase(background=False, phase="instprep",
161 + scheduler=self._scheduler, settings=self.settings)
162 + phase.start()
163 + if phase.wait() != os.EX_OK:
164 + showMessage(_("!!! instprep failed\n"),
165 + level=logging.ERROR, noiselevel=-1)
166 + return 1
167 +
168 is_binpkg = self.settings.get("EMERGE_FROM") == "binary"
169 slot = ''
170 for var_name in ('CHOST', 'SLOT'):
171 diff --git a/lib/portage/package/ebuild/doebuild.py b/lib/portage/package/ebuild/doebuild.py
172 index 9706de422..d0e96f34c 100644
173 --- a/lib/portage/package/ebuild/doebuild.py
174 +++ b/lib/portage/package/ebuild/doebuild.py
175 @@ -656,6 +656,7 @@ def doebuild(myebuild, mydo, _unused=DeprecationWarning, settings=None, debug=0,
176 "compile":["configure"],
177 "test": ["compile"],
178 "install":["test"],
179 + "instprep":["install"],
180 "rpm": ["install"],
181 "package":["install"],
182 "merge" :["install"],
183 @@ -674,7 +675,7 @@ def doebuild(myebuild, mydo, _unused=DeprecationWarning, settings=None, debug=0,
184 "config", "info", "setup", "depend", "pretend",
185 "fetch", "fetchall", "digest",
186 "unpack", "prepare", "configure", "compile", "test",
187 - "install", "rpm", "qmerge", "merge",
188 + "install", "instprep", "rpm", "qmerge", "merge",
189 "package", "unmerge", "manifest", "nofetch"]
190
191 if mydo not in validcommands:
192 @@ -1402,6 +1403,7 @@ def _spawn_actionmap(settings):
193 "compile": {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":nosandbox, "sesandbox":sesandbox, "fakeroot":0}},
194 "test": {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":nosandbox, "sesandbox":sesandbox, "fakeroot":0}},
195 "install": {"cmd":ebuild_sh, "args":{"droppriv":0, "free":0, "sesandbox":sesandbox, "fakeroot":fakeroot}},
196 +"instprep": {"cmd":misc_sh, "args":{"droppriv":0, "free":0, "sesandbox":sesandbox, "fakeroot":fakeroot}},
197 "rpm": {"cmd":misc_sh, "args":{"droppriv":0, "free":0, "sesandbox":0, "fakeroot":fakeroot}},
198 "package": {"cmd":misc_sh, "args":{"droppriv":0, "free":0, "sesandbox":0, "fakeroot":fakeroot}},
199 }
200 diff --git a/man/ebuild.1 b/man/ebuild.1
201 index 1d48844da..5893c3df6 100644
202 --- a/man/ebuild.1
203 +++ b/man/ebuild.1
204 @@ -130,6 +130,11 @@ the \fIsrc_install()\fR function. When completed, the
205 will contain all the files that should either be merged to the local
206 filesystem or included in a binary package.
207 .TP
208 +.BR instprep
209 +Performs the additional post-install/pre-merge preparations inside
210 +the temporary \fIinstall directory\fR. This is intended to be called
211 +\fBafter\fR building binary package but before executing \fBpreinst\fR.
212 +.TP
213 .BR postinst
214 Runs package-specific actions that need to be done after the package
215 is installed into the live filesystem. Usually helpful messages are
216 diff --git a/man/make.conf.5 b/man/make.conf.5
217 index a33929143..ec03c93ca 100644
218 --- a/man/make.conf.5
219 +++ b/man/make.conf.5
220 @@ -275,6 +275,12 @@ existing digest, the digest will be regenerated regardless of whether or
221 not \fIassume\-digests\fR is enabled. The \fBebuild\fR(1) \fBdigest\fR command
222 has a \fB\-\-force\fR option that can be used to force regeneration of digests.
223 .TP
224 +.B binpkg\-docompress
225 +Perform \fBdocompress\fR (controllable file compression) before creating binary
226 +package. When this option is enabled (the default), documentation files are
227 +already compressed inside binary packages. When it is disabled, binary packages
228 +contain uncompressed documentation and Portage compresses it before installing.
229 +.TP
230 .B binpkg\-logs
231 Keep logs from successful binary package merges. This is relevant only when
232 \fBPORT_LOGDIR\fR is set.
233 --
234 2.19.1

Replies