Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion etc/DependencyInstaller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,35 @@ _install_bazel() {
_execute "Installing bazelisk..." mv bazelisk "${bazel_prefix}/bin/bazelisk"
)
if _command_exists "apt-get"; then
# Ubuntu 26.04 ships the libxml2 runtime with soname
# libxml2.so.16, but the prebuilt LLVM toolchain (lld) pulled in
# by the Bazel build is linked against the old libxml2.so.2.
# Pull in libxml2-dev there (and add a compatibility symlink
# below); older Ubuntu still provides .so.2 via libxml2.
local ubuntu_version=""
if [[ -f /etc/os-release ]]; then
ubuntu_version=$(awk -F= '/^VERSION_ID/{print $2}' /etc/os-release | sed 's/"//g')
fi
local libxml2_pkg="libxml2"
if [[ -n "${ubuntu_version}" ]] && _version_compare "${ubuntu_version}" -ge "26.04"; then
libxml2_pkg="libxml2-dev"
fi
_execute "Installing bazel required libraries..." \
apt-get -y install --no-install-recommends \
libc6-dev libxml2 libtinfo6 zlib1g libstdc++6
libc6-dev "${libxml2_pkg}" libtinfo6 zlib1g libstdc++6
# lld only uses libxml2 for Windows COFF manifests, never during a
# Linux link, so the .so.16 -> .so.2 compatibility symlink is safe.
# Gated to 26.04+ only.
if [[ -n "${ubuntu_version}" ]] && _version_compare "${ubuntu_version}" -ge "26.04"; then
local libdir="/usr/lib/$(uname -m)-linux-gnu"
local libxml2_so
libxml2_so=$(ls "${libdir}"/libxml2.so.* 2>/dev/null \
| grep -v 'libxml2.so.2$' | head -n1)
Comment on lines +890 to +892

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since set -euo pipefail is active at the top of the script, any command in a pipeline that exits with a non-zero status will cause the entire pipeline to fail, which in turn triggers set -e and terminates the script immediately.

If ls "${libdir}"/libxml2.so.* does not match any files (for example, if libxml2 is not installed, is in a different directory, or if the directory doesn't exist), ls will exit with a non-zero status. This will cause the pipeline to fail and the script to crash.

Using a pure Bash loop with globbing avoids spawning external processes (ls, grep, head), is completely safe under set -eo pipefail, and is more efficient. Additionally, when searching for libraries in a shared prefix on Linux, we should account for multiarch layouts by including globs for architecture-specific subdirectories (e.g., "${libdir}"/*/libxml2.so.*).

Suggested change
local libxml2_so
libxml2_so=$(ls "${libdir}"/libxml2.so.* 2>/dev/null \
| grep -v 'libxml2.so.2$' | head -n1)
local libxml2_so=""
local f
for f in "${libdir}"/libxml2.so.* "${libdir}"/*/libxml2.so.*; do
if [[ -e "${f}" && "${f}" != *"/libxml2.so.2" ]]; then
libxml2_so="${f}"
break
fi
done
References
  1. When cleaning up or searching for libraries in a shared prefix on Linux, account for multiarch layouts by including globs for architecture-specific subdirectories (e.g., "lib/*/").

if [[ ! -e "${libdir}/libxml2.so.2" && -n "${libxml2_so}" ]]; then
_execute "Adding libxml2.so.2 compatibility symlink for prebuilt LLVM lld..." \
ln -sf "$(basename "${libxml2_so}")" "${libdir}/libxml2.so.2"
fi
fi
elif _command_exists "yum"; then
_execute "Installing bazel required libraries..." \
yum install -y \
Expand Down
Loading