chroot_version_hooks.d: install zstd from source if needed
If people haven't updated their SDK, then installing zstd from a binpkg
fails because it's a binpkg using zstd. Build it from source.
BUG=b:187789829
TEST=CQ passes
Change-Id: I6255510308649d40b6d437e62af880f1f814cb30
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/3626114
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Chris McDonald <cjmcdonald@chromium.org>
Reviewed-by: Chris McDonald <cjmcdonald@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
diff --git a/chroot_version_hooks.d/182_binutils235_upgrade b/chroot_version_hooks.d/182_binutils235_upgrade
index 51139d8..9a8b21c 100644
--- a/chroot_version_hooks.d/182_binutils235_upgrade
+++ b/chroot_version_hooks.d/182_binutils235_upgrade
@@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# See comments in the hook.
+. /mnt/host/source/src/scripts/chroot_version_hooks.d/204_zstd
+
# Upgrade binutils to avoid binutils being pulled into
# build graph when building target packages, https://crbug.com/1171084
sudo emerge -ugq sys-devel/binutils
diff --git a/chroot_version_hooks.d/183_sandbox_update b/chroot_version_hooks.d/183_sandbox_update
index 66bcdbb..bdaed62 100644
--- a/chroot_version_hooks.d/183_sandbox_update
+++ b/chroot_version_hooks.d/183_sandbox_update
@@ -2,5 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# See comments in the hook.
+. /mnt/host/source/src/scripts/chroot_version_hooks.d/204_zstd
+
# Upgrade sandbox to avoid renameat failures, https://crbug.com/1176957
sudo emerge -ugq sys-apps/sandbox
diff --git a/chroot_version_hooks.d/186_bash_upgrade b/chroot_version_hooks.d/186_bash_upgrade
index 231d956..a2c1d77 100644
--- a/chroot_version_hooks.d/186_bash_upgrade
+++ b/chroot_version_hooks.d/186_bash_upgrade
@@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# See comments in the hook.
+. /mnt/host/source/src/scripts/chroot_version_hooks.d/204_zstd
+
# Upgrade bash to the latest version we support.
# Bash updates change behavior, and build scripts are made to support the
# latest bash version, and may not work with older versions.
diff --git a/chroot_version_hooks.d/199_emerge_libunwind b/chroot_version_hooks.d/199_emerge_libunwind
index 6e069e0..a53bc8f 100644
--- a/chroot_version_hooks.d/199_emerge_libunwind
+++ b/chroot_version_hooks.d/199_emerge_libunwind
@@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# See comments in the hook.
+. /mnt/host/source/src/scripts/chroot_version_hooks.d/204_zstd
+
# Force all boards to re-emerge llvm-libunwind
# b/210927982
diff --git a/chroot_version_hooks.d/203_emerge_libcxx b/chroot_version_hooks.d/203_emerge_libcxx
index 8d02f14..9dde085 100644
--- a/chroot_version_hooks.d/203_emerge_libcxx
+++ b/chroot_version_hooks.d/203_emerge_libcxx
@@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# See comments in the hook.
+. /mnt/host/source/src/scripts/chroot_version_hooks.d/204_zstd
+
# Force all boards to re-emerge sys-libs/libcxxabi sys-libs/libcxx.
# This is required for switch to runtimes builds (b/204093890).
diff --git a/chroot_version_hooks.d/204_zstd b/chroot_version_hooks.d/204_zstd
new file mode 100644
index 0000000..1cb0298
--- /dev/null
+++ b/chroot_version_hooks.d/204_zstd
@@ -0,0 +1,10 @@
+# Copyright 2022 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# If an older SDK doesn't have zstd yet, the SDK produces the zstd binpkg using
+# zstd, so we can't install it. Force it from source.
+
+if ! type -P zstd >/dev/null; then
+ sudo emerge -1O --buildpkg=n zstd
+fi