lib: implement and sprinkle some very basic config var change-tracking across board/family sourcing and several hook calls

This commit is contained in:
Ricardo Pardini
2023-12-28 00:12:50 +01:00
committed by Igor
parent ea8953422a
commit bebf4c7ae0
5 changed files with 77 additions and 1 deletions

View File

@@ -0,0 +1,47 @@
# Hint for GitHub Copilot: # Think carefully. Work step by step. # Use modern bash (v5+) features to make it easier to read and maintain.
#
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2023 Ricardo Pardini <ricardo@pardini.net>
# This file is a part of the Armbian Build Framework https://github.com/armbian/build/
#
declare -g -A STORED_CONFIG_VARS=()
function track_config_variables() {
declare when="${1}"
shift
declare -a vars=("${@}")
declare var_name
for var_name in "${vars[@]}"; do
declare var_value var_previous_value was_text value_text
# if the var is an array...
if [[ "${array_values:-"no"}" == "yes" ]]; then
eval "var_value=\"\${${var_name}[@]}\"" # sorry
value_text="${blue_color:-}(${bright_blue_color:-}${var_value}${blue_color:-})"
else
var_value="${!var_name}"
value_text="${blue_color:-}'${bright_blue_color:-}${var_value}${blue_color:-}'"
fi
var_previous_value="${STORED_CONFIG_VARS["${var_name}"]}"
if [[ "${var_value}" == "${var_previous_value}" ]]; then
continue
fi
was_text=""
if [[ -n "${var_previous_value}" ]]; then
was_text=" ${tool_color:-}# (was: '${var_previous_value}')"
fi
if [[ "${silent:-"no"}" != "yes" ]]; then
display_alert "change-tracking: ${when}" "${bright_blue_color:-}${var_name}${normal_color:-}=${value_text}${was_text}" "change-tracking"
fi
STORED_CONFIG_VARS["${var_name}"]="${var_value}"
done
}
function track_general_config_variables() {
track_config_variables "${1}" BOARDFAMILY KERNELSOURCE KERNEL_MAJOR_MINOR KERNELBRANCH LINUXFAMILY LINUXCONFIG KERNELPATCHDIR KERNEL_PATCH_ARCHIVE_BASE
array_values="yes" track_config_variables "${1}" KERNEL_DRIVERS_SKIP
track_config_variables "${1}" BOOTSOURCE BOOTBRANCH BOOTPATCHDIR BOOTDIR BOOTCONFIG BOOTBRANCH_BOARD BOOTPATCHDIR_BOARD
}

View File

@@ -271,6 +271,7 @@ function do_main_configuration() {
Since the family can override values from the user configuration and the board configuration,
it is often used to in turn override those.
POST_FAMILY_CONFIG
track_general_config_variables "after post_family_config hooks"
# A secondary post_family_config hook, this time with the BRANCH in the name, lowercase.
call_extension_method "post_family_config_branch_${BRANCH,,}" <<- 'POST_FAMILY_CONFIG_PER_BRANCH'
@@ -280,6 +281,7 @@ function do_main_configuration() {
The sole purpose of this is to avoid "case ... esac for $BRANCH" in the board configuration,
allowing separate functions for different branches. You're welcome.
POST_FAMILY_CONFIG_PER_BRANCH
track_general_config_variables "after post_family_config_branch hooks"
# Lets make some variables readonly.
# We don't want anything changing them, it's exclusively for family config.
@@ -355,6 +357,7 @@ function do_extra_configuration() {
if [[ -f $USERPATCHES_PATH/lib.config ]]; then
display_alert "Using user configuration override" "$USERPATCHES_PATH/lib.config" "info"
source "$USERPATCHES_PATH"/lib.config
track_general_config_variables "after sourcing lib.config"
fi
# Prepare array for extensions to fill in.
@@ -367,6 +370,7 @@ function do_extra_configuration() {
It is called after sourcing the `lib.config` file if it exists,
but before assembling any package lists.
USER_CONFIG
track_general_config_variables "after user_config hooks"
display_alert "Extensions: prepare configuration" "extension_prepare_config" "debug"
call_extension_method "extension_prepare_config" <<- 'EXTENSION_PREPARE_CONFIG'
@@ -374,6 +378,7 @@ function do_extra_configuration() {
Implementors should preserve variable values pre-set, but can default values an/or validate them.
This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user.
EXTENSION_PREPARE_CONFIG
track_general_config_variables "after extension_prepare_config hooks"
error_if_lib_tag_set # make sure users are not thrown off by using old parameter which does nothing anymore
@@ -492,15 +497,19 @@ function source_family_config_and_arch() {
fi
fi
track_general_config_variables "after sourcing family config"
# load "all-around common arch defaults" common.conf
display_alert "Sourcing common arch configuration" "common.conf" "debug"
# shellcheck source=config/sources/common.conf
source "${SRC}/config/sources/common.conf"
track_general_config_variables "after sourcing common arch"
# load architecture defaults
display_alert "Sourcing arch configuration" "${ARCH}.conf" "info"
# shellcheck source=/dev/null
source "${SRC}/config/sources/${ARCH}.conf"
track_general_config_variables "after sourcing ${ARCH} arch"
return 0
}

View File

@@ -140,10 +140,15 @@ function display_alert() {
;;
ext)
level_indicator="✨" # or ✅ ?
level_indicator="✨"
inline_logs_color="\e[1;32m"
;;
change-tracking)
level_indicator="✅"
inline_logs_color="\e[1;36m" # cyan
;;
*)
level="${level:-info}" # for file logging.
level_indicator="🌿"

View File

@@ -129,11 +129,14 @@ function config_source_board_file() {
# Otherwise publish it as readonly global
declare -g -r SOURCED_BOARD_CONFIGS_FILENAME_LIST="${sourced_board_configs[*]}"
track_general_config_variables "after sourcing board"
# this is (100%?) rewritten by family config!
# answer: this defaults LINUXFAMILY to BOARDFAMILY. that... shouldn't happen, extensions might change it too.
# @TODO: better to check for empty after sourcing family config and running extensions, *warning about it*, and only then default to BOARDFAMILY.
# this sourced the board config. do_main_configuration will source the (BOARDFAMILY) family file.
LINUXFAMILY="${BOARDFAMILY}"
track_general_config_variables "after defaulting LINUXFAMILY to BOARDFAMILY"
# Lets make some variables readonly after sourcing the board file.
# We don't want anything changing them, it's exclusively for board config.
@@ -162,6 +165,8 @@ function config_early_init() {
declare -g -a KERNEL_DRIVERS_SKIP=() # Prepare array to be filled in by board/family/extensions
silent="yes" track_general_config_variables "after config_early_init" # don't log anything, just init the change tracking
return 0 # protect against eventual shortcircuit above
}
@@ -225,6 +230,7 @@ function config_post_main() {
call_extension_method "late_family_config" <<- 'LATE_FAMILY_CONFIG'
*late defaults/overrides, main hook point for KERNELSOURCE/BRANCH and BOOTSOURCE/BRANCH etc*
LATE_FAMILY_CONFIG
track_general_config_variables "after late_family_config hooks"
if [[ "${KERNELSOURCE}" != 'none' ]]; then
if [[ "x${KERNEL_MAJOR_MINOR}x" == "xx" ]]; then

View File

@@ -550,6 +550,15 @@ set -o errexit ## set -e : exit the script if any statement returns a non-true
# shellcheck source=lib/functions/configuration/aggregation.sh
source "${SRC}"/lib/functions/configuration/aggregation.sh
# no errors tolerated. invoked before each sourced file to make sure.
#set -o pipefail # trace ERR through pipes - will be enabled "soon"
#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled
set -o errtrace # trace ERR through - enabled
set -o errexit ## set -e : exit the script if any statement returns a non-true return value - enabled
### lib/functions/configuration/change-tracking.sh
# shellcheck source=lib/functions/configuration/change-tracking.sh
source "${SRC}"/lib/functions/configuration/change-tracking.sh
# no errors tolerated. invoked before each sourced file to make sure.
#set -o pipefail # trace ERR through pipes - will be enabled "soon"
#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled