#!/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 <] install-dependencies [@(+|-)variant [...]] Build and install the dependencies of the given port. Run \`$prog help' for global options and a list of other subcommands. EOF } install-dependencies() { 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 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" "$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" 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" # save $@ since 'set' is used below 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 variants, where # the variants are optional. depname=${dependency%% *} depvariants=${dependency:${#depname}+1} # $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 # 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 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}" "${depvariants}") ]]; then echo "Already installed, nothing to do" echo "[OK]" >> "$log_status_dependencies" dependencies_counter=$((dependencies_counter + 1)) else # $depvariants isn't quoted on purpose # shellcheck disable=SC2154,SC2086 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 if ! failcache_failure "$depname" $depvariants; 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 if ! failcache_success "$depname" $depvariants; 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 "$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, 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 ${dependencies}; then echo "Activating all dependencies failed, aborting." >&2 return 1 fi echo "Done." fi }