Files
mpbb/mpbb-list-subports
Clemens Lang 60af0776e8 Support specifying variants in list-subports
Allow passing variants into list-subports by separating port name and
variants specification with an "@" sign. @ is not a valid character in
port names and should allow us to specify variants per port in the
buildbot's portlist.

When not using this new syntax, the output will look exactly as it did
before to avoid breaking the existing setup.

Closes: https://trac.macports.org/ticket/52742
2018-03-11 17:35:23 +01:00

141 lines
4.9 KiB
Bash

#!/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 [<opts>] <port>[@(+|-)variant [...]] [<port2>[@(+|-)variant [...]] [...]]
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 portvariants=${2:${#portname}+1}
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=()
# $thisdir is set in mpbb
# shellcheck disable=SC2154
archive_path=$("${tclsh}" "${thisdir}/tools/archive-path.tcl" "${port}" "${portvariants}")
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}" "${portvariants}"; 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}" "${portvariants}"); 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}" "${portvariants}")
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
if [ -n "${portvariants}" ]; then
echo "${port}@${portvariants}"
else
echo "$port"
fi
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
}