-
Notifications
You must be signed in to change notification settings - Fork 2
/
pkg_checks.sh
130 lines (119 loc) · 4.6 KB
/
pkg_checks.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
#
# Check for the presence of required packages/commands.
#
# This build requires:
# * a C compiler, e.g. gcc (if there is stuff to build, e.g. not on Windows)
# * build tools: make, m4 (same as above)
# * patch (for applying patches from src/, these can be hotfixes to .py files)
# * git (for patching Python's version, if building Python)
# * a C++ compiler for testing Python C++ extensions (test_cppext).
# * automake, libtool, headers of a curses library (if building libedit)
# * perl 5.10.0 or newer, Test::More 0.96 or newer (if building OpenSSL)
# * curl, sha512sum, tar, unzip (for downloading and unpacking)
#
# On platforms with multiple C compilers, choose by setting CC in os_quirks.sh.
# List of OS packages required for building Python/pyOpenSSL/cryptography etc.
BASE_PKGS="gcc make m4 patch perl"
if [ "$BUILD_LIBEDIT" = "yes" ]; then
BASE_PKGS="$BASE_PKGS automake libtool"
fi
APK_PKGS="$BASE_PKGS git curl bash musl-dev linux-headers lddtree \
openssh-client file g++ musl-locales dejagnu"
DEB_PKGS="$BASE_PKGS unzip tar diffutils git curl \
openssh-client libtest-simple-perl xz-utils g++ dejagnu"
RPM_PKGS="$BASE_PKGS bzip2 unzip tar diffutils git-core curl \
openssh-clients perl-Test-Simple perl-IPC-Cmd xz gcc-c++ dejagnu"
# Check for OS packages required for the build.
MISSING_PACKAGES=""
# Generic list of required commands (not an array because it's never executed).
PACKAGES="$CC make m4 git patch curl sha512sum tar unzip"
# This is defined as an array of commands and opts, to allow it to be quoted.
CHECK_CMD=(command -v)
# $CHECK_CMD should exit with 0 only when checked package is installed.
case "$OS" in
windows)
# Nothing to actually build on Windows.
PACKAGES="curl sha512sum"
;;
macos)
# Avoid using Homebrew tools from /usr/local. It is also needed to neuter
# /usr/local libs to avoid polluting the build with unwanted deps.
# See the macOS job in the "bare" GitHub Actions workflow for details.
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
PACKAGES="$CC make m4 git patch libtool perl curl shasum tar unzip"
;;
fbsd*)
PACKAGES="$CC make m4 git patch libtool curl shasum tar unzip"
;;
obsd*)
PACKAGES="$CC make m4 git patch libtool curl sha512 tar unzip"
;;
linux*)
if [ -x /sbin/apk ]; then
# Assumes Alpine Linux 3.15.
CHECK_CMD=(/sbin/apk info -q -e)
PACKAGES="$APK_PKGS"
elif [ -x /usr/bin/dpkg ]; then
# Assumes Ubuntu Linux 16.04.
CHECK_CMD=(dpkg --status)
PACKAGES="$DEB_PKGS"
elif [ -x /usr/bin/rpm ]; then
# Assumes Amazon Linux 2.
CHECK_CMD=(rpm --query)
PACKAGES="$RPM_PKGS"
else
PACKAGES="$PACKAGES perl"
fi
;;
esac
# External checks with various exit codes are checked below.
set +o errexit
# If $CHECK_CMD is still "(command -v)", it's only a check for needed commands.
if [ -n "$PACKAGES" ]; then
for package in $PACKAGES ; do
echo "Checking if $package is available..."
if ! "${CHECK_CMD[@]}" "$package"; then
echo "Missing required dependency: $package"
MISSING_PACKAGES="$MISSING_PACKAGES $package"
fi
done
fi
if [ -n "$MISSING_PACKAGES" ]; then
(>&2 echo "Missing required dependencies: $MISSING_PACKAGES.")
exit 149
fi
if [ -n "$PACKAGES" ]; then
echo "All required dependencies are present: $PACKAGES"
fi
# Windows "build" is special, following checks are for other platforms.
if [ "$OS" = "windows" ]; then
set -o errexit
return
fi
# Many systems don't have this installed and it's not really need it.
if ! command -v makeinfo >/dev/null; then
(>&2 echo "# Missing makeinfo, linking it to /bin/true in ~/bin... #")
execute mkdir -p ~/bin
execute rm -f ~/bin/makeinfo
execute ln -s /bin/true ~/bin/makeinfo
export PATH="$PATH:~/bin/"
fi
# To avoid having Python's uuid module linked to system libs.
echo "# Checking if it's possible to avoid linking to system uuid libs... #"
case "$OS" in
ubuntu*)
"${CHECK_CMD[@]}" uuid-dev \
&& echo "To not link to uuid libs, run: apt remove -y uuid-dev"
;;
rhel*|amzn*)
"${CHECK_CMD[@]}" libuuid-devel \
&& echo -n "To not link to uuid libs, run: " \
&& echo "yum remove -y e2fsprogs-devel libuuid-devel"
;;
*)
(>&2 echo "Not guarding against linking to uuid libs on this system!")
;;
esac
# This script is sourced, execution does not end here.
set -o errexit