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

Implement build-install (as per #79) #418

Merged
merged 6 commits into from
May 9, 2023
Merged
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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Git checkout
uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@1.1.0
uses: ludeeus/action-shellcheck@2.0.0
# uses .markdownlint.yml for configuration
- name: Run markdownlint
uses: DavidAnson/markdownlint-cli2-action@v7
Expand Down
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