improve stagefiles encapsulation

- added and used Stagefiles_dir()
 - added and used Stagefile_exists()

pretty self explanatory.

Gbp-Dch: Short
This commit is contained in:
Lyndon Brown 2020-05-02 14:49:45 +01:00
parent b20979334c
commit 2d7ff4934d
6 changed files with 31 additions and 14 deletions

View File

@ -21,7 +21,7 @@ Exit ()
# Skip if we have not yet completed the initial bootstrapping (bootstrap_debootstrap) # Skip if we have not yet completed the initial bootstrapping (bootstrap_debootstrap)
# (nothing to be done; avoids unhelpful messages) # (nothing to be done; avoids unhelpful messages)
if [ ! -e .build/bootstrap ]; then if ! Stagefile_exists bootstrap; then
return ${VALUE} return ${VALUE}
fi fi
@ -43,10 +43,12 @@ Exit ()
done done
fi fi
rm -f .build/chroot_devpts STAGEFILES_DIR="$(Stagefiles_dir)"
rm -f .build/chroot_proc
rm -f .build/chroot_selinuxfs rm -f "${STAGEFILES_DIR}"/chroot_devpts
rm -f .build/chroot_sysfs rm -f "${STAGEFILES_DIR}"/chroot_proc
rm -f "${STAGEFILES_DIR}"/chroot_selinuxfs
rm -f "${STAGEFILES_DIR}"/chroot_sysfs
Echo_message "Saving caches..." Echo_message "Saving caches..."
@ -54,7 +56,7 @@ Exit ()
# but let's assume that if there's any binary stage file arround # but let's assume that if there's any binary stage file arround
# we are in binary stage. # we are in binary stage.
if ls .build/binary* > /dev/null 2>&1 if ls "${STAGEFILES_DIR}"/binary* > /dev/null 2>&1
then then
Save_package_cache binary Save_package_cache binary
else else

View File

@ -12,7 +12,7 @@
Auto_build_config () Auto_build_config ()
{ {
# Automatically build config # Automatically build config
if [ -x auto/config ] && [ ! -e .build/config ]; then if [ -x auto/config ] && ! Stagefile_exists config; then
Echo_message "Automatically populating config tree." Echo_message "Automatically populating config tree."
lb config lb config
fi fi

View File

@ -9,6 +9,11 @@
## under certain conditions; see COPYING for details. ## under certain conditions; see COPYING for details.
Stagefiles_dir ()
{
echo ".build"
}
# Get the default filename for a script's stagefile (the name of the script # Get the default filename for a script's stagefile (the name of the script
# file itself). A suffix can be appended via providing as a param. # file itself). A suffix can be appended via providing as a param.
Stagefile_name () Stagefile_name ()
@ -19,6 +24,14 @@ Stagefile_name ()
echo ${FILENAME}${SUFFIX:+.$SUFFIX} echo ${FILENAME}${SUFFIX:+.$SUFFIX}
} }
Stagefile_exists ()
{
if [ -f ".build/${1:-$(Stagefile_name)}" ]; then
return 0
fi
return 1
}
Check_stagefile () Check_stagefile ()
{ {
local FILE local FILE

View File

@ -94,7 +94,7 @@ if In_list "archives" ${HELPERS} && [ -z "${ARCHIVES_PASS}" ]; then
exit 1 exit 1
fi fi
if In_list "archives" ${HELPERS} && [ ! -e .build/bootstrap ]; then if In_list "archives" ${HELPERS} && ! Stagefile_exists bootstrap; then
Echo_warning "The 'archives' helper is selected, but the bootstrap stage has not completed." Echo_warning "The 'archives' helper is selected, but the bootstrap stage has not completed."
fi fi

View File

@ -46,6 +46,8 @@ else
ARGUMENTS="${@}" ARGUMENTS="${@}"
fi fi
STAGEFILES_DIR="$(Stagefiles_dir)"
for ARGUMENT in ${ARGUMENTS} for ARGUMENT in ${ARGUMENTS}
do do
case "${ARGUMENT}" in case "${ARGUMENT}" in
@ -85,7 +87,7 @@ do
rm -f chroot.packages.live chroot.packages.install rm -f chroot.packages.live chroot.packages.install
rm -f chroot.files rm -f chroot.files
rm -f .build/chroot* rm -f "${STAGEFILES_DIR}"/chroot*
;; ;;
--binary) --binary)
@ -104,7 +106,7 @@ do
rm -rf binary rm -rf binary
rm -rf tftpboot rm -rf tftpboot
rm -f .build/binary* rm -f "${STAGEFILES_DIR}"/binary*
;; ;;
--remove) --remove)
@ -118,12 +120,12 @@ do
if [ -e auto/config ] if [ -e auto/config ]
then then
rm -f .build/config Remove_stagefile config
fi fi
;; ;;
--stage) --stage)
rm -rf .build/* rm -rf "${STAGEFILES_DIR}"/*
;; ;;
--source) --source)
@ -136,7 +138,7 @@ do
rm -rf source rm -rf source
rm -f .build/source* rm -f "${STAGEFILES_DIR}"/source*
;; ;;
-h|--help) -h|--help)

View File

@ -871,7 +871,7 @@ fi
# Ignoring --config if CWD already has a config # Ignoring --config if CWD already has a config
# Only print warning from direct execution, not when run from auto script redirection, to avoid repetition # Only print warning from direct execution, not when run from auto script redirection, to avoid repetition
if [ -e .build/config ] && [ -n "${_CONFIG}" ] if Stagefile_exists && [ -n "${_CONFIG}" ]
then then
if [ "${1}" != "noauto" ] if [ "${1}" != "noauto" ]
then then