diff options
Diffstat (limited to 'lib/cmd/build.sh')
-rw-r--r-- | lib/cmd/build.sh | 126 |
1 files changed, 59 insertions, 67 deletions
diff --git a/lib/cmd/build.sh b/lib/cmd/build.sh index 140ef4a..32dca26 100644 --- a/lib/cmd/build.sh +++ b/lib/cmd/build.sh @@ -19,11 +19,15 @@ # <http://www.gnu.org/licenses/>. use profile -use chroot +use session use rand use package use control +cmd_build_root= +cmd_build_pkg_dir= +cmd_build_build_deps= + cmd_build_main() { local root= @@ -31,12 +35,7 @@ cmd_build_main() local arch= local plat= local first_arg= - local prev_arg= local arg= - local dir= - local uname_s= - local build_deps= - local f= if [ ${#} -lt 2 ]; then print_cmd_usage 'build' >&2 @@ -44,6 +43,7 @@ cmd_build_main() fi root="${1}" + cmd_build_root="${root}" shift 1 opkbuild_optstring="$(cat "${root}/usr/share/opkbuild/optstring")" @@ -51,98 +51,90 @@ cmd_build_main() plat="$(cat "${root}/etc/proteanos_plat")" while getopts "${opkbuild_optstring}" opt 2>/dev/null; do case "${opt}" in - a) - arch="${OPTARG}" - ;; - p) - plat="${OPTARG}" - ;; + a) arch="${OPTARG}";; + p) plat="${OPTARG}";; esac 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}" - rand - dir="/prokit/build.${rand_x}" - uname_s="$( (uname -s) 2>/dev/null)" || uname_s='unknown' - mkdir -p "${root}${dir}/pkg" - case "${uname_s}" in - 'Linux') - mount -o bind "${prev_arg}" "${root}${dir}/pkg" - ;; - esac - - build_deps="$(package_get_build_deps "${arch}" "${plat}")" - if [ "x${build_deps}" != 'x' ]; then - mkdir -p "${root}${dir}/builddeps/control" \ - "${root}${dir}/builddeps/data" - cmd_build_make_deps_pkg "${root}${dir}" "${rand_x}" \ - "${build_deps}" + session_begin "${root}" "${cmd_build_pkg_dir}" cmd_build_fini false + + 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 - chroot_exec "${root}" sh <<-EOF - cd '${dir}/pkg' - if [ 'x${build_deps}' != 'x' ]; then - opkg install ../builddeps.opk - fi - opkbuild ${@} - if [ 'x${build_deps}' != 'x' ]; then - opkg --autoremove remove prokit-builddeps-${rand_x} - fi - EOF + session_exec opkbuild "${@}" - case "${uname_s}" in - 'Linux') - umount "${root}${dir}/pkg" - ;; - esac - rmdir "${root}${dir}/pkg" - rm -f "${root}${dir}/builddeps.opk" - for f in "${root}${dir}/"*; do - [ -e "${f}" ] || continue - mv "${f}" "${prev_arg}/.." - done - rmdir "${root}${dir}" + cmd_build_fini + + session_end } cmd_build_make_deps_pkg() { - local build_dir="${1}" - local build_id="${2}" - local build_deps="${3}" + local pkg_dir= - printf '2.0\n' >"${build_dir}/builddeps/debian-binary" - cat >"${build_dir}/builddeps/control/control" <<-EOF - Package: prokit-builddeps-${build_id} + 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 + Package: prokit-builddeps-$(session_id) Source: prokit Version: 1.0 Architecture: all Platform: all - Depends: ${build_deps} + Depends: ${cmd_build_build_deps} Description: Build dependencies metapackage generated by prokit EOF - (cd "${build_dir}/builddeps/data"; tar -czf ../data.tar.gz .) - (cd "${build_dir}/builddeps/control"; tar -czf ../control.tar.gz .) - (cd "${build_dir}/builddeps"; tar -czf ../builddeps.opk \ + (cd "${pkg_dir}/data"; tar -czf ../data.tar.gz .) + (cd "${pkg_dir}/control"; tar -czf ../control.tar.gz .) + (cd "${pkg_dir}"; tar -czf ../builddeps.opk \ 'debian-binary' 'data.tar.gz' 'control.tar.gz') - rm -Rf "${build_dir}/builddeps" + 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 } |