diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0fd29e0e86..07813cfb36 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -687,9 +687,12 @@ jobs: - name: Stage verified Play components if: inputs.play_bundle == true + env: + DROIDDECK_ZSTD: /usr/bin/zstd run: | set -euo pipefail bash tools/ci/install-ubuntu-packages.sh zstd + "$DROIDDECK_ZSTD" --version python3 tools/playstore/payloads.py stage --play-only --manifest tools/playstore/components.lock.json \ --cache "$RUNNER_TEMP/play-component-cache" --output build/playstore-payloads diff --git a/tools/playstore/prepare_archive.py b/tools/playstore/prepare_archive.py index 88b805cab6..0ef9ab6ebc 100644 --- a/tools/playstore/prepare_archive.py +++ b/tools/playstore/prepare_archive.py @@ -2,13 +2,15 @@ import gzip import hashlib from pathlib import Path import subprocess +import os from contextlib import ExitStack def prepare(source, destination, definition): if definition['method'] not in {'gzip-to-zstd-19', 'zstd-to-zstd-19'}: raise ValueError('Unsupported component preparation method') - version = subprocess.check_output(['zstd', '--version'], text=True) + zstd = os.environ.get('DROIDDECK_ZSTD', 'zstd') + version = subprocess.check_output([zstd, '--version'], text=True) if 'v' + definition['zstd_version'] + ',' not in version: raise ValueError('Component preparation requires the pinned zstd version') digest = hashlib.sha256() @@ -18,12 +20,12 @@ def prepare(source, destination, definition): if definition['method'] == 'gzip-to-zstd-19': original = stack.enter_context(gzip.open(source, 'rb')) else: - decoder = subprocess.Popen(['zstd', '-dc', str(source)], stdout=subprocess.PIPE) + decoder = subprocess.Popen([zstd, '-dc', str(source)], stdout=subprocess.PIPE) stack.callback(decoder.wait) stack.callback(lambda: decoder.poll() is None and decoder.terminate()) original = stack.enter_context(decoder.stdout) output = stack.enter_context(Path(destination).open('xb')) - process = subprocess.Popen(['zstd', '-19', '-T4', '-c'], stdin=subprocess.PIPE, stdout=output) + process = subprocess.Popen([zstd, '-19', '-T4', '-c'], stdin=subprocess.PIPE, stdout=output) try: for block in iter(lambda: original.read(1024 * 1024), b''): size += len(block) diff --git a/tools/tests/test_playstore_archive_preparation.py b/tools/tests/test_playstore_archive_preparation.py index fe4b2ce8de..6762a47da1 100644 --- a/tools/tests/test_playstore_archive_preparation.py +++ b/tools/tests/test_playstore_archive_preparation.py @@ -1,4 +1,5 @@ import gzip +import os import hashlib from pathlib import Path import re @@ -6,6 +7,7 @@ import shutil import subprocess import tempfile import unittest +from unittest.mock import patch from tools.playstore.prepare_archive import prepare @@ -54,6 +56,16 @@ class PlayArchivePreparationTest(unittest.TestCase): prepare(original, output, definition) self.assertEqual(self.content, subprocess.check_output(['zstd', '-dc', str(output)])) + def test_pinned_executable_is_used_when_another_zstd_shadows_the_path(self): + actual = shutil.which('zstd') + directory = self.root / 'shadow' + directory.mkdir() + (directory / 'zstd').symlink_to(shutil.which('false')) + output = self.root / 'prepared.tar.zst' + with patch.dict(os.environ, DROIDDECK_ZSTD=actual, PATH=str(directory) + os.pathsep + os.environ['PATH']): + prepare(self.source, output, self.definition) + self.assertEqual(self.content, subprocess.check_output([actual, '-dc', str(output)])) + if __name__ == '__main__': unittest.main()