commit:     230595cf600cae6beb6ebf6f817d08ace433c3ea
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon May 11 01:23:41 2020 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun May 24 22:26:29 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=230595cf

Default BINPKG_COMPRESSION to zstd (bug 715108)

This includes a _compat_upgrade.binpkg_compression script that the
ebuild can call in pkg_preinst in order to maintain a backward-compatible
bzip2 default when appropriate, ensuring that binary package consumers
are not caught off guard.

Bug: https://bugs.gentoo.org/715108
Reviewed-by: Brian Dolbec <dolsen <AT> gentoo.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 .travis.yml                                       |  4 +++
 cnf/make.globals                                  |  5 +--
 lib/portage/_compat_upgrade/binpkg_compression.py | 40 +++++++++++++++++++++++
 lib/portage/tests/resolver/ResolverPlayground.py  |  1 +
 man/make.conf.5                                   |  4 +--
 5 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9269d4034..2132c8c87 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,4 @@
+dist: bionic
 language: python
 python:
     - 2.7
@@ -8,6 +9,9 @@ python:
     - pypy3
 
 # command to install dependencies
+before_install:
+    # Use "dist: bionic" to get a zstd with --long support.
+    - sudo apt-get -y install zstd
 install:
     - pip install tox
 

diff --git a/cnf/make.globals b/cnf/make.globals
index 4a59dbe3c..dd3f28f70 100644
--- a/cnf/make.globals
+++ b/cnf/make.globals
@@ -34,8 +34,9 @@ RPMDIR="/var/cache/rpm"
 # Temporary build directory
 PORTAGE_TMPDIR="/var/tmp"
 
-# The compression used for binary packages. Defaults to zstd when USE=zstd is 
enabled.
-BINPKG_COMPRESS="bzip2"
+# The compression used for binary packages. Defaults to zstd except for
+# existing installs where bzip2 is used for backward compatibility.
+BINPKG_COMPRESS="zstd"
 
 # Fetching command (3 tries, passive ftp for firewall compatibility)
 FETCHCOMMAND="wget -t 3 -T 60 --passive-ftp -O \"\${DISTDIR}/\${FILE}\" 
\"\${URI}\""

diff --git a/lib/portage/_compat_upgrade/binpkg_compression.py 
b/lib/portage/_compat_upgrade/binpkg_compression.py
new file mode 100644
index 000000000..0f5704733
--- /dev/null
+++ b/lib/portage/_compat_upgrade/binpkg_compression.py
@@ -0,0 +1,40 @@
+# Copyright 2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+import re
+
+import portage
+from portage import os
+from portage.const import GLOBAL_CONFIG_PATH
+
+COMPAT_BINPKG_COMPRESS = 'bzip2'
+
+
+def main():
+       """
+       If the current installation is still configured to use the old
+       default BINPKG_COMPRESS=bzip2 setting, then patch make.globals
+       inside ${ED} to maintain backward compatibility, ensuring that
+       binary package consumers are not caught off guard. This is
+       intended to be called from the ebuild as follows:
+
+       pkg_preinst() {
+               python_setup
+               env -u BINPKG_COMPRESS
+                       
PYTHONPATH="${D%/}$(python_get_sitedir)${PYTHONPATH:+:${PYTHONPATH}}" \
+                       "${PYTHON}" -m 
portage._compat_upgrade.binpkg_compression || die
+       }
+       """
+       if portage.settings.get('BINPKG_COMPRESS', COMPAT_BINPKG_COMPRESS) == 
COMPAT_BINPKG_COMPRESS:
+               config_path = os.path.join(os.environ['ED'], 
GLOBAL_CONFIG_PATH.lstrip(os.sep), 'make.globals')
+               with open(config_path) as f:
+                       content = f.read()
+                       compat_setting = 
'BINPKG_COMPRESS="{}"'.format(COMPAT_BINPKG_COMPRESS)
+                       portage.output.EOutput().einfo('Setting make.globals 
default {} for backward compatibility'.format(compat_setting))
+                       content = re.sub('^BINPKG_COMPRESS=.*$', 
compat_setting, content, flags=re.MULTILINE)
+               with open(config_path, 'wt') as f:
+                       f.write(content)
+
+
+if __name__ == '__main__':
+       main()

diff --git a/lib/portage/tests/resolver/ResolverPlayground.py 
b/lib/portage/tests/resolver/ResolverPlayground.py
index 98831e000..de80a0cc1 100644
--- a/lib/portage/tests/resolver/ResolverPlayground.py
+++ b/lib/portage/tests/resolver/ResolverPlayground.py
@@ -112,6 +112,7 @@ class ResolverPlayground(object):
                                "uname",
                                "uniq",
                                "xargs",
+                               "zstd",
                        )
                        # Exclude internal wrappers from PATH lookup.
                        orig_path = os.environ['PATH']

diff --git a/man/make.conf.5 b/man/make.conf.5
index f82fed65a..a3bd662ae 100644
--- a/man/make.conf.5
+++ b/man/make.conf.5
@@ -1,4 +1,4 @@
-.TH "MAKE.CONF" "5" "Nov 2019" "Portage VERSION" "Portage"
+.TH "MAKE.CONF" "5" "May 2020" "Portage VERSION" "Portage"
 .SH "NAME"
 make.conf \- custom settings for Portage
 .SH "SYNOPSIS"
@@ -115,7 +115,7 @@ This variable is used to determine the compression used for 
\fIbinary
 packages\fR. Supported settings and compression algorithms are: bzip2, gzip,
 lz4, lzip, lzop, xz, zstd.
 .br
-Defaults to "bzip2".
+Defaults to "zstd".
 .br
 .I Example:
 .nf

Reply via email to