scripts/functions
changeset 121 82e69d88119b
parent 112 ea15433daba0
child 127 2ba6a8d5d4be
     1.1 --- a/scripts/functions	Sun May 20 13:48:26 2007 +0000
     1.2 +++ b/scripts/functions	Tue May 22 20:46:07 2007 +0000
     1.3 @@ -304,7 +304,7 @@
     1.4          if [ -r "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" -a \
     1.5               "${CT_FORCE_DOWNLOAD}" != "y" ]; then
     1.6              CT_DoLog EXTRA "Copying \"${file}\" from local copy"
     1.7 -            cp -v "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog DEBUG
     1.8 +            cp -v "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog ALL
     1.9              return 0
    1.10          fi
    1.11      done
    1.12 @@ -460,3 +460,112 @@
    1.13      esac
    1.14      CT_TARGET="`${CT_TOP_DIR}/tools/config.sub ${CT_TARGET}`"
    1.15  }
    1.16 +
    1.17 +# This function does pause the build until the user strikes "Return"
    1.18 +# Usage: CT_DoPause [optional_message]
    1.19 +CT_DoPause() {
    1.20 +    local foo
    1.21 +    local message="${1:-Pausing for your pleasure}"
    1.22 +    CT_DoLog INFO "${message}"
    1.23 +    read -p "Press \"Enter\" to continue, or Ctrl-C to stop..." foo >&6
    1.24 +    return 0
    1.25 +}
    1.26 +
    1.27 +# This function saves the state of the toolchain to be able to restart
    1.28 +# at any one point
    1.29 +# Usage: CT_DoSaveState <next_step_name>
    1.30 +CT_DoSaveState() {
    1.31 +	[ "${CT_DEBUG_CT_SAVE_STEPS}" = "y" ] || return 0
    1.32 +    local state_name="$1"
    1.33 +    local state_dir="${CT_STATE_DIR}/${state_name}"
    1.34 +
    1.35 +    CT_DoLog DEBUG "Saving state to restart at step \"${state_name}\"..."
    1.36 +    rm -rf "${state_dir}"
    1.37 +    mkdir -p "${state_dir}"
    1.38 +
    1.39 +    case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
    1.40 +        y)  tar_opt=czf; tar_ext=".tar.gz";;
    1.41 +        *)  tar_opt=cf;  tar_ext=".tar";;
    1.42 +    esac
    1.43 +
    1.44 +    CT_DoLog DEBUG "  Saving environment and aliases"
    1.45 +    # We must omit shell functions
    1.46 +    # 'isgrep' is here because I don't seem to
    1.47 +    # be able to remove the functions names.
    1.48 +    set |awk '
    1.49 +         BEGIN { _p = 1; }
    1.50 +         $0~/^[^ ] ()/ { _p = 0; }
    1.51 +         _p == 1
    1.52 +         $0 == "}" { _p = 1; }
    1.53 +         ' |egrep -v '^[^ ]+ \(\)' >"${state_dir}/env.sh"
    1.54 +
    1.55 +    CT_DoLog DEBUG "  Saving CT_CC_CORE_PREFIX_DIR=\"${CT_CC_CORE_PREFIX_DIR}\""
    1.56 +    CT_Pushd "${CT_CC_CORE_PREFIX_DIR}"
    1.57 +    tar ${tar_opt} "${state_dir}/cc_core_prefix_dir${tar_ext}" .
    1.58 +    CT_Popd
    1.59 +
    1.60 +    CT_DoLog DEBUG "  Saving CT_PREFIX_DIR=\"${CT_PREFIX_DIR}\""
    1.61 +    CT_Pushd "${CT_PREFIX_DIR}"
    1.62 +    tar ${tar_opt} "${state_dir}/prefix_dir${tar_ext}" .
    1.63 +    CT_Popd
    1.64 +
    1.65 +    if [ "${CT_LOG_TO_FILE}" = "y" ]; then
    1.66 +        CT_DoLog DEBUG "  Saving log file"
    1.67 +        exec >/dev/null
    1.68 +        case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
    1.69 +            y)  gzip -3 -c "${CT_LOG_FILE}"  >"${state_dir}/log.gz";;
    1.70 +            *)  cat "${CT_LOG_FILE}" >"${state_dir}/log";;
    1.71 +        esac
    1.72 +        exec >>"${CT_LOG_FILE}"
    1.73 +    fi
    1.74 +}
    1.75 +
    1.76 +# This functions restores a previously saved state
    1.77 +# Usage: CT_DoLoadState <state_name>
    1.78 +CT_DoLoadState(){
    1.79 +    local state_name="$1"
    1.80 +    local state_dir="${CT_STATE_DIR}/${state_name}"
    1.81 +
    1.82 +    # We need to do something special with the log file!
    1.83 +    if [ "${CT_LOG_TO_FILE}" = "y" ]; then
    1.84 +        exec >"${state_dir}/tail.log"
    1.85 +    fi
    1.86 +    CT_DoLog DEBUG "Restoring state at step \"${state_name}\"..."
    1.87 +
    1.88 +    case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
    1.89 +        y)  tar_opt=xzf; tar_ext=".tar.gz";;
    1.90 +        *)  tar_opt=cf;  tar_ext=".tar";;
    1.91 +    esac
    1.92 +
    1.93 +    CT_DoLog DEBUG "  Removing previous build directories"
    1.94 +    chmod -R u+rwX "${CT_PREFIX_DIR}" "${CT_CC_CORE_PREFIX_DIR}"
    1.95 +    rm -rf         "${CT_PREFIX_DIR}" "${CT_CC_CORE_PREFIX_DIR}"
    1.96 +    mkdir -p       "${CT_PREFIX_DIR}" "${CT_CC_CORE_PREFIX_DIR}"
    1.97 +
    1.98 +    CT_DoLog DEBUG "  Restoring CT_PREFIX_DIR=\"${CT_PREFIX_DIR}\""
    1.99 +    CT_Pushd "${CT_PREFIX_DIR}"
   1.100 +    tar ${tar_opt} "${state_dir}/prefix_dir${tar_ext}"
   1.101 +    CT_Popd
   1.102 +
   1.103 +    CT_DoLog DEBUG "  Restoring CT_CC_CORE_PREFIX_DIR=\"${CT_CC_CORE_PREFIX_DIR}\""
   1.104 +    CT_Pushd "${CT_CC_CORE_PREFIX_DIR}"
   1.105 +    tar ${tar_opt} "${state_dir}/cc_core_prefix_dir${tar_ext}"
   1.106 +    CT_Popd
   1.107 +
   1.108 +    # Restore the environment, discarding any error message
   1.109 +    # (for example, read-only bash internals)
   1.110 +    CT_DoLog DEBUG "  Restoring environment"
   1.111 +    . "${state_dir}/env.sh" >/dev/null 2>&1 || true
   1.112 +
   1.113 +    if [ "${CT_LOG_TO_FILE}" = "y" ]; then
   1.114 +        CT_DoLog DEBUG "  Restoring log file"
   1.115 +        exec >/dev/null
   1.116 +        case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
   1.117 +            y)  zcat "${state_dir}/log.gz" >"${CT_LOG_FILE}";;
   1.118 +            *)  cat "${state_dir}/log" >"${CT_LOG_FILE}";;
   1.119 +        esac
   1.120 +        cat "${state_dir}/tail.log" >>"${CT_LOG_FILE}"
   1.121 +        exec >>"${CT_LOG_FILE}"
   1.122 +        rm -f "${state_dir}/tail.log"
   1.123 +    fi
   1.124 +}