mirror of
https://github.com/crosstool-ng/crosstool-ng.git
synced 2025-02-20 17:12:55 +00:00
scripts/functions: add a save/restore handler
Saving and restoring the steps requires saving/restoring multiple directories. Depending on the configuration, some may not exist. Add a wrapper that checks before creating/extracting the tarballs.
This commit is contained in:
parent
09154a7162
commit
2d54ce4a2c
@ -909,6 +909,54 @@ CT_DoPause() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# This function creates a tarball of the specified directory, but
|
||||
# only if it exists
|
||||
# Usage: CT_DoTarballIfExists <dir> <tarball_basename> [extra_tar_options [...]]
|
||||
CT_DoTarballIfExists() {
|
||||
local dir="$1"
|
||||
local tarball="$2"
|
||||
shift 2
|
||||
local -a extra_tar_opts=( "$@" )
|
||||
local tar_opt
|
||||
|
||||
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
||||
y) tar_opt=-z; tar_ext=.gz;;
|
||||
*) tar_opt=; tar_ext=;;
|
||||
esac
|
||||
|
||||
if [ -d "${dir}" ]; then
|
||||
CT_DoLog DEBUG " Saving '${dir}'"
|
||||
CT_DoExecLog DEBUG tar c -C "${dir}" -v ${tar_opt} -f "${tarball}.tar${tar_ext}" "${extra_tar_opts[@]}" .
|
||||
else
|
||||
CT_DoLog DEBUG " Not saving '${dir}': does not exist"
|
||||
fi
|
||||
}
|
||||
|
||||
# This function extracts a tarball to the specified directory, but
|
||||
# only if the tarball exists
|
||||
# Usage: CT_DoTarballIfExists <tarball_basename> <dir> [extra_tar_options [...]]
|
||||
CT_DoExtractTarballIfExists() {
|
||||
local tarball="$1"
|
||||
local dir="$2"
|
||||
shift 2
|
||||
local -a extra_tar_opts=( "$@" )
|
||||
local tar_opt
|
||||
|
||||
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
||||
y) tar_opt=-z; tar_ext=.gz;;
|
||||
*) tar_opt=; tar_ext=;;
|
||||
esac
|
||||
|
||||
if [ -f "${tarball}.tar${tar_ext}" ]; then
|
||||
CT_DoLog DEBUG " Restoring '${dir}'"
|
||||
CT_DoForceRmdir "${dir}"
|
||||
CT_DoExecLog DEBUG mkdir -p "${dir}"
|
||||
CT_DoExecLog DEBUG tar x -C "${dir}" -v ${tar_opt} -f "${tarball}.tar${tar_ext}" "${extra_tar_opts[@]}"
|
||||
else
|
||||
CT_DoLog DEBUG " Not restoring '${dir}': does not exist"
|
||||
fi
|
||||
}
|
||||
|
||||
# This function saves the state of the toolchain to be able to restart
|
||||
# at any one point
|
||||
# Usage: CT_DoSaveState <next_step_name>
|
||||
@ -923,11 +971,6 @@ CT_DoSaveState() {
|
||||
rm -rf "${state_dir}"
|
||||
mkdir -p "${state_dir}"
|
||||
|
||||
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
||||
y) tar_opt=z; tar_ext=.gz;;
|
||||
*) tar_opt=; tar_ext=;;
|
||||
esac
|
||||
|
||||
CT_DoLog DEBUG " Saving environment and aliases"
|
||||
# We must omit shell functions, and some specific bash variables
|
||||
# that break when restoring the environment, later. We could do
|
||||
@ -942,31 +985,14 @@ CT_DoSaveState() {
|
||||
/^(FUNCNAME|GROUPS|PPID|SHELLOPTS)=/d;' >"${state_dir}/env.sh"
|
||||
|
||||
if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
|
||||
CT_DoLog DEBUG " Saving CT_COMPLIBS_DIR='${CT_COMPLIBS_DIR}'"
|
||||
CT_Pushd "${CT_COMPLIBS_DIR}"
|
||||
CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/complibs_dir.tar${tar_ext}" .
|
||||
CT_Popd
|
||||
# If complibs are not shared, then COMPLIBS_DIR == PREFIX_DIR,
|
||||
# so do not save.
|
||||
CT_DoTarballIfExists "${CT_COMPLIBS_DIR}" "${state_dir}/complibs_dir"
|
||||
fi
|
||||
|
||||
CT_DoLog DEBUG " Saving CT_CONFIG_DIR='${CT_CONFIG_DIR}'"
|
||||
CT_Pushd "${CT_CONFIG_DIR}"
|
||||
CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/config_dir.tar${tar_ext}" .
|
||||
CT_Popd
|
||||
|
||||
CT_DoLog DEBUG " Saving CT_CC_CORE_STATIC_PREFIX_DIR='${CT_CC_CORE_STATIC_PREFIX_DIR}'"
|
||||
CT_Pushd "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
||||
CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/cc_core_static_prefix_dir.tar${tar_ext}" .
|
||||
CT_Popd
|
||||
|
||||
CT_DoLog DEBUG " Saving CT_CC_CORE_SHARED_PREFIX_DIR='${CT_CC_CORE_SHARED_PREFIX_DIR}'"
|
||||
CT_Pushd "${CT_CC_CORE_SHARED_PREFIX_DIR}"
|
||||
CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/cc_core_shared_prefix_dir.tar${tar_ext}" .
|
||||
CT_Popd
|
||||
|
||||
CT_DoLog DEBUG " Saving CT_PREFIX_DIR='${CT_PREFIX_DIR}'"
|
||||
CT_Pushd "${CT_PREFIX_DIR}"
|
||||
CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/prefix_dir.tar${tar_ext}" --exclude '*.log' .
|
||||
CT_Popd
|
||||
CT_DoTarballIfExists "${CT_CONFIG_DIR}" "${state_dir}/config_dir"
|
||||
CT_DoTarballIfExists "${CT_CC_CORE_STATIC_PREFIX_DIR}" "${state_dir}/cc_core_static_prefix_dir"
|
||||
CT_DoTarballIfExists "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${state_dir}/cc_core_shared_prefix_dir"
|
||||
CT_DoTarballIfExists "${CT_PREFIX_DIR}" "${state_dir}/prefix_dir" --exclude '*.log'
|
||||
|
||||
if [ "${CT_LOG_TO_FILE}" = "y" ]; then
|
||||
CT_DoLog DEBUG " Saving log file"
|
||||
@ -997,40 +1023,14 @@ CT_DoLoadState(){
|
||||
# Log this to the log level required by the user
|
||||
CT_DoLog ${CT_LOG_LEVEL_MAX} "Restoring state at step '${state_name}', as requested."
|
||||
|
||||
case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
|
||||
y) tar_opt=z; tar_ext=.gz;;
|
||||
*) tar_opt=; tar_ext=;;
|
||||
esac
|
||||
|
||||
CT_DoLog DEBUG " Removing previous build directories"
|
||||
CT_DoForceRmdir "${CT_PREFIX_DIR}" "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${CT_CC_CORE_STATIC_PREFIX_DIR}" "${CT_CONFIG_DIR}"
|
||||
CT_DoExecLog DEBUG mkdir -p "${CT_PREFIX_DIR}" "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${CT_CC_CORE_STATIC_PREFIX_DIR}" "${CT_CONFIG_DIR}"
|
||||
|
||||
CT_DoLog DEBUG " Restoring CT_PREFIX_DIR='${CT_PREFIX_DIR}'"
|
||||
CT_Pushd "${CT_PREFIX_DIR}"
|
||||
CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/prefix_dir.tar${tar_ext}"
|
||||
CT_Popd
|
||||
|
||||
CT_DoLog DEBUG " Restoring CT_CC_CORE_SHARED_PREFIX_DIR='${CT_CC_CORE_SHARED_PREFIX_DIR}'"
|
||||
CT_Pushd "${CT_CC_CORE_SHARED_PREFIX_DIR}"
|
||||
CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/cc_core_shared_prefix_dir.tar${tar_ext}"
|
||||
CT_Popd
|
||||
|
||||
CT_DoLog DEBUG " Restoring CT_CC_CORE_STATIC_PREFIX_DIR='${CT_CC_CORE_STATIC_PREFIX_DIR}'"
|
||||
CT_Pushd "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
||||
CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/cc_core_static_prefix_dir.tar${tar_ext}"
|
||||
CT_Popd
|
||||
|
||||
CT_DoLog DEBUG " Restoring CT_CONFIG_DIR='${CT_CONFIG_DIR}'"
|
||||
CT_Pushd "${CT_CONFIG_DIR}"
|
||||
CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/config_dir.tar${tar_ext}"
|
||||
CT_Popd
|
||||
|
||||
CT_DoExtractTarballIfExists "${state_dir}/prefix_dir" "${CT_PREFIX_DIR}"
|
||||
CT_DoExtractTarballIfExists "${state_dir}/cc_core_shared_prefix_dir" "${CT_CC_CORE_SHARED_PREFIX_DIR}"
|
||||
CT_DoExtractTarballIfExists "${state_dir}/cc_core_static_prefix_dir" "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
||||
CT_DoExtractTarballIfExists "${state_dir}/config_dir" "${CT_CONFIG_DIR}"
|
||||
if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
|
||||
CT_DoLog DEBUG " Restoring CT_COMPLIBS_DIR='${CT_COMPLIBS_DIR}'"
|
||||
CT_Pushd "${CT_COMPLIBS_DIR}"
|
||||
CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/complibs_dir.tar${tar_ext}"
|
||||
CT_Popd
|
||||
# If complibs are not shared, then COMPLIBS_DIR == PREFIX_DIR,
|
||||
# so do not restore.
|
||||
CT_DoExtractTarballIfExists "${state_dir}/complibs_dir" "${CT_COMPLIBS_DIR}"
|
||||
fi
|
||||
|
||||
# Restore the environment, discarding any error message
|
||||
|
Loading…
x
Reference in New Issue
Block a user