Files
build/lib/functions/main/start-end.sh
Markus Hoffrogge d1252fc0ee interactive: better Repeat Build Options [by @mhoffrog, squashed, rebased]
Add interactive configurations to Repeat Build Options

Simplify function produce_repeat_args_array()

- make use of $ARMBIAN_NON_PARAM_ARGS and $ARMBIAN_PARSED_CMDLINE_PARAMS (associated array)
- quote parameter values to be on the safe side

Move "Repeat Build Options" logs to start-end.sh

- cli-build.sh, start-end.sh:
  - move function function produce_repeat_args_array() to start-end.sh
  - add $WHAT as first arg to produce_repeat_args_array() if
    $WHAT is not empty
  - move early display log of "Repeat Build Options" to
    function main_default_start_build()
  - move last log of "Repeat Build Options" to
    function main_default_end_build()
  - add last log of "Repeat Build Options" to
    LOG_SECTION="repeat_build_options"
2023-04-21 14:26:33 +02:00

127 lines
5.7 KiB
Bash

#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
# Common start/end build functions. Used by the default build and others
function main_default_start_build() {
# 1x: show interactively-selected as soon as possible, after config
produce_repeat_args_array
display_alert "Repeat Build Options (early)" "${repeat_args[*]}" "ext"
if [[ "${PRE_PREPARED_HOST:-"no"}" != "yes" ]]; then
prepare_host_init # this has its own logging sections, and is possibly interactive.
fi
# Prepare ccache, cthreads, etc for the build
LOG_SECTION="prepare_compilation_vars" do_with_logging prepare_compilation_vars
# from mark_aggregation_required_in_default_build_start() possibly marked during config
if [[ ${aggregation_required_in_default_build_start:-0} -gt 0 ]]; then
display_alert "Configuration requires aggregation" "running aggregation now" "debug"
aggregate_packages_in_logging_section
else
display_alert "Configuration does not require aggregation" "skipping aggregation" "debug"
fi
return 0
}
function prepare_host_init() {
wait_for_disk_sync "before starting build" # fsync, wait for disk to sync, and then continue. alert user if takes too long.
# Check that WORKDIR_BASE_TMP exists; if not, create it.
if [[ ! -d "${WORKDIR_BASE_TMP}" ]]; then
mkdir -p "${WORKDIR_BASE_TMP}"
fi
# Check the sanity of WORKDIR_BASE_TMP regarding mount options.
LOG_SECTION="check_dir_for_mount_options" do_with_logging check_dir_for_mount_options "${WORKDIR_BASE_TMP}" "main temporary dir"
# Starting work. Export TMPDIR, which will be picked up by all `mktemp` invocations hopefully.
# Runner functions in logging/runners.sh will explicitly unset TMPDIR before invoking chroot.
# Invoking chroot directly will fail in subtle ways, so, please use the runner.sh functions.
display_alert "Starting single build, exporting TMPDIR" "${WORKDIR}" "debug"
LOG_SECTION="prepare_tmpfs_workdir" do_with_logging prepare_tmpfs_for "WORKDIR" "${WORKDIR}" # this adds its own cleanup handler, which deletes it if it was created
add_cleanup_handler trap_handler_cleanup_workdir # this is for when it is NOT a tmpfs, for any reason; it does not delete the dir itself.
# 'declare -g -x': global, export
declare -g -x TMPDIR="${WORKDIR}" # TMPDIR is default for a lot of stuff, but...
declare -g -x CCACHE_TEMPDIR="${WORKDIR}/ccache_tmp" # Export CCACHE_TEMPDIR, under Workdir, which is hopefully under tmpfs. Thanks @the-Going for this.
declare -g -x XDG_RUNTIME_DIR="${WORKDIR}/xdg_tmp" # XDG_RUNTIME_DIR is used by the likes of systemd/freedesktop centric apps.
declare -g start_timestamp # global timestamp; read below by main_default_end_build()
start_timestamp=$(date +%s)
### Write config summary # @TODO: or not? this is a bit useless
LOG_SECTION="config_summary" do_with_logging write_config_summary_output_file
# Check and install dependencies, directory structure and settings
prepare_host # this has its own logging sections, and is possibly interactive.
# @TODO: what if there is no python2? bookworm/sid, currently. not long until more
# Create a directory inside WORKDIR with a "python" symlink to "/usr/bin/python2"; add it to PATH first.
BIN_WORK_DIR="${WORKDIR}/bin"
# No cleanup of this is necessary, since it's inside WORKDIR.
mkdir -p "${BIN_WORK_DIR}"
ln -s "/usr/bin/python2" "${BIN_WORK_DIR}/python"
declare -g PATH="${BIN_WORK_DIR}:${PATH}"
}
function main_default_end_build() {
call_extension_method "run_after_build" <<- 'RUN_AFTER_BUILD'
*hook for function to run after build, i.e. to change owner of `$SRC`*
Really one of the last hooks ever called. The build has ended. Congratulations.
- *NOTE:* this will run only if there were no errors during build process.
RUN_AFTER_BUILD
declare end_timestamp
end_timestamp=$(date +%s)
declare runtime_seconds=$((end_timestamp - start_timestamp))
# display_alert in its own logging section.
LOG_SECTION="runtime_total" do_with_logging display_alert "Runtime" "$(printf "%d:%02d min" $((runtime_seconds / 60)) $((runtime_seconds % 60)))" "info"
produce_repeat_args_array
LOG_SECTION="repeat_build_options" do_with_logging display_alert "Repeat Build Options" "${repeat_args[*]}" "ext" # * = expand array, space delimited, single-word.
return 0
}
function trap_handler_cleanup_workdir() {
display_alert "Cleanup WORKDIR: $WORKDIR" "trap_handler_cleanup_workdir" "cleanup"
unset TMPDIR
if [[ -d "${WORKDIR}" ]]; then
if [[ "${PRESERVE_WORKDIR}" != "yes" ]]; then
if [[ "${SHOW_DEBUG}" == "yes" ]]; then
display_alert "Cleaning up WORKDIR" "$(du -h -s "$WORKDIR")" "cleanup"
fi
# Remove all files and directories in WORKDIR, but not WORKDIR itself.
rm -rf "${WORKDIR:?}"/* # Note this is protected by :?
else
display_alert "Preserving WORKDIR due to PRESERVE_WORKDIR=yes" "$(du -h -s "$WORKDIR")" "warn"
# @TODO: tmpfs might just be unmounted, though.
fi
fi
}
function produce_repeat_args_array() {
# Make it easy to repeat build by displaying build options used. Prepare array.
declare -a -g repeat_args=("./compile.sh")
# @TODO: missing the config file name, if any.
repeat_args+=(${ARMBIAN_NON_PARAM_ARGS[*]})
for param_name in "${!ARMBIAN_PARSED_CMDLINE_PARAMS[@]}"; do
# Parameter values are quoted to be on the safe side.
repeat_args+=("${param_name}=${ARMBIAN_PARSED_CMDLINE_PARAMS[$param_name]@Q}")
done
for param_name in "${!ARMBIAN_INTERACTIVE_CONFIGS[@]}"; do
# Parameter values are quoted to be on the safe side.
repeat_args+=("${param_name}=${ARMBIAN_INTERACTIVE_CONFIGS[$param_name]@Q}")
done
}