Skip to content

Commit

Permalink
Implement build-install (as per #79) (#418)
Browse files Browse the repository at this point in the history
* Implement build-install

I'm still missing the bash and zsh completions

* Add tests

* Update bash-completion

When you type

  kerl build-install <tab><tab>

this'll suggest from the list of releases

It won't do anything if you type

  kerl build-install git <tab><tab>

* Update zsh-completion

When you type

  kerl build-install <tab><tab>

this'll suggest from the list of releases

It won't do anything if you type

  kerl build-install git <tab><tab>

* Update CI to remove set-output -related warning

* Tweak as per CI results
  • Loading branch information
paulo-ferraz-oliveira authored May 9, 2023
1 parent 2e0a695 commit 5660908
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,22 @@ jobs:
run: ./kerl delete installation $(./kerl path install_"$_KERL_VSN")
- name: Delete build
run: ./kerl delete build "$_KERL_VSN"
- name: Test build+install chosen version
run: |
export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
if ! KERL_DEBUG=true ./kerl build-install ${_KERL_PREFIX_GIT} \
${_KERL_PREFIX_GIT_TARGET} \
"${_KERL_VSN}" \
"${_KERL_VSN}" \
"$PWD/build-install_${_KERL_VSN}"; then
## Print build log if it fails
cat ~/.kerl/builds/*/*.log
exit 1
fi
- name: Check installation status (build+install)
run: ./kerl status
- name: Validate installation (build+install)
run: |
source $(./kerl path build-install_"${_KERL_VSN}")/activate
erl -s crypto -s init stop
erl_call
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ Activation will backup your $PATH, prepend it with the installation's bin/
directory. Thus it's only valid for the current shell session, and until you
activate another installation or call `kerl_deactivate`.

**Note**: alternatively you can use `kerl build-install` as a shortcut for
the two previous actions to be played in sequence.

$ kerl build-install
usage: ./kerl build-install <release> [build_name] [directory]

$ kerl build-install git
usage: ./kerl build-install git <git_url> <git_version> <build_name> [directory]

You're now ready to work with your 19.2 installation:

$ erl -version
Expand Down
11 changes: 10 additions & 1 deletion bash_completion/kerl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _kerl()
case $prev in
kerl)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W 'build install update upgrade list delete active path status' -- "$cur"))
COMPREPLY=($(compgen -W 'build install build-install update upgrade list delete active path status' -- "$cur"))
;;
list)
# shellcheck disable=SC2207
Expand Down Expand Up @@ -48,6 +48,15 @@ _kerl()
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$BUILDS" -- "$cur"))
;;
build-install)
if [ "$COMP_CWORD" -eq 2 ]; then
if [ -f "$HOME"/.kerl/otp_releases ]; then
RELEASES=$(cat "$HOME"/.kerl/otp_releases)
fi
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$RELEASES"))
fi
;;
path)
INSTALL_LIST="$HOME"/.kerl/otp_installations
if [ -f "$INSTALL_LIST" ]; then
Expand Down
72 changes: 72 additions & 0 deletions kerl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ usage() {
stderr 'Valid commands are:'
stderr ' build Build specified release or git repository'
stderr ' install Install the specified release at the given location'
stderr ' build-install Builds and installs the specified release or git repository at the given location'
stderr ' deploy Deploy the specified installation to the given host and location'
stderr ' update Update the list of available releases from your source provider'
stderr ' list List releases, builds and installations'
Expand Down Expand Up @@ -1165,6 +1166,39 @@ _do_build() {
fi
}

do_build_install() {
release_or_git=$1
git_url=$2
git_version=$3
build_name=$4
directory=$5

if is_valid_installation "$build_name"; then
l=e stderr "There's already an installation named $build_name. Skipping build step..."
exit 1
fi

# This is also done on do_install, but saves the build time in case of error
if ! is_valid_install_path "$directory"; then
exit 1
fi

if [ "$release_or_git" = "git" ]; then
$0 build git "$git_url" "$git_version" "$build_name"
else
release="$release_or_git"
$0 build "$release" "$build_name"
fi

status=$?
if [ $status -ne 0 ]; then
l=e stderr "Build failed! Skipping install step..."
exit 1
fi

$0 install "$build_name" "$directory"
}

do_install() {
if ! rel=$(get_release_from_name "$1"); then
l=e stderr "No build named $1"
Expand Down Expand Up @@ -2359,6 +2393,44 @@ case "$1" in
fi
fi
;;
build-install)
# naming contains _or_ because do_build_install either accepts $2 as "git" or otherwise
release_or_git="$2"
build_name_or_git_url="$3"
directory_or_git_version="$4"
build_name="$5"
directory="$6"

if [ "$release_or_git" = "git" ]; then
if [ $# -ne 5 ] && [ $# -ne 6 ]; then
l=e stderr "usage: $0 $1 git <git_url> <git_version> <build_name> [directory]"
exit 1
fi
git_url="$build_name_or_git_url"
git_version="$directory_or_git_version"
else
if [ $# -ne 2 ] && [ $# -ne 3 ] && [ $# -ne 4 ]; then
l=e stderr "usage: $0 $1 <release> [build_name] [directory]"
exit 1
fi
release="$release_or_git"
build_name="$build_name_or_git_url"
git_url="_unused_"
directory="$directory_or_git_version"
git_version="_unused_"
if [ $# -eq 2 ]; then
build_name="$release"
fi
fi
if [ -z "$directory" ]; then
if [ -z "$KERL_DEFAULT_INSTALL_DIR" ]; then
directory="$PWD"
else
directory="$KERL_DEFAULT_INSTALL_DIR/$build_name"
fi
fi
do_build_install "$release_or_git" "$git_url" "$git_version" "$build_name" "$directory"
;;
install)
if [ $# -lt 2 ]; then
l=e stderr "usage: $0 $1 <build_name> [directory]"
Expand Down
8 changes: 8 additions & 0 deletions zsh_completion/_kerl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local -a _1st_arguments
_1st_arguments=(
'build:Build specified release or git repository'
'install:Install the specified release at the given location'
'build-install:Build+install specified release or git repository'
'deploy:Deploy the specified installation to the given host and location'
'update:Update the list of available releases from erlang.org'
'upgrade:Upgrade kerl to the latest available version'
Expand Down Expand Up @@ -102,6 +103,13 @@ case "$words[1]" in
# TODO: suggest starting location of "$KERLDIR/$(lowercase $build)"
_directories
;;
build-install)
_arguments \
'1: :->rels' \

if [[ "$state" == rels ]]; then
_kerl_available_releases
_wanted releases expl 'all releases' compadd -a releases
path)
_arguments \
'1: :->installnames' && return 0
Expand Down

0 comments on commit 5660908

Please sign in to comment.