forked from macports/mpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpbb-list-subports
136 lines (117 loc) · 4.69 KB
/
mpbb-list-subports
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
#!/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!
list-subports-usage() {
# "prog" is defined in mpbb-help.
# shellcheck disable=SC2154
cat <<EOF
usage: $prog [<global opts>] list-subports <port> [<port2> [...]]
Print the name and subports of each given port to standard output.
Options:
--archive-site=<URL>
URL of a mirror to check for preexisting archives. Defaults to
\`https://packages.macports.org'.
Run \`$prog help' for global options and a list of other subcommands.
EOF
}
print-subports() {
local archive_site=$1
local portname=$2
local port
local portgroup
local ports
local exclude
local exclude_reasons
local reason
os_version="$(sw_vers -productVersion | cut -d . -f 1-2)"
# $option_prefix is set in mpbb
# shellcheck disable=SC2154
tclsh=${option_prefix}/bin/port-tclsh
# $option_prefix is set in mpbb
# shellcheck disable=SC2154
ports=$("${option_prefix}/bin/port" -q info --index --line --name "${portname}" "subportof:${portname}" 2>/dev/null) || return
for port in $ports; do
exclude=0
exclude_reasons=()
# FIXME: this doesn't take selected variants into account
# $thisdir is set in mpbb
# shellcheck disable=SC2154
archive_path=$("${tclsh}" "${thisdir}/tools/archive-path.tcl" "${port}")
if [[ -f "${archive_path}" ]]; then
archive_basename=$(basename "${archive_path}")
if curl -fIsL "${archive_site}/${port}/${archive_basename}" > /dev/null; then
exclude=1
exclude_reasons+=("it has already been built and uploaded")
elif ! "${tclsh}" "${option_jobs_dir}/port_binary_distributable.tcl" "${port}"; then
exclude=1
exclude_reasons+=("it has already been built and is not distributable")
fi
fi
if [[ $exclude -eq 0 ]]; then
if [[ "$port" =~ graveyard ]]; then
exclude=1
exclude_reasons+=("its name contains 'graveyard'")
else
# $thisdir is set in mpbb
# shellcheck disable=SC2154
for portgroup in $("${tclsh}" "${thisdir}/tools/portgroups.tcl" "$port"); do
if [ "$portgroup" = "obsolete-1.0" ]; then
exclude=1
exclude_reasons+=("it includes the obsolete 1.0 PortGroup")
fi
done
fi
fi
if [[ $exclude -eq 0 && ("${os_version}" = "10.6" || "${os_version}" = "10.5") ]]; then
supported_archs=$("${tclsh}" "${thisdir}/tools/supported-archs.tcl" "${port}")
if [[ -n "${supported_archs}" ]]; then
is_64bit_capable="$(sysctl -n hw.cpu64bit_capable)"
if [[ "${os_version}" = "10.6" && "${is_64bit_capable}" = "0" && ! ("${supported_archs}" == *"x86_64"* && "${supported_archs}" == *"i386"*) ]]; then
exclude=1
exclude_reasons+=("the ${os_version}_x86_64 builder will build it")
elif [[ "${os_version}" = "10.5" && "${supported_archs}" != *"ppc"* && "${supported_archs}" != *"noarch"* ]]; then
exclude=1
exclude_reasons+=("it does not support the ppc arch")
fi
fi
fi
if [ $exclude -eq 0 ]; then
echo "$port"
else
if [ ${#exclude_reasons[@]} -eq 1 ]; then
echo >&2 "Excluding '${port}' because ${exclude_reasons[0]}."
else
echo >&2 "Excluding '${port}' for the following reasons:"
for reason in "${exclude_reasons[@]}"; do
echo >&2 " - ${reason}"
done
fi
fi
done
}
list-subports() {
# $option_log_dir is set in mpbb
# shellcheck disable=SC2154
local log_subports_progress="${option_log_dir}/ports-progress.txt"
local args
parseopt archive-site: "$@" || return
: "${option_archive_site=https://packages.macports.org}"
set -- ${args+"${args[@]}"}
if [ $# -le 0 ]; then
err "Must specify at least one port"
return 1
fi
success=0
# prepare the log file and make sure to start with an empty one
mkdir -p "$option_log_dir"
> "$log_subports_progress"
for p in "$@"; do
print-subports "$option_archive_site" "$p" && success=1
done
if [ $success -eq 0 ]; then
err "None of the specified ports were found in the port index."
return 1
fi
}