Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant support #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 30 additions & 36 deletions mpbb-install-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install-dependencies-usage() {
# "prog" is defined in mpbb-help.
# shellcheck disable=SC2154
cat <<EOF
usage: $prog [<global opts>] install-dependencies <port>
usage: $prog [<global opts>] install-dependencies <port>[@(+|-)variant [...]]

Build and install the dependencies of the given port.

Expand All @@ -18,11 +18,12 @@ EOF
}

install-dependencies() {
local port=${1-}
if [[ -z $port ]]; then
if [[ -z $1 ]]; then
err "Must specify a port"
return 1
fi
local port=${1%%@*}
local portvariants=${1:${#port}+1}
local dependencies
local dependencies_count
local dependencies_counter
Expand All @@ -36,12 +37,13 @@ install-dependencies() {

# prepare the log file and make sure to start with an empty one
mkdir -p "${option_log_dir}"
> "$log_status_dependencies"
:> "$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" "$@")
dependencies=$("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/dependencies.tcl" "$port" "$portvariants")
# shellcheck disable=SC2181
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"
Expand All @@ -61,18 +63,15 @@ install-dependencies() {
echo >> "$log_status_dependencies"

# save $@ since 'set' is used below
orig_args="$@"
orig_args="$*"

# 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#\"}"
# Split portname +variant1+variant2 into portname and variants, where
# the variants are optional.
depname=${dependency%% *}
depvariants=${dependency:${#depname}+1}

# $depvariants isn't quoted on purpose
# shellcheck disable=SC2086
Expand All @@ -90,41 +89,37 @@ install-dependencies() {
return 1
fi

# option_work_dir is set in mpbb
# shellcheck disable=SC2154
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}')"
# Split portname +variant1+variant2 into portname and variants, where
# the variants are optional.
depname=${dependency%% *}
depvariants=${dependency:${#depname}+1}

text="Installing dependency ($dependencies_counter of $dependencies_count) '${depname}' with variants '${depvariants}'"
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
if [[ -f $("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/archive-path.tcl" "${depname}" "${depvariants}") ]]; then
echo "Already installed, nothing to do"
echo "[OK]" >> "$log_status_dependencies"
dependencies_counter=$((dependencies_counter + 1))
else
# $deprequestedvariants isn't quoted on purpose
# $depvariants 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
if ! "${option_prefix}/bin/port" -dn install --unrequested "$depname" $depvariants; then
echo "Build of dependency '${depname}' with variants '${depvariants}' 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
if ! failcache_failure "$depname" $depvariants; then
err "failcache_failure $depname $depvariants failed."
return 1
fi
Expand All @@ -135,8 +130,7 @@ install-dependencies() {
# Remove failcache if it exists
# $depvariants isn't quoted on purpose
# shellcheck disable=SC2086
failcache_success "$depname" $depvariants
if [ $? -ne 0 ]; then
if ! failcache_success "$depname" $depvariants; then
err "failcache_success $depname $depvariants failed."
return 1
fi
Expand All @@ -148,21 +142,21 @@ install-dependencies() {
fi
fi
# add to the list for gather_archives
echo "$depname $deprequestedvariants" >> "${option_work_dir}/all_ports"
echo "$dependency" >> "${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
# $option_prefix and $thisdir are set in mpbb, orig_args is not quoted on purpose
# shellcheck disable=SC2154,SC2086
if [[ -f $("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/archive-path.tcl" ${orig_args}) ]]; then
echo "${orig_args} 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
if ! "${option_prefix}/bin/port" -dn install --unrequested ${dependencies}; then
echo "Activating all dependencies failed, aborting." >&2
return 1
fi
Expand Down
35 changes: 20 additions & 15 deletions mpbb-install-port
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install-port-usage() {
# "prog" is defined in mpbb-help.
# shellcheck disable=SC2154
cat <<EOF
usage: $prog [<global opts>] install-port <port>
usage: $prog [<global opts>] install-port <port>[@(+|-)variant [...]]

Build and install the given port.

Expand All @@ -18,11 +18,12 @@ EOF
}

install-port() {
local port=${1-}
if [[ -z $port ]]; then
if [[ -z $1 ]]; then
err "Must specify a port"
return 1
fi
local port=${1%%@*}
local portvariants=${1:${#port}+1}
# $option_log_dir is set in mpbb
# shellcheck disable=SC2154
local log_port_contents="${option_log_dir}/port-contents.txt"
Expand All @@ -33,11 +34,11 @@ install-port() {
# prepare the log files and make sure to start with empty ones
mkdir -p "${option_log_dir}"
#> "$log_port_contents"
> "$log_port_stats"
:> "$log_port_stats"

# $option_prefix and $thisdir are set in mpbb
# shellcheck disable=SC2154
if [[ -f $("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/archive-path.tcl" "$@") ]]; then
if [[ -f $("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/archive-path.tcl" "$port" "$portvariants") ]]; then
echo "$* already installed, nothing to do"
# log: summary for the portwatcher
echo "Building '$port' ... [OK]" >> "$log_subports_progress"
Expand All @@ -49,22 +50,20 @@ install-port() {
local time_stop
time_start=$(date +%s)
# $option_prefix is set in mpbb
# shellcheck disable=SC2154
if "${option_prefix}/bin/port" -dkn install "$@"; then
# shellcheck disable=SC2154,SC2086
if "${option_prefix}/bin/port" -dkn install "$port" $portvariants; then
# Remove failcache if it exists
failcache_success "$@"
if [ $? -ne 0 ]; then
err "failcache_success" "$@" "failed."
if ! failcache_success "$port" "$portvariants"; then
err "failcache_success $port $portvariants failed."
return 1
fi
else
echo "Build of '$port' failed."
# log: summary for the portwatcher
echo "Building '$port' ... [ERROR] maintainers: $(get-maintainers "$port")." >> "$log_subports_progress"
# update failcache
failcache_failure "$@"
if [ $? -ne 0 ]; then
err "failcache_failure" "$@" "failed."
if ! failcache_failure "$port" "$portvariants"; then
err "failcache_failure $port $portvariants failed."
return 1
fi
return 1
Expand All @@ -86,9 +85,11 @@ install-port() {
local print_arg_workdir="ERROR"
local print_arg_destdir="ERROR"
# First, compute port_workdir_size and port_destdir_size
port_workdir=$("${option_prefix}/bin/port" work "$port")
# shellcheck disable=SC2086
port_workdir=$("${option_prefix}/bin/port" work "$port" $portvariants)
if [ -n "$port_workdir" ]; then
port_workdir_size=$(du -ks "$port_workdir" | sed 's/^ *//' | tr '\t' '\n' | head -n 1)
# shellcheck disable=SC2181
if [ $? -eq 0 ] && [ -n "$port_workdir_size" ]; then
print_arg_workdir="${port_workdir_size}k"
fi
Expand All @@ -99,6 +100,7 @@ install-port() {
print_arg_destdir="-"
if [ -d "$port_destdir" ]; then
port_destdir_size=$(du -ks "$port_destdir" | sed 's/^ *//' | tr '\t' '\n' | head -n 1)
# shellcheck disable=SC2181
if [ $? -eq 0 ] && [ -n "$port_destdir_size" ]; then
print_arg_destdir="${port_destdir_size}k"
fi
Expand All @@ -111,7 +113,10 @@ install-port() {

# log: main.log
local port_mainlog
port_mainlog=$("${option_prefix}/bin/port" logfile "$port")
# portvariants is not quoted on purpose
# shellcheck disable=SC2086
port_mainlog=$("${option_prefix}/bin/port" logfile "$port" $portvariants)
# shellcheck disable=SC2181
if [ $? -eq 0 ] && [ -f "$port_mainlog" ]; then
cp -f "$port_mainlog" "$log_port_main"
fi
Expand Down
20 changes: 12 additions & 8 deletions mpbb-list-subports
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ list-subports-usage() {
# "prog" is defined in mpbb-help.
# shellcheck disable=SC2154
cat <<EOF
usage: $prog [<global opts>] list-subports [<opts>] <port> [<port2> [...]]
usage: $prog [<global opts>] list-subports [<opts>] <port>[@(+|-)variant [...]] [<port2>[@(+|-)variant [...]] [...]]

Print the name and subports of each given port to standard output.

Expand All @@ -25,7 +25,8 @@ EOF

print-subports() {
local archive_site=$1
local portname=$2
local portname=${2%%@*}
local portvariants=${2:${#portname}+1}
local port
local portgroup
local ports
Expand All @@ -44,16 +45,15 @@ print-subports() {
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}")
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}"; then
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
Expand All @@ -66,7 +66,7 @@ print-subports() {
else
# $thisdir is set in mpbb
# shellcheck disable=SC2154
for portgroup in $("${tclsh}" "${thisdir}/tools/portgroups.tcl" "$port"); do
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")
Expand All @@ -76,7 +76,7 @@ print-subports() {
fi

if [[ $exclude -eq 0 && ("${os_version}" = "10.6" || "${os_version}" = "10.5") ]]; then
supported_archs=$("${tclsh}" "${thisdir}/tools/supported-archs.tcl" "${port}")
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
Expand All @@ -90,7 +90,11 @@ print-subports() {
fi

if [ $exclude -eq 0 ]; then
echo "$port"
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]}."
Expand Down
20 changes: 5 additions & 15 deletions tools/dependencies.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ proc printdependency {ditem} {
# Given the active_variants of the current dependency calculation and the
# default variants, calculate the required string.
set default_variants {}
if {[info exists depinfo(vinfo)]} {
if {[array size variants] > 0 && [info exists depinfo(vinfo)]} {
foreach {vname vattrs} $depinfo(vinfo) {
foreach {key val} $vattrs {
if {$key eq "is_default" && $val eq "+"} {
Expand All @@ -113,29 +113,19 @@ proc printdependency {ditem} {
}
}

set activevariantstring ""
set requestedvariantstring ""
set variantstring ""
array set active_variants $depinfo(active_variants)

set relevant_variants [lsort -unique [concat [array names active_variants] $default_variants]]
foreach variant $relevant_variants {
if {[info exists active_variants($variant)]} {
append activevariantstring "$active_variants($variant)$variant"
if {$variant ni $default_variants} {
append requestedvariantstring "$active_variants($variant)$variant"
}
append variantstring "$active_variants($variant)$variant"
} else {
# the only case where this situation can occur is a default variant that was explicitly disabled
append requestedvariantstring "-$variant"
append variantstring "-$variant"
}
}

if {$activevariantstring eq ""} {
set activevariantstring {""}
}
if {$requestedvariantstring eq ""} {
set requestedvariantstring {""}
}
puts [string trim "$depinfo(name) $activevariantstring $requestedvariantstring"]
puts [string trim "$depinfo(name) $variantstring"]
}
dlist_eval $dlist {} [list printdependency]