Skip to content

Commit 7af5983

Browse files
authored
Add guard to macOS and glibc version checks (conda#1094)
1 parent c4bd536 commit 7af5983

File tree

2 files changed

+64
-41
lines changed

2 files changed

+64
-41
lines changed

constructor/header.sh

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,53 @@ if ! echo "$0" | grep '\.sh$' > /dev/null; then
2121
fi
2222

2323
{%- if osx and min_osx_version %}
24-
min_osx_version="{{ min_osx_version }}"
25-
system_osx_version="${CONDA_OVERRIDE_OSX:-$(SYSTEM_VERSION_COMPAT=0 sw_vers -productVersion)}"
26-
# shellcheck disable=SC2183 disable=SC2046
27-
int_min_osx_version="$(printf "%02d%02d%02d" $(echo "$min_osx_version" | sed 's/\./ /g'))"
28-
# shellcheck disable=SC2183 disable=SC2046
29-
int_system_osx_version="$(printf "%02d%02d%02d" $(echo "$system_osx_version" | sed 's/\./ /g'))"
30-
if [ "$int_system_osx_version" -lt "$int_min_osx_version" ]; then
31-
echo "Installer requires macOS >=${min_osx_version}, but system has ${system_osx_version}."
32-
exit 1
24+
if [ "$(uname)" = "Darwin" ]; then
25+
min_osx_version="{{ min_osx_version }}"
26+
system_osx_version="${CONDA_OVERRIDE_OSX:-$(SYSTEM_VERSION_COMPAT=0 sw_vers -productVersion)}"
27+
# shellcheck disable=SC2183 disable=SC2046
28+
int_min_osx_version="$(printf "%02d%02d%02d" $(echo "$min_osx_version" | sed 's/\./ /g'))"
29+
# shellcheck disable=SC2183 disable=SC2046
30+
int_system_osx_version="$(printf "%02d%02d%02d" $(echo "$system_osx_version" | sed 's/\./ /g'))"
31+
if [ "$int_system_osx_version" -lt "$int_min_osx_version" ]; then
32+
echo "Installer requires macOS >=${min_osx_version}, but system has ${system_osx_version}."
33+
exit 1
34+
fi
3335
fi
3436
{%- elif linux and min_glibc_version %}
35-
min_glibc_version="{{ min_glibc_version }}"
36-
system_glibc_version="${CONDA_OVERRIDE_GLIBC:-}"
37-
if [ "${system_glibc_version}" = "" ]; then
38-
case "$(ldd --version 2>&1)" in
39-
*musl*)
40-
# musl ldd will report musl version; call libc.so directly
41-
# see https://github.com/conda/constructor/issues/850#issuecomment-2343756454
42-
libc_so="$(find /lib /usr/local/lib /usr/lib -name 'libc.so.*' -print -quit 2>/dev/null)"
43-
if [ -z "${libc_so}" ]; then
44-
libc_so="$(strings /etc/ld.so.cache | grep '^/.*/libc\.so.*' | head -1)"
45-
fi
46-
if [ -z "${libc_so}" ]; then
47-
echo "Warning: Couldn't find libc.so; won't be able to determine GLIBC version!" >&2
48-
echo "Override by setting CONDA_OVERRIDE_GLIBC" >&2
49-
system_glibc_version="0.0"
50-
else
51-
system_glibc_version=$("${libc_so}" --version | awk 'NR==1{ sub(/\.$/, ""); print $NF}')
52-
fi
53-
;;
54-
*)
55-
# ldd reports glibc in the last field of the first line
56-
system_glibc_version=$(ldd --version | awk 'NR==1{print $NF}')
57-
;;
58-
esac
59-
fi
60-
# shellcheck disable=SC2183 disable=SC2046
61-
int_min_glibc_version="$(printf "%02d%02d%02d" $(echo "$min_glibc_version" | sed 's/\./ /g'))"
62-
# shellcheck disable=SC2183 disable=SC2046
63-
int_system_glibc_version="$(printf "%02d%02d%02d" $(echo "$system_glibc_version" | sed 's/\./ /g'))"
64-
if [ "$int_system_glibc_version" -lt "$int_min_glibc_version" ]; then
65-
echo "Installer requires GLIBC >=${min_glibc_version}, but system has ${system_glibc_version}."
66-
exit 1
37+
if [ "$(uname)" = "Linux" ]; then
38+
min_glibc_version="{{ min_glibc_version }}"
39+
system_glibc_version="${CONDA_OVERRIDE_GLIBC:-}"
40+
if [ "${system_glibc_version}" = "" ]; then
41+
case "$(ldd --version 2>&1)" in
42+
*musl*)
43+
# musl ldd will report musl version; call libc.so directly
44+
# see https://github.com/conda/constructor/issues/850#issuecomment-2343756454
45+
libc_so="$(find /lib /usr/local/lib /usr/lib -name 'libc.so.*' -print -quit 2>/dev/null)"
46+
if [ -z "${libc_so}" ]; then
47+
libc_so="$(strings /etc/ld.so.cache | grep '^/.*/libc\.so.*' | head -1)"
48+
fi
49+
if [ -z "${libc_so}" ]; then
50+
echo "Warning: Couldn't find libc.so; won't be able to determine GLIBC version!" >&2
51+
echo "Override by setting CONDA_OVERRIDE_GLIBC" >&2
52+
system_glibc_version="0.0"
53+
else
54+
system_glibc_version=$("${libc_so}" --version | awk 'NR==1{ sub(/\.$/, ""); print $NF}')
55+
fi
56+
;;
57+
*)
58+
# ldd reports glibc in the last field of the first line
59+
system_glibc_version=$(ldd --version | awk 'NR==1{print $NF}')
60+
;;
61+
esac
62+
fi
63+
# shellcheck disable=SC2183 disable=SC2046
64+
int_min_glibc_version="$(printf "%02d%02d%02d" $(echo "$min_glibc_version" | sed 's/\./ /g'))"
65+
# shellcheck disable=SC2183 disable=SC2046
66+
int_system_glibc_version="$(printf "%02d%02d%02d" $(echo "$system_glibc_version" | sed 's/\./ /g'))"
67+
if [ "$int_system_glibc_version" -lt "$int_min_glibc_version" ]; then
68+
echo "Installer requires GLIBC >=${min_glibc_version}, but system has ${system_glibc_version}."
69+
exit 1
70+
fi
6771
fi
6872
{%- endif %}
6973

news/1094-add-guards-os-checks

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Enhancements
2+
3+
* <news item>
4+
5+
### Bug fixes
6+
7+
* Add guards to macOS and `glibc` version checks. (#1094)
8+
9+
### Deprecations
10+
11+
* <news item>
12+
13+
### Docs
14+
15+
* <news item>
16+
17+
### Other
18+
19+
* <news item>

0 commit comments

Comments
 (0)