mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
run shellfmt on all of lib
This commit is contained in:
@@ -35,7 +35,7 @@ call_extension_method() {
|
||||
|
||||
# Then call the hooks, if they are defined.
|
||||
for hook_name in "$@"; do
|
||||
echo "-- Extension Method being called: ${hook_name}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "-- Extension Method being called: ${hook_name}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
# shellcheck disable=SC2086
|
||||
[[ $(type -t ${hook_name}) == function ]] && { ${hook_name}; }
|
||||
done
|
||||
@@ -66,13 +66,13 @@ initialize_extension_manager() {
|
||||
|
||||
# Log destination.
|
||||
export EXTENSION_MANAGER_LOG_FILE="${EXTENSION_MANAGER_TMP_DIR}/extensions.log"
|
||||
echo -n "" >"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt"
|
||||
echo -n "" > "${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt"
|
||||
|
||||
# globally initialize the extensions log.
|
||||
echo "-- lib/extensions.sh included. logs will be below, followed by the debug generated by the initialize_extension_manager() function." >"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "-- lib/extensions.sh included. logs will be below, followed by the debug generated by the initialize_extension_manager() function." > "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
|
||||
# log whats happening.
|
||||
echo "-- initialize_extension_manager() called." >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "-- initialize_extension_manager() called." >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
|
||||
# this is the all-important separator.
|
||||
local hook_extension_delimiter="__"
|
||||
@@ -87,13 +87,13 @@ initialize_extension_manager() {
|
||||
|
||||
# initialize the cleanups file.
|
||||
fragment_manager_cleanup_file="${SRC}"/.tmp/extension_function_cleanup.sh
|
||||
echo "# cleanups: " >"${fragment_manager_cleanup_file}"
|
||||
echo "# cleanups: " > "${fragment_manager_cleanup_file}"
|
||||
|
||||
local FUNCTION_SORT_OPTIONS="--general-numeric-sort --ignore-case" # --random-sort could be used to introduce chaos
|
||||
local hook_point=""
|
||||
# now loop over the hook_points.
|
||||
for hook_point in ${all_hook_points}; do
|
||||
echo "-- hook_point ${hook_point}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "-- hook_point ${hook_point}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
|
||||
# check if the hook point is already defined as a function.
|
||||
# that can happen for example with user_config(), that can be implemented itself directly by a userpatches config.
|
||||
@@ -102,7 +102,7 @@ initialize_extension_manager() {
|
||||
local existing_hook_point_function
|
||||
existing_hook_point_function="$(compgen -A function | grep "^${hook_point}\$")"
|
||||
if [[ "${existing_hook_point_function}" == "${hook_point}" ]]; then
|
||||
echo "--- hook_point_functions (final sorted realnames): ${hook_point_functions}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "--- hook_point_functions (final sorted realnames): ${hook_point_functions}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
display_alert "Extension conflict" "function ${hook_point} already defined! ignoring functions: $(compgen -A function | grep "^${hook_point}${hook_extension_delimiter}")" "wrn"
|
||||
continue
|
||||
fi
|
||||
@@ -125,7 +125,7 @@ initialize_extension_manager() {
|
||||
|
||||
# gather the real names of the functions (after the delimiter).
|
||||
hook_point_functions_pre_sort="$(compgen -A function | grep "^${hook_point}${hook_extension_delimiter}" | awk -F "${hook_extension_delimiter}" '{print $2}' | xargs echo -n)"
|
||||
echo "--- hook_point_functions_pre_sort: ${hook_point_functions_pre_sort}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "--- hook_point_functions_pre_sort: ${hook_point_functions_pre_sort}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
|
||||
# add "500_" to the names of function that do NOT start with a number.
|
||||
# keep a reference from the new names to the old names (we'll sort on the new, but invoke the old)
|
||||
@@ -141,7 +141,7 @@ initialize_extension_manager() {
|
||||
# actually sort the sort_id's...
|
||||
# shellcheck disable=SC2086
|
||||
hook_point_functions_sorted_by_sort_id="$(echo "${hook_point_functions_realname_to_sortname[*]}" | tr " " "\n" | LC_ALL=C sort ${FUNCTION_SORT_OPTIONS} | xargs echo -n)"
|
||||
echo "--- hook_point_functions_sorted_by_sort_id: ${hook_point_functions_sorted_by_sort_id}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "--- hook_point_functions_sorted_by_sort_id: ${hook_point_functions_sorted_by_sort_id}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
|
||||
# then map back to the real names, keeping the order..
|
||||
hook_point_functions=""
|
||||
@@ -150,7 +150,7 @@ initialize_extension_manager() {
|
||||
done
|
||||
# shellcheck disable=SC2086
|
||||
hook_point_functions="$(echo -n ${hook_point_functions})"
|
||||
echo "--- hook_point_functions (final sorted realnames): ${hook_point_functions}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "--- hook_point_functions (final sorted realnames): ${hook_point_functions}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
|
||||
hook_point_functions_counter=0
|
||||
hook_points_counter=$((hook_points_counter + 1))
|
||||
@@ -167,13 +167,13 @@ initialize_extension_manager() {
|
||||
done
|
||||
common_function_vars="${common_function_vars} HOOK_POINT_TOTAL_FUNCS=\"${hook_point_functions_counter}\""
|
||||
|
||||
echo "-- hook_point: ${hook_point} will run ${hook_point_functions_counter} functions: ${hook_point_functions}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
echo "-- hook_point: ${hook_point} will run ${hook_point_functions_counter} functions: ${hook_point_functions}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
local temp_source_file_for_hook_point="${EXTENSION_MANAGER_TMP_DIR}/extension_function_definition.sh"
|
||||
|
||||
hook_point_functions_loop_counter=0
|
||||
|
||||
# prepare the cleanup for the function, so we can remove our mess at the end of the build.
|
||||
cat <<-FUNCTION_CLEANUP_FOR_HOOK_POINT >>"${fragment_manager_cleanup_file}"
|
||||
cat <<- FUNCTION_CLEANUP_FOR_HOOK_POINT >> "${fragment_manager_cleanup_file}"
|
||||
unset ${hook_point}
|
||||
FUNCTION_CLEANUP_FOR_HOOK_POINT
|
||||
|
||||
@@ -181,7 +181,7 @@ initialize_extension_manager() {
|
||||
# theres a lot of opportunities here, but for now I keep it simple:
|
||||
# - execute functions in the order defined by ${hook_point_functions} above
|
||||
# - define call-specific environment variables, to help extension authors to write portable extensions (eg: EXTENSION_DIR)
|
||||
cat <<-FUNCTION_DEFINITION_HEADER >"${temp_source_file_for_hook_point}"
|
||||
cat <<- FUNCTION_DEFINITION_HEADER > "${temp_source_file_for_hook_point}"
|
||||
${hook_point}() {
|
||||
echo "*** Extension-managed hook starting '${hook_point}': will run ${hook_point_functions_counter} functions: '${hook_point_functions}'" >>"\${EXTENSION_MANAGER_LOG_FILE}"
|
||||
FUNCTION_DEFINITION_HEADER
|
||||
@@ -205,7 +205,7 @@ initialize_extension_manager() {
|
||||
# output the call, passing arguments, and also logging the output to the extensions log.
|
||||
# attention: don't pipe here (eg, capture output), otherwise hook function cant modify the environment (which is mostly the point)
|
||||
# @TODO: better error handling. we have a good opportunity to 'set -e' here, and 'set +e' after, so that extension authors are encouraged to write error-free handling code
|
||||
cat <<-FUNCTION_DEFINITION_CALLSITE >>"${temp_source_file_for_hook_point}"
|
||||
cat <<- FUNCTION_DEFINITION_CALLSITE >> "${temp_source_file_for_hook_point}"
|
||||
hook_point_function_trace_sources["${hook_point}${hook_extension_delimiter}${hook_point_function}"]="\${BASH_SOURCE[*]}"
|
||||
hook_point_function_trace_lines["${hook_point}${hook_extension_delimiter}${hook_point_function}"]="\${BASH_LINENO[*]}"
|
||||
[[ "\${DEBUG_EXTENSION_CALLS}" == "yes" ]] && display_alert "---> Extension Method ${hook_point}" "${hook_point_functions_loop_counter}/${hook_point_functions_counter} (ext:${EXTENSION:-built-in}) ${hook_point_function}" ""
|
||||
@@ -215,7 +215,7 @@ initialize_extension_manager() {
|
||||
FUNCTION_DEFINITION_CALLSITE
|
||||
|
||||
# output the cleanup for the implementation as well.
|
||||
cat <<-FUNCTION_CLEANUP_FOR_HOOK_POINT_IMPLEMENTATION >>"${fragment_manager_cleanup_file}"
|
||||
cat <<- FUNCTION_CLEANUP_FOR_HOOK_POINT_IMPLEMENTATION >> "${fragment_manager_cleanup_file}"
|
||||
unset ${hook_point}${hook_extension_delimiter}${hook_point_function}
|
||||
FUNCTION_CLEANUP_FOR_HOOK_POINT_IMPLEMENTATION
|
||||
|
||||
@@ -223,7 +223,7 @@ initialize_extension_manager() {
|
||||
unset EXTENSION EXTENSION_DIR EXTENSION_FILE EXTENSION_ADDED_BY
|
||||
done
|
||||
|
||||
cat <<-FUNCTION_DEFINITION_FOOTER >>"${temp_source_file_for_hook_point}"
|
||||
cat <<- FUNCTION_DEFINITION_FOOTER >> "${temp_source_file_for_hook_point}"
|
||||
echo "*** Extension-managed hook ending '${hook_point}': completed." >>"\${EXTENSION_MANAGER_LOG_FILE}"
|
||||
} # end ${hook_point}() function
|
||||
FUNCTION_DEFINITION_FOOTER
|
||||
@@ -232,8 +232,8 @@ initialize_extension_manager() {
|
||||
unset hook_point_functions hook_point_functions_sortname_to_realname hook_point_functions_realname_to_sortname
|
||||
|
||||
# log what was produced in our own debug logfile
|
||||
cat "${temp_source_file_for_hook_point}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
cat "${fragment_manager_cleanup_file}" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
cat "${temp_source_file_for_hook_point}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
cat "${fragment_manager_cleanup_file}" >> "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
|
||||
# source the generated function.
|
||||
# shellcheck disable=SC1090
|
||||
@@ -268,7 +268,7 @@ run_after_build__999_finish_extension_manager() {
|
||||
export defined_hook_point_functions hook_point_function_trace_sources
|
||||
|
||||
# eat our own dog food, pt2.
|
||||
call_extension_method "extension_metadata_ready" <<'EXTENSION_METADATA_READY'
|
||||
call_extension_method "extension_metadata_ready" << 'EXTENSION_METADATA_READY'
|
||||
*meta-Meta time!*
|
||||
Implement this hook to work with/on the meta-data made available by the extension manager.
|
||||
Interesting stuff to process:
|
||||
@@ -297,14 +297,14 @@ write_hook_point_metadata() {
|
||||
local main_hook_point_name="$1"
|
||||
|
||||
[[ ! -d "${EXTENSION_MANAGER_TMP_DIR}" ]] && mkdir -p "${EXTENSION_MANAGER_TMP_DIR}"
|
||||
cat - >"${EXTENSION_MANAGER_TMP_DIR}/${main_hook_point_name}.orig.md" # Write the hook point documentation received via stdin to a tmp file for later processing.
|
||||
cat - > "${EXTENSION_MANAGER_TMP_DIR}/${main_hook_point_name}.orig.md" # Write the hook point documentation received via stdin to a tmp file for later processing.
|
||||
shift
|
||||
echo -n "$@" >"${EXTENSION_MANAGER_TMP_DIR}/${main_hook_point_name}.compat" # log the 2nd+ arguments too (those are the alternative/compatibility names), separate file.
|
||||
compgen -A export >"${EXTENSION_MANAGER_TMP_DIR}/${main_hook_point_name}.exports" # capture the exported env vars.
|
||||
compgen -A variable >"${EXTENSION_MANAGER_TMP_DIR}/${main_hook_point_name}.vars" # capture all env vars.
|
||||
echo -n "$@" > "${EXTENSION_MANAGER_TMP_DIR}/${main_hook_point_name}.compat" # log the 2nd+ arguments too (those are the alternative/compatibility names), separate file.
|
||||
compgen -A export > "${EXTENSION_MANAGER_TMP_DIR}/${main_hook_point_name}.exports" # capture the exported env vars.
|
||||
compgen -A variable > "${EXTENSION_MANAGER_TMP_DIR}/${main_hook_point_name}.vars" # capture all env vars.
|
||||
|
||||
# add to the list of hook points called, in order.
|
||||
echo "${main_hook_point_name}" >>"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt"
|
||||
echo "${main_hook_point_name}" >> "${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt"
|
||||
}
|
||||
|
||||
# Helper function, to get clean "stack traces" that do not include the hook/extension infrastructure code.
|
||||
@@ -312,8 +312,8 @@ get_extension_hook_stracktrace() {
|
||||
local sources_str="$1" # Give this ${BASH_SOURCE[*]} - expanded
|
||||
local lines_str="$2" # And this # Give this ${BASH_LINENO[*]} - expanded
|
||||
local sources lines index final_stack=""
|
||||
IFS=' ' read -r -a sources <<<"${sources_str}"
|
||||
IFS=' ' read -r -a lines <<<"${lines_str}"
|
||||
IFS=' ' read -r -a sources <<< "${sources_str}"
|
||||
IFS=' ' read -r -a lines <<< "${lines_str}"
|
||||
for index in "${!sources[@]}"; do
|
||||
local source="${sources[index]}" line="${lines[((index - 1))]}"
|
||||
# skip extension infrastructure sources, these only pollute the trace and add no insight to users
|
||||
|
||||
Reference in New Issue
Block a user