1.1 --- a/scripts/functions Tue Apr 13 20:05:47 2010 +0200
1.2 +++ b/scripts/functions Tue Apr 13 20:52:38 2010 +0200
1.3 @@ -909,6 +909,54 @@
1.4 return 0
1.5 }
1.6
1.7 +# This function creates a tarball of the specified directory, but
1.8 +# only if it exists
1.9 +# Usage: CT_DoTarballIfExists <dir> <tarball_basename> [extra_tar_options [...]]
1.10 +CT_DoTarballIfExists() {
1.11 + local dir="$1"
1.12 + local tarball="$2"
1.13 + shift 2
1.14 + local -a extra_tar_opts=( "$@" )
1.15 + local tar_opt
1.16 +
1.17 + case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
1.18 + y) tar_opt=-z; tar_ext=.gz;;
1.19 + *) tar_opt=; tar_ext=;;
1.20 + esac
1.21 +
1.22 + if [ -d "${dir}" ]; then
1.23 + CT_DoLog DEBUG " Saving '${dir}'"
1.24 + CT_DoExecLog DEBUG tar c -C "${dir}" -v ${tar_opt} -f "${tarball}.tar${tar_ext}" "${extra_tar_opts[@]}" .
1.25 + else
1.26 + CT_DoLog DEBUG " Not saving '${dir}': does not exist"
1.27 + fi
1.28 +}
1.29 +
1.30 +# This function extracts a tarball to the specified directory, but
1.31 +# only if the tarball exists
1.32 +# Usage: CT_DoTarballIfExists <tarball_basename> <dir> [extra_tar_options [...]]
1.33 +CT_DoExtractTarballIfExists() {
1.34 + local tarball="$1"
1.35 + local dir="$2"
1.36 + shift 2
1.37 + local -a extra_tar_opts=( "$@" )
1.38 + local tar_opt
1.39 +
1.40 + case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
1.41 + y) tar_opt=-z; tar_ext=.gz;;
1.42 + *) tar_opt=; tar_ext=;;
1.43 + esac
1.44 +
1.45 + if [ -f "${tarball}.tar${tar_ext}" ]; then
1.46 + CT_DoLog DEBUG " Restoring '${dir}'"
1.47 + CT_DoForceRmdir "${dir}"
1.48 + CT_DoExecLog DEBUG mkdir -p "${dir}"
1.49 + CT_DoExecLog DEBUG tar x -C "${dir}" -v ${tar_opt} -f "${tarball}.tar${tar_ext}" "${extra_tar_opts[@]}"
1.50 + else
1.51 + CT_DoLog DEBUG " Not restoring '${dir}': does not exist"
1.52 + fi
1.53 +}
1.54 +
1.55 # This function saves the state of the toolchain to be able to restart
1.56 # at any one point
1.57 # Usage: CT_DoSaveState <next_step_name>
1.58 @@ -923,11 +971,6 @@
1.59 rm -rf "${state_dir}"
1.60 mkdir -p "${state_dir}"
1.61
1.62 - case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
1.63 - y) tar_opt=z; tar_ext=.gz;;
1.64 - *) tar_opt=; tar_ext=;;
1.65 - esac
1.66 -
1.67 CT_DoLog DEBUG " Saving environment and aliases"
1.68 # We must omit shell functions, and some specific bash variables
1.69 # that break when restoring the environment, later. We could do
1.70 @@ -942,31 +985,14 @@
1.71 /^(FUNCNAME|GROUPS|PPID|SHELLOPTS)=/d;' >"${state_dir}/env.sh"
1.72
1.73 if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
1.74 - CT_DoLog DEBUG " Saving CT_COMPLIBS_DIR='${CT_COMPLIBS_DIR}'"
1.75 - CT_Pushd "${CT_COMPLIBS_DIR}"
1.76 - CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/complibs_dir.tar${tar_ext}" .
1.77 - CT_Popd
1.78 + # If complibs are not shared, then COMPLIBS_DIR == PREFIX_DIR,
1.79 + # so do not save.
1.80 + CT_DoTarballIfExists "${CT_COMPLIBS_DIR}" "${state_dir}/complibs_dir"
1.81 fi
1.82 -
1.83 - CT_DoLog DEBUG " Saving CT_CONFIG_DIR='${CT_CONFIG_DIR}'"
1.84 - CT_Pushd "${CT_CONFIG_DIR}"
1.85 - CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/config_dir.tar${tar_ext}" .
1.86 - CT_Popd
1.87 -
1.88 - CT_DoLog DEBUG " Saving CT_CC_CORE_STATIC_PREFIX_DIR='${CT_CC_CORE_STATIC_PREFIX_DIR}'"
1.89 - CT_Pushd "${CT_CC_CORE_STATIC_PREFIX_DIR}"
1.90 - CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/cc_core_static_prefix_dir.tar${tar_ext}" .
1.91 - CT_Popd
1.92 -
1.93 - CT_DoLog DEBUG " Saving CT_CC_CORE_SHARED_PREFIX_DIR='${CT_CC_CORE_SHARED_PREFIX_DIR}'"
1.94 - CT_Pushd "${CT_CC_CORE_SHARED_PREFIX_DIR}"
1.95 - CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/cc_core_shared_prefix_dir.tar${tar_ext}" .
1.96 - CT_Popd
1.97 -
1.98 - CT_DoLog DEBUG " Saving CT_PREFIX_DIR='${CT_PREFIX_DIR}'"
1.99 - CT_Pushd "${CT_PREFIX_DIR}"
1.100 - CT_DoExecLog DEBUG tar cv${tar_opt}f "${state_dir}/prefix_dir.tar${tar_ext}" --exclude '*.log' .
1.101 - CT_Popd
1.102 + CT_DoTarballIfExists "${CT_CONFIG_DIR}" "${state_dir}/config_dir"
1.103 + CT_DoTarballIfExists "${CT_CC_CORE_STATIC_PREFIX_DIR}" "${state_dir}/cc_core_static_prefix_dir"
1.104 + CT_DoTarballIfExists "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${state_dir}/cc_core_shared_prefix_dir"
1.105 + CT_DoTarballIfExists "${CT_PREFIX_DIR}" "${state_dir}/prefix_dir" --exclude '*.log'
1.106
1.107 if [ "${CT_LOG_TO_FILE}" = "y" ]; then
1.108 CT_DoLog DEBUG " Saving log file"
1.109 @@ -997,40 +1023,14 @@
1.110 # Log this to the log level required by the user
1.111 CT_DoLog ${CT_LOG_LEVEL_MAX} "Restoring state at step '${state_name}', as requested."
1.112
1.113 - case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
1.114 - y) tar_opt=z; tar_ext=.gz;;
1.115 - *) tar_opt=; tar_ext=;;
1.116 - esac
1.117 -
1.118 - CT_DoLog DEBUG " Removing previous build directories"
1.119 - CT_DoForceRmdir "${CT_PREFIX_DIR}" "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${CT_CC_CORE_STATIC_PREFIX_DIR}" "${CT_CONFIG_DIR}"
1.120 - CT_DoExecLog DEBUG mkdir -p "${CT_PREFIX_DIR}" "${CT_CC_CORE_SHARED_PREFIX_DIR}" "${CT_CC_CORE_STATIC_PREFIX_DIR}" "${CT_CONFIG_DIR}"
1.121 -
1.122 - CT_DoLog DEBUG " Restoring CT_PREFIX_DIR='${CT_PREFIX_DIR}'"
1.123 - CT_Pushd "${CT_PREFIX_DIR}"
1.124 - CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/prefix_dir.tar${tar_ext}"
1.125 - CT_Popd
1.126 -
1.127 - CT_DoLog DEBUG " Restoring CT_CC_CORE_SHARED_PREFIX_DIR='${CT_CC_CORE_SHARED_PREFIX_DIR}'"
1.128 - CT_Pushd "${CT_CC_CORE_SHARED_PREFIX_DIR}"
1.129 - CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/cc_core_shared_prefix_dir.tar${tar_ext}"
1.130 - CT_Popd
1.131 -
1.132 - CT_DoLog DEBUG " Restoring CT_CC_CORE_STATIC_PREFIX_DIR='${CT_CC_CORE_STATIC_PREFIX_DIR}'"
1.133 - CT_Pushd "${CT_CC_CORE_STATIC_PREFIX_DIR}"
1.134 - CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/cc_core_static_prefix_dir.tar${tar_ext}"
1.135 - CT_Popd
1.136 -
1.137 - CT_DoLog DEBUG " Restoring CT_CONFIG_DIR='${CT_CONFIG_DIR}'"
1.138 - CT_Pushd "${CT_CONFIG_DIR}"
1.139 - CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/config_dir.tar${tar_ext}"
1.140 - CT_Popd
1.141 -
1.142 + CT_DoExtractTarballIfExists "${state_dir}/prefix_dir" "${CT_PREFIX_DIR}"
1.143 + CT_DoExtractTarballIfExists "${state_dir}/cc_core_shared_prefix_dir" "${CT_CC_CORE_SHARED_PREFIX_DIR}"
1.144 + CT_DoExtractTarballIfExists "${state_dir}/cc_core_static_prefix_dir" "${CT_CC_CORE_STATIC_PREFIX_DIR}"
1.145 + CT_DoExtractTarballIfExists "${state_dir}/config_dir" "${CT_CONFIG_DIR}"
1.146 if [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
1.147 - CT_DoLog DEBUG " Restoring CT_COMPLIBS_DIR='${CT_COMPLIBS_DIR}'"
1.148 - CT_Pushd "${CT_COMPLIBS_DIR}"
1.149 - CT_DoExecLog DEBUG tar xv${tar_opt}f "${state_dir}/complibs_dir.tar${tar_ext}"
1.150 - CT_Popd
1.151 + # If complibs are not shared, then COMPLIBS_DIR == PREFIX_DIR,
1.152 + # so do not restore.
1.153 + CT_DoExtractTarballIfExists "${state_dir}/complibs_dir" "${CT_COMPLIBS_DIR}"
1.154 fi
1.155
1.156 # Restore the environment, discarding any error message