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