diff --git a/install.sh b/install.sh index 4c33aa3..a38e033 100755 --- a/install.sh +++ b/install.sh @@ -93,7 +93,7 @@ echo_run mkdir -p "${dest_dir}" echo_run tar -C "${dest_dir}" -x -f "${tmp_dir}/atomvm_packbeam-${version}.tar" echo_run mkdir -p "${prefix}/bin" -echo_run sed "s|PACKBEAM_INSTALL_LOCATION|${dest_dir}|g" "${root_dir}/release/packbeam.in" > "${prefix}/bin/packbeam" +echo_run mv "${dest_dir}/bin/packbeam.sh" "${prefix}/bin/packbeam" echo_run chmod 755 "${prefix}/bin/packbeam" echo_run rm -rf "${tmp_dir}" diff --git a/rebar.config b/rebar.config index cbce9c3..6eb4277 100644 --- a/rebar.config +++ b/rebar.config @@ -38,11 +38,18 @@ {mode, prod}, {generate_start_script, false}, {overlay, [ - {copy, "src/packbeam.erl", "bin/packbeam.escript"} + {template, "release/packbeam.in", "bin/packbeam.sh"} ]} ]}. -%% copy and rename escript next to `packbeam.escript` (See escript man page) +%% make sure escriptize is run before we release +{provider_hooks, [ + {pre, [ + {release, escriptize} + ]} +]}. + +%% copy the generated escript into the release {post_hooks, [ - {release, "cp ${REBAR_BUILD_DIR}/rel/atomvm_packbeam/erts-${ERLANG_ERTS_VER}/bin/escript ${REBAR_BUILD_DIR}/rel/atomvm_packbeam/bin/packbeam"} + {release, "cp ${REBAR_BUILD_DIR}/bin/packbeam ${REBAR_BUILD_DIR}/rel/atomvm_packbeam/bin/packbeam"} ]}. diff --git a/release/packbeam.in b/release/packbeam.in index f1bfdc4..239748e 100644 --- a/release/packbeam.in +++ b/release/packbeam.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -e # # This file is part of AtomVM. # @@ -19,4 +19,10 @@ # SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later # -exec PACKBEAM_INSTALL_LOCATION/bin/packbeam "$@" +root_dir="$(cd $(dirname $0)/.. && pwd)" +pkg_root="${root_dir}/atomvm_packbeam" + +PATH="${pkg_root}/erts-{{ release_erts_version }}/bin:${PATH}" +export PATH + +exec ${pkg_root}/bin/packbeam "$@" diff --git a/src/packbeam.erl b/src/packbeam.erl index 9d784fc..06b231d 100644 --- a/src/packbeam.erl +++ b/src/packbeam.erl @@ -28,13 +28,6 @@ %% escript -export([main/1]). -%% -%% MAINTENANCE NOTE. Due to an issue loading our atomvm_packbeam -%% application from an escript in a release, we need to fall back to -%% a hard-wired version string. -%% --define(CURRENT_VERSION, "0.7.0"). - %% %% Public API %% @@ -177,10 +170,10 @@ get_version() -> {_, _, Version} -> Version; false -> - ?CURRENT_VERSION + "Error! Unable to find atomvm_packbeam in loaded applications" end; {error, _Reason} -> - ?CURRENT_VERSION + "Error! Unable to load atomvm_packbeam application" end. %% @private