Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] Default BINPKG_COMPRESSION to zstd (bug 715108)
Date: Mon, 11 May 2020 02:32:11
Message-Id: 20200511022934.317695-1-zmedico@gentoo.org
1 This includes a _compat_upgrade.binpkg_compression script that the
2 ebuild can call in pkg_preinst in order to maintain a backward-compatible
3 bzip2 default when appropriate, ensuring that binary package consumers
4 are not caught off guard.
5
6 Bug: https://bugs.gentoo.org/715108
7 Signed-off-by: Zac Medico <zmedico@g.o>
8 ---
9 .travis.yml | 4 ++
10 cnf/make.globals | 5 ++-
11 .../_compat_upgrade/binpkg_compression.py | 40 +++++++++++++++++++
12 .../tests/resolver/ResolverPlayground.py | 1 +
13 man/make.conf.5 | 4 +-
14 5 files changed, 50 insertions(+), 4 deletions(-)
15 create mode 100644 lib/portage/_compat_upgrade/binpkg_compression.py
16
17 diff --git a/.travis.yml b/.travis.yml
18 index 9269d4034..2132c8c87 100644
19 --- a/.travis.yml
20 +++ b/.travis.yml
21 @@ -1,3 +1,4 @@
22 +dist: bionic
23 language: python
24 python:
25 - 2.7
26 @@ -8,6 +9,9 @@ python:
27 - pypy3
28
29 # command to install dependencies
30 +before_install:
31 + # Use "dist: bionic" to get a zstd with --long support.
32 + - sudo apt-get -y install zstd
33 install:
34 - pip install tox
35
36 diff --git a/cnf/make.globals b/cnf/make.globals
37 index 4a59dbe3c..dd3f28f70 100644
38 --- a/cnf/make.globals
39 +++ b/cnf/make.globals
40 @@ -34,8 +34,9 @@ RPMDIR="/var/cache/rpm"
41 # Temporary build directory
42 PORTAGE_TMPDIR="/var/tmp"
43
44 -# The compression used for binary packages. Defaults to zstd when USE=zstd is enabled.
45 -BINPKG_COMPRESS="bzip2"
46 +# The compression used for binary packages. Defaults to zstd except for
47 +# existing installs where bzip2 is used for backward compatibility.
48 +BINPKG_COMPRESS="zstd"
49
50 # Fetching command (3 tries, passive ftp for firewall compatibility)
51 FETCHCOMMAND="wget -t 3 -T 60 --passive-ftp -O \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
52 diff --git a/lib/portage/_compat_upgrade/binpkg_compression.py b/lib/portage/_compat_upgrade/binpkg_compression.py
53 new file mode 100644
54 index 000000000..0f5704733
55 --- /dev/null
56 +++ b/lib/portage/_compat_upgrade/binpkg_compression.py
57 @@ -0,0 +1,40 @@
58 +# Copyright 2020 Gentoo Authors
59 +# Distributed under the terms of the GNU General Public License v2
60 +
61 +import re
62 +
63 +import portage
64 +from portage import os
65 +from portage.const import GLOBAL_CONFIG_PATH
66 +
67 +COMPAT_BINPKG_COMPRESS = 'bzip2'
68 +
69 +
70 +def main():
71 + """
72 + If the current installation is still configured to use the old
73 + default BINPKG_COMPRESS=bzip2 setting, then patch make.globals
74 + inside ${ED} to maintain backward compatibility, ensuring that
75 + binary package consumers are not caught off guard. This is
76 + intended to be called from the ebuild as follows:
77 +
78 + pkg_preinst() {
79 + python_setup
80 + env -u BINPKG_COMPRESS
81 + PYTHONPATH="${D%/}$(python_get_sitedir)${PYTHONPATH:+:${PYTHONPATH}}" \
82 + "${PYTHON}" -m portage._compat_upgrade.binpkg_compression || die
83 + }
84 + """
85 + if portage.settings.get('BINPKG_COMPRESS', COMPAT_BINPKG_COMPRESS) == COMPAT_BINPKG_COMPRESS:
86 + config_path = os.path.join(os.environ['ED'], GLOBAL_CONFIG_PATH.lstrip(os.sep), 'make.globals')
87 + with open(config_path) as f:
88 + content = f.read()
89 + compat_setting = 'BINPKG_COMPRESS="{}"'.format(COMPAT_BINPKG_COMPRESS)
90 + portage.output.EOutput().einfo('Setting make.globals default {} for backward compatibility'.format(compat_setting))
91 + content = re.sub('^BINPKG_COMPRESS=.*$', compat_setting, content, flags=re.MULTILINE)
92 + with open(config_path, 'wt') as f:
93 + f.write(content)
94 +
95 +
96 +if __name__ == '__main__':
97 + main()
98 diff --git a/lib/portage/tests/resolver/ResolverPlayground.py b/lib/portage/tests/resolver/ResolverPlayground.py
99 index 98831e000..de80a0cc1 100644
100 --- a/lib/portage/tests/resolver/ResolverPlayground.py
101 +++ b/lib/portage/tests/resolver/ResolverPlayground.py
102 @@ -112,6 +112,7 @@ class ResolverPlayground(object):
103 "uname",
104 "uniq",
105 "xargs",
106 + "zstd",
107 )
108 # Exclude internal wrappers from PATH lookup.
109 orig_path = os.environ['PATH']
110 diff --git a/man/make.conf.5 b/man/make.conf.5
111 index f82fed65a..a3bd662ae 100644
112 --- a/man/make.conf.5
113 +++ b/man/make.conf.5
114 @@ -1,4 +1,4 @@
115 -.TH "MAKE.CONF" "5" "Nov 2019" "Portage VERSION" "Portage"
116 +.TH "MAKE.CONF" "5" "May 2020" "Portage VERSION" "Portage"
117 .SH "NAME"
118 make.conf \- custom settings for Portage
119 .SH "SYNOPSIS"
120 @@ -115,7 +115,7 @@ This variable is used to determine the compression used for \fIbinary
121 packages\fR. Supported settings and compression algorithms are: bzip2, gzip,
122 lz4, lzip, lzop, xz, zstd.
123 .br
124 -Defaults to "bzip2".
125 +Defaults to "zstd".
126 .br
127 .I Example:
128 .nf
129 --
130 2.25.3

Replies