Skip to content

Commit

Permalink
;pkg:hledger-install: try third party packages again without bounds
Browse files Browse the repository at this point in the history
This makes hledger-iadd and hledger-interest more likely to install
successfully, even if their bounds have not yet been updated for a new
hledger release.
  • Loading branch information
simonmichael committed Dec 13, 2024
1 parent 57bc54b commit c9128c6
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions hledger-install/hledger-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ cmd_location() {
# Get the given command's version, ie the first number in the first line of its --version output,
# or empty string if there's a problem.
cmd_version() {
(command "$1" --version 2>/dev/null | head -n1 | grep -E '[0-9]' | $SED -e 's/[^0-9]*([0-9][0-9.]*).*/\1/') || ""
(command "$1" --version 2>/dev/null | head -n1 | grep -E '[0-9]' | $SED -e 's/[^0-9]*([0-9][0-9.]*).*/\1/') || echo ""
}

# Check whether the given command exists with given version
Expand Down Expand Up @@ -898,11 +898,24 @@ quietly_run() {
try_install() {
cd # ensure we install at user level, not in some project's stack/cabal setup
if has_cmd stack ; then
try_info stack install --install-ghc --resolver $STACKAGE_SNAPSHOT "$@" --verbosity="$STACK_VERBOSITY" || echo "Failed to install $@"
try_info stack install --install-ghc --resolver $STACKAGE_SNAPSHOT "$@" --verbosity="$STACK_VERBOSITY" || (echo "Failed to install $@"; false)
elif has_cmd cabal ; then
try_info cabal install "$@" --verbose="$CABAL_VERBOSITY" || echo "Failed to install $@"
try_info cabal install "$@" --verbose="$CABAL_VERBOSITY" || (echo "Failed to install $@"; false)
else
echo "Failed to install $@"
echo "Failed to install $@"; false
fi
}

# Like the above but try harder, ignoring dependency bounds. Could potentially try to install something very old.
try_install_ignore_bounds() {
cd # ensure we install at user level, not in some project's stack/cabal setup
echo "Trying without dependency bounds"
if has_cmd stack ; then
try_info stack install --allow-newer --install-ghc --resolver $STACKAGE_SNAPSHOT "$@" --verbosity="$STACK_VERBOSITY" || (echo "Failed to install $@"; false)
elif has_cmd cabal ; then
try_info cabal install --allow-newer "$@" --verbose="$CABAL_VERBOSITY" || (echo "Failed to install $@"; false)
else
echo "Failed to install $@"; false
fi
}

Expand All @@ -913,7 +926,7 @@ try_install_py() {
if has_cmd pip ; then
try_info pip install --disable-pip-version-check -U "$@" $PIP_VERBOSITY
else
echo "Failed to install $@"
echo "Failed to install $@"; false
fi
}

Expand Down Expand Up @@ -1076,20 +1089,22 @@ else
fi

# Third-party addons.
# We might have to build these with an older version of hledger,
# if they have not been updated yet.
# These often won't build with new hledger right away just because of tight bounds,
# so we'll also try building without bounds. Perhaps a little risky.

if [[ $(cmpver "$(cmd_version hledger-iadd 2>/dev/null)" $HLEDGER_IADD_VERSION) = 2 ]]; then
echo Installing hledger-iadd
try_install hledger-iadd-$HLEDGER_IADD_VERSION hledger-lib-$HLEDGER_LIB_VERSION $STACK_EXTRA_DEPS
try_install hledger-iadd-$HLEDGER_IADD_VERSION hledger-lib-$HLEDGER_LIB_VERSION $STACK_EXTRA_DEPS \
|| try_install_ignore_bounds hledger-iadd-$HLEDGER_IADD_VERSION hledger-lib-$HLEDGER_LIB_VERSION $STACK_EXTRA_DEPS
echo
else
echo hledger-iadd is up to date
fi

if [[ $(cmpver "$(cmd_version hledger-interest 2>/dev/null)" $HLEDGER_INTEREST_VERSION) = 2 ]]; then
echo Installing hledger-interest
try_install hledger-interest-$HLEDGER_INTEREST_VERSION hledger-lib-$HLEDGER_LIB_VERSION $STACK_EXTRA_DEPS
try_install hledger-interest-$HLEDGER_INTEREST_VERSION hledger-lib-$HLEDGER_LIB_VERSION $STACK_EXTRA_DEPS \
|| try_install_ignore_bounds hledger-interest-$HLEDGER_INTEREST_VERSION hledger-lib-$HLEDGER_LIB_VERSION $STACK_EXTRA_DEPS
echo
else
echo hledger-interest is up to date
Expand Down

0 comments on commit c9128c6

Please sign in to comment.