forked from macports/mpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpbb-install-dependencies
177 lines (155 loc) · 7.2 KB
/
mpbb-install-dependencies
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
# -*- coding: utf-8; mode: sh; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=sh:et:sw=4:ts=4:sts=4
# Note:
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
install-dependencies-usage() {
# "prog" is defined in mpbb-help.
# shellcheck disable=SC2154
cat <<EOF
usage: $prog [<global opts>] install-dependencies <port>
Build and install the dependencies of the given port.
Run \`$prog help' for global options and a list of other subcommands.
EOF
}
get-maintainers() {
# '[email protected] github_username' => '[email protected]'
# $option_prefix is set in mpbb
# shellcheck disable=SC2154
"${option_prefix}/bin/port" info --index --maintainers --line "$@" \
| tr ', ' '\n' | fgrep '@' | tr '\n' ',' | sed 's/,$//'
}
install-dependencies() {
local port=${1-}
if [[ -z $port ]]; then
err "Must specify a port"
return 1
fi
local dependencies
local dependencies_count
local dependencies_counter
local depname
local depvariants
local failcachecounter
# $option_log_dir is set in mpbb
# shellcheck disable=SC2154
local log_status_dependencies="${option_log_dir}/dependencies-progress.txt"
local log_subports_progress="${option_log_dir}/ports-progress.txt"
# prepare the log file and make sure to start with an empty one
mkdir -p "${option_log_dir}"
> "$log_status_dependencies"
# calculate list of dependencies in-order
# $option_prefix and $thisdir are set in mpbb
# shellcheck disable=SC2154
dependencies=$("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/dependencies.tcl" "$@")
if [ $? -ne 0 ]; then
echo "Calculating dependencies for '$port' failed, aborting." >&2
echo "Building '$port' ... [ERROR] (failed to calculate dependencies) maintainers: $(get-maintainers "$port")." >> "$log_subports_progress"
return 1
fi
if [ -z "$dependencies" ]; then
echo "'$port' has no dependencies, continuing." >&2
return 0
fi
dependencies_count=$(echo "$dependencies" | wc -l | sed 's/ *//g')
dependencies_counter=1
echo "Installing $dependencies_count dependencies of $port:" | tee -a "$log_status_dependencies"
echo "$dependencies" | sed -E 's/^/ - /' | tee -a "$log_status_dependencies"
echo >> "$log_status_dependencies"
# Check whether any of the dependencies have previously failed
failcachecounter=0
while read -r dependency; do
# Split portname +variant1+variant2 into portname and active
# variants, where the variants are optional.
set $dependency
depname="$1"
# remove surrounding quotes
depvariants="${2%\"}"
depvariants="${depvariants#\"}"
# $depvariants isn't quoted on purpose
# shellcheck disable=SC2086
if ! failcache_test "$depname" $depvariants; then
text="Dependency '${depname}' with variants '${depvariants}' has previously failed and is required."
echo "$text" >&2
echo "$text" >> "$log_status_dependencies"
echo "Building '$port' ... [ERROR] (failed to install dependency '${depname}') maintainers: $(get-maintainers "$port" "${depname}")." >> "$log_subports_progress"
failcachecounter=$((failcachecounter + 1))
fi
done <<<"$dependencies"
if [ $failcachecounter -gt 0 ]; then
echo "Aborting build because $failcachecounter dependencies are known to fail." >&2
return 1
fi
rm -f "${option_work_dir}/all_ports"
while read -r dependency; do
# Split portname +variant1+variant2 into portname and active and
# requested variants, where the variants are optional.
set $dependency
depname=$1
# remove surrounding quotes
depvariants="${2%\"}"
depvariants="${depvariants#\"}"
deprequestedvariants="${3%\"}"
deprequestedvariants="${deprequestedvariants#\"}"
text="Installing dependency ($dependencies_counter of $dependencies_count) '${depname}' with variants '${depvariants}' (requesting '${deprequestedvariants}')"
echo "----> ${text}"
echo -n "${text} ... " >> "$log_status_dependencies"
# $option_prefix and $thisdir are set in mpbb
# shellcheck disable=SC2154
if [[ -f $("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/archive-path.tcl" "${depname}" "${deprequestedvariants}") ]]; then
echo "Already installed, nothing to do"
echo "[OK]" >> "$log_status_dependencies"
dependencies_counter=$((dependencies_counter + 1))
else
# $deprequestedvariants isn't quoted on purpose
# shellcheck disable=SC2154,SC2086
if ! "${option_prefix}/bin/port" -dn install --unrequested "$depname" $deprequestedvariants; then
echo "Build of dependency '${depname}' with variants '${deprequestedvariants}' failed, aborting." >&2
echo "[FAIL]" >> "$log_status_dependencies"
echo "Building '$port' ... [ERROR] (failed to install dependency '${depname}') maintainers: $(get-maintainers "$port" "${depname}")." >> "$log_subports_progress"
# Update failcache
# $depvariants isn't quoted on purpose
# shellcheck disable=SC2086
failcache_failure "$depname" $depvariants
if [ $? -ne 0 ]; then
err "failcache_failure $depname $depvariants failed."
return 1
fi
return 1
else
echo "[OK]" >> "$log_status_dependencies"
# Remove failcache if it exists
# $depvariants isn't quoted on purpose
# shellcheck disable=SC2086
failcache_success "$depname" $depvariants
if [ $? -ne 0 ]; then
err "failcache_success $depname $depvariants failed."
return 1
fi
dependencies_counter=$((dependencies_counter + 1))
# deactivate everything between builds
# $option_prefix is set by mpbb
# shellcheck disable=SC2154
"${option_prefix}/bin/port" -fp deactivate active
fi
fi
# add to the list for gather_archives
echo "$depname $deprequestedvariants" >> "${option_work_dir}/all_ports"
done <<<"$dependencies"
# activate everything now that we know it's all built and installed
# ... but only we're actually going to build the requested port
# $option_prefix and $thisdir are set in mpbb
# shellcheck disable=SC2154
if [[ -f $("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/archive-path.tcl" "$@") ]]; then
echo "$@ Already installed, not activating dependencies"
else
echo "Activating all dependencies..."
# $option_prefix is set by mpbb, and dependencies isn't quoted on purpose
# shellcheck disable=SC2154,SC2086
if ! "${option_prefix}/bin/port" -dn install --unrequested $(cat "${option_work_dir}/all_ports"); then
echo "Activating all dependencies failed, aborting." >&2
return 1
fi
echo "Done."
fi
}