Skip to content
Permalink
Browse files

Only request variants explicitly when needed.

  • Loading branch information
jmroot committed Jul 8, 2017
1 parent 3b66122 commit f6e46815a5033358212ce383956fd567eb51e53c
Showing with 39 additions and 21 deletions.
  1. +24 −16 mpbb-install-dependencies
  2. +15 −5 tools/dependencies.tcl
@@ -71,10 +71,13 @@ install-dependencies() {
# 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}
# 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
@@ -95,25 +98,30 @@ install-dependencies() {
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}'"
# 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}" "${depvariants}") ]]; then
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
# $depvariants isn't quoted on purpose
# $deprequestedvariants 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
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"

@@ -145,7 +153,7 @@ install-dependencies() {
fi
fi
# add to the list for gather_archives
echo "$dependency" >> "${option_work_dir}/all_ports"
echo "$depname $deprequestedvariants" >> "${option_work_dir}/all_ports"
done <<<"$dependencies"

# activate everything now that we know it's all built and installed
@@ -159,7 +167,7 @@ install-dependencies() {
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
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
@@ -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 {[array size variants] > 0 && [info exists depinfo(vinfo)]} {
if {[info exists depinfo(vinfo)]} {
foreach {vname vattrs} $depinfo(vinfo) {
foreach {key val} $vattrs {
if {$key eq "is_default" && $val eq "+"} {
@@ -113,19 +113,29 @@ proc printdependency {ditem} {
}
}

set variantstring ""
set activevariantstring ""
set requestedvariantstring ""
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 variantstring "$active_variants($variant)$variant"
append activevariantstring "$active_variants($variant)$variant"
if {$variant ni $default_variants} {
append requestedvariantstring "$active_variants($variant)$variant"
}
} else {
# the only case where this situation can occur is a default variant that was explicitly disabled
append variantstring "-$variant"
append requestedvariantstring "-$variant"
}
}

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

2 comments on commit f6e4681

@neverpanic

This comment has been minimized.

Copy link
Member

@neverpanic neverpanic replied Mar 11, 2018

@jmroot Do you remember why you added this change? I'm trying to add variant support to mpbb, and this causes problems for me.

Consider the following case: I'm trying to install pango +quartz-x11. install-dependencies will determine that it needs to install (among others) cairo +quartz (passing -x11 to achieve that) and glib2 +quartz (passing +quartz to achieve that).

However, this now doesn't work as expected. install-dependencies runs sudo port -nd install --unrequested glib2 +quartz and sudo port -nd install --unrequested cairo -x11, but the cairo installation passes these variants down to its dependency glib2 and attempts to install glib2 -x11, which fails because +x11 is the default for glib2. The -n flag does not prevent this.

Reverting this commit fixes that.

@jmroot

This comment has been minimized.

Copy link
Member Author

@jmroot jmroot replied Mar 11, 2018

It was because of #4.

Please sign in to comment.
You can’t perform that action at this time.