diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cmd/build.sh | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/lib/cmd/build.sh b/lib/cmd/build.sh index bbcb837..4d2bf0e 100644 --- a/lib/cmd/build.sh +++ b/lib/cmd/build.sh @@ -24,6 +24,10 @@ use rand use package use control +cmd_build_root= +cmd_build_pkg_dir= +cmd_build_build_deps= + cmd_build_main() { local root= @@ -31,11 +35,7 @@ cmd_build_main() local arch= local plat= local first_arg= - local prev_arg= local arg= - local session_dir= - local build_deps= - local f= if [ ${#} -lt 2 ]; then print_cmd_usage 'build' >&2 @@ -43,6 +43,7 @@ cmd_build_main() fi root="${1}" + cmd_build_root="${root}" shift 1 opkbuild_optstring="$(cat "${root}/usr/share/opkbuild/optstring")" @@ -60,59 +61,47 @@ cmd_build_main() done first_arg=true - prev_arg= + cmd_build_pkg_dir='' for arg in "${@}"; do if ${first_arg}; then set -- first_arg=false else - set -- "${@}" "${prev_arg}" + set -- "${@}" "${cmd_build_pkg_dir}" fi - prev_arg="${arg}" + cmd_build_pkg_dir="${arg}" done . "${root}/etc/os-release" profile_set "${ID}" - if ! [ -d "${prev_arg}" ]; then - error 2 "$(get_msg 'cmd_build_not_a_dir')" "${prev_arg}" + if ! [ -d "${cmd_build_pkg_dir}" ]; then + error 2 "$(get_msg 'cmd_build_not_a_dir')" \ + "${cmd_build_pkg_dir}" fi - package_init "${prev_arg}" + package_init "${cmd_build_pkg_dir}" package_set_substvars "${arch}" "${plat}" - session_begin "${root}" "${prev_arg}" : false - session_dir="$(session_dir)" + session_begin "${root}" "${cmd_build_pkg_dir}" cmd_build_fini false - build_deps="$(package_get_build_deps "${arch}" "${plat}")" - if [ "x${build_deps}" != 'x' ]; then - cmd_build_make_deps_pkg "${root}" "${build_deps}" + cmd_build_build_deps="$(package_get_build_deps "${arch}" "${plat}")" + if [ "x${cmd_build_build_deps}" != 'x' ]; then + cmd_build_make_deps_pkg session_exec opkg install ../builddeps.opk fi session_exec opkbuild "${@}" - if [ "x${build_deps}" != 'x' ]; then - session_exec opkg --autoremove remove \ - prokit-builddeps-$(session_id) - rm "${root}${session_dir}/builddeps.opk" - fi - - for f in "${root}${session_dir}/"*; do - [ -e "${f}" ] || continue - [ "x${f##*/}" = 'xwd' ] && continue - mv "${f}" "${prev_arg}/.." - done + cmd_build_fini session_end } cmd_build_make_deps_pkg() { - local root="${1}" - local build_deps="${2}" local pkg_dir= - pkg_dir="${root}$(session_dir)/builddeps" + pkg_dir="${cmd_build_root}$(session_dir)/builddeps" mkdir -p "${pkg_dir}/control" "${pkg_dir}/data" printf '2.0\n' >"${pkg_dir}/debian-binary" cat >"${pkg_dir}/control/control" <<-EOF @@ -121,7 +110,7 @@ cmd_build_make_deps_pkg() Version: 1.0 Architecture: all Platform: all - Depends: ${build_deps} + Depends: ${cmd_build_build_deps} Description: Build dependencies metapackage generated by prokit EOF (cd "${pkg_dir}/data"; tar -czf ../data.tar.gz .) @@ -130,3 +119,26 @@ cmd_build_make_deps_pkg() 'debian-binary' 'data.tar.gz' 'control.tar.gz') rm -Rf "${pkg_dir}" } + +cmd_build_fini() +{ + local session_dir= + local f= + + session_dir="$(session_dir)" + + if [ "x${cmd_build_build_deps}" != 'x' ]; then + session_exec opkg --autoremove remove \ + prokit-builddeps-$(session_id) + rm "${cmd_build_root}${session_dir}/builddeps.opk" + # Hack to avoid this code branch if the function is called again + # in response to a signal. + cmd_build_build_deps='' + fi + + for f in "${cmd_build_root}${session_dir}/"*; do + [ -e "${f}" ] || continue + [ "x${f##*/}" = 'xwd' ] && continue + mv "${f}" "${cmd_build_pkg_dir}/.." + done +} |