lib: fix: replace undue export statements with declare -g

This commit is contained in:
Ricardo Pardini
2023-03-28 20:20:56 +02:00
committed by Igor Pečovnik
parent 77921725fb
commit ed0b406265
18 changed files with 35 additions and 35 deletions

View File

@@ -17,7 +17,7 @@ function cli_docker_pre_run() {
shell)
# inside-function-function: a dynamic hook, only triggered if this CLI runs.
function add_host_dependencies__ssh_client_for_docker_shell_over_ssh() {
export EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} openssh-client"
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} openssh-client"
}
declare -g DOCKER_PASS_SSH_AGENT="yes" # Pass SSH agent to docker
;;

View File

@@ -15,7 +15,7 @@ function cli_patch_kernel_pre_run() {
# inside-function-function: a dynamic hook, only triggered if this CLI runs.
# install openssh-client, we'll need it to push the patched tree.
function add_host_dependencies__ssh_client_for_patch_pushing_over_ssh() {
export EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} openssh-client"
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} openssh-client"
}
# "gimme root on a Linux machine"

View File

@@ -60,7 +60,7 @@ function compile_uboot_target() {
PRE_CONFIG_UBOOT_TARGET
display_alert "${uboot_prefix}Preparing u-boot config" "${version} ${target_make}" "info"
export if_error_detail_message="${uboot_prefix}Failed to configure u-boot ${version} $BOOTCONFIG ${target_make}"
declare -g if_error_detail_message="${uboot_prefix}Failed to configure u-boot ${version} $BOOTCONFIG ${target_make}"
run_host_command_logged CCACHE_BASEDIR="$(pwd)" PATH="${toolchain}:${toolchain2}:${PATH}" \
"KCFLAGS=-fdiagnostics-color=always" \
unbuffer make "$CTHREADS" "$BOOTCONFIG" "CROSS_COMPILE=\"$CCACHE $UBOOT_COMPILER\""
@@ -169,7 +169,7 @@ function compile_uboot_target() {
local uboot_cflags="${uboot_cflags_array[*]}"
display_alert "${uboot_prefix}Compiling u-boot" "${version} ${target_make} with gcc '${gcc_version_main}'" "info"
export if_error_detail_message="${uboot_prefix}Failed to build u-boot ${version} ${target_make}"
declare -g if_error_detail_message="${uboot_prefix}Failed to build u-boot ${version} ${target_make}"
do_with_ccache_statistics run_host_command_logged_long_running \
"CFLAGS='${uboot_cflags}'" "KCFLAGS='${uboot_cflags}'" \
CCACHE_BASEDIR="$(pwd)" PATH="${toolchain}:${toolchain2}:${PATH}" \

View File

@@ -11,10 +11,10 @@ function prepare_compilation_vars() {
# moved from config: rpardini: ccache belongs in compilation, not config. I think.
if [[ $USE_CCACHE != no ]]; then
CCACHE=ccache
export PATH="/usr/lib/ccache:$PATH"
export PATH="/usr/lib/ccache:$PATH" # this actually needs export'ing
# private ccache directory to avoid permission issues when using build script with "sudo"
# see https://ccache.samba.org/manual.html#_sharing_a_cache for alternative solution
[[ $PRIVATE_CCACHE == yes ]] && export CCACHE_DIR=$SRC/cache/ccache
[[ $PRIVATE_CCACHE == yes ]] && export CCACHE_DIR=$SRC/cache/ccache # actual export
else
CCACHE=""
fi

View File

@@ -22,7 +22,7 @@ function desktop_element_available_for_arch() {
function desktop_element_supported() {
local desktop_element_path="${1}"
local support_level_filepath="${desktop_element_path}/support"
export desktop_element_supported_result=0
declare -g desktop_element_supported_result=0
if [[ -f "${support_level_filepath}" ]]; then
local support_level
support_level="$(cat "${support_level_filepath}")"
@@ -130,8 +130,8 @@ function interactive_desktop_main_configuration() {
fi
display_alert "desktop-config" "DESKTOP_ENVIRONMENT_CONFIG_NAME exit: ${DESKTOP_ENVIRONMENT_CONFIG_NAME}" "debug"
export DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH="${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}"
export DESKTOP_ENVIRONMENT_PACKAGE_LIST_FILEPATH="${DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH}/packages"
declare -g DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH="${DESKTOP_ENVIRONMENT_DIRPATH}/${DESKTOP_ENVIRONMENT_CONFIG_NAME}"
declare -g DESKTOP_ENVIRONMENT_PACKAGE_LIST_FILEPATH="${DESKTOP_ENVIRONMENT_PACKAGE_LIST_DIRPATH}/packages"
display_alert "desktop-config" "DESKTOP_APPGROUPS_SELECTED+x entry: ${DESKTOP_APPGROUPS_SELECTED+x}" "debug"
# "-z ${VAR+x}" allows to check for unset variable

View File

@@ -15,8 +15,8 @@ function interactive_config_prepare_terminal() {
# override stty size, if stdin is a terminal.
[[ -n $COLUMNS ]] && stty cols $COLUMNS
[[ -n $LINES ]] && stty rows $LINES
export TTY_X=$(($(stty size | awk '{print $2}') - 6)) # determine terminal width
export TTY_Y=$(($(stty size | awk '{print $1}') - 6)) # determine terminal height
declare -g TTY_X=$(($(stty size | awk '{print $2}') - 6)) # determine terminal width
declare -g TTY_Y=$(($(stty size | awk '{print $1}') - 6)) # determine terminal height
fi
fi
# We'll use this title on all menus

View File

@@ -45,7 +45,7 @@ function do_main_configuration() {
DEST_LANG="${DEST_LANG:-"en_US.UTF-8"}" # en_US.UTF-8 is default locale for target
display_alert "DEST_LANG..." "DEST_LANG: ${DEST_LANG}" "debug"
export SKIP_EXTERNAL_TOOLCHAINS="${SKIP_EXTERNAL_TOOLCHAINS:-yes}" # don't use any external toolchains, by default.
declare -g SKIP_EXTERNAL_TOOLCHAINS="${SKIP_EXTERNAL_TOOLCHAINS:-yes}" # don't use any external toolchains, by default.
# Timezone
if [[ -f /etc/timezone ]]; then # Timezone for target is taken from host, if it exists.
@@ -153,9 +153,9 @@ function do_main_configuration() {
[[ $USE_MAINLINE_GOOGLE_MIRROR == yes ]] && MAINLINE_MIRROR=google
# URL for the git bundle used to "bootstrap" local git copies without too much server load. This applies independently of git mirror below.
export MAINLINE_KERNEL_TORVALDS_BUNDLE_URL="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/clone.bundle" # this is plain torvalds, single branch
export MAINLINE_KERNEL_STABLE_BUNDLE_URL="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/clone.bundle" # this is all stable branches. with tags!
export MAINLINE_KERNEL_COLD_BUNDLE_URL="${MAINLINE_KERNEL_COLD_BUNDLE_URL:-${MAINLINE_KERNEL_TORVALDS_BUNDLE_URL}}" # default to Torvalds; everything else is small enough with this
declare -g MAINLINE_KERNEL_TORVALDS_BUNDLE_URL="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/clone.bundle" # this is plain torvalds, single branch
declare -g MAINLINE_KERNEL_STABLE_BUNDLE_URL="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/clone.bundle" # this is all stable branches. with tags!
declare -g MAINLINE_KERNEL_COLD_BUNDLE_URL="${MAINLINE_KERNEL_COLD_BUNDLE_URL:-${MAINLINE_KERNEL_TORVALDS_BUNDLE_URL}}" # default to Torvalds; everything else is small enough with this
case $MAINLINE_MIRROR in
google)

View File

@@ -19,8 +19,8 @@
# otherwise it will NOT exit with error, even if user cancelled.
# This is a boring topic, see https://askubuntu.com/questions/491509/how-to-get-dialog-box-input-directed-to-a-variable
function dialog_if_terminal_set_vars() {
export DIALOG_RESULT=""
export DIALOG_EXIT_CODE=0
declare -g DIALOG_RESULT=""
declare -g DIALOG_EXIT_CODE=0
[[ ! -t 0 ]] && exit_with_error "stdin is not a terminal. can't use dialog." "dialog_if_terminal_set_vars ${*}" "err"
[[ ! -t 1 ]] && exit_with_error "stdout is not a terminal. can't use dialog." "dialog_if_terminal_set_vars ${*}" "err"
@@ -51,7 +51,7 @@ function dialog_if_terminal_set_vars() {
# Myy : Menu configuration for choosing desktop configurations
dialog_menu() {
export DIALOG_MENU_RESULT=""
declare -g DIALOG_MENU_RESULT=""
provided_title=$1
provided_backtitle=$2
provided_menuname=$3
@@ -62,7 +62,7 @@ dialog_menu() {
# Almost identical, but is a checklist instead of menu
dialog_checklist() {
export DIALOG_CHECKLIST_RESULT=""
declare -g DIALOG_CHECKLIST_RESULT=""
provided_title=$1
provided_backtitle=$2
provided_menuname=$3

View File

@@ -76,7 +76,7 @@ function initialize_extension_manager() {
}
# This marks the manager as initialized, no more extensions are allowed to load after this.
export initialize_extension_manager_counter=$((initialize_extension_manager_counter + 1))
declare -g initialize_extension_manager_counter=$((initialize_extension_manager_counter + 1))
# Extensions has its own work/tmp directory, defined by do_main_configuration, with build UUID. We just create it here, unless told not to.
display_alert "Initializing EXTENSION_MANAGER_TMP_DIR" "${EXTENSION_MANAGER_TMP_DIR}" "debug"
@@ -295,7 +295,7 @@ function cleanup_handler_extensions() {
# final location. this will make run_after_build() "hot" (eg, emit warnings)
function run_after_build__999_finish_extension_manager() {
# export these maps, so the hook can access them and produce useful stuff.
export defined_hook_point_functions hook_point_function_trace_sources
declare -g defined_hook_point_functions hook_point_function_trace_sources
# eat our own dog food, pt2.
call_extension_method "extension_metadata_ready" <<- 'EXTENSION_METADATA_READY'

View File

@@ -350,8 +350,8 @@ function docker_cli_build_dockerfile() {
# If we get here without a local_image_sha, we need to build from scratch, so we need to re-create the Dockerfile.
if [[ -z "${local_image_sha}" ]]; then
display_alert "Base image not in local cache, building from scratch" "${DOCKER_ARMBIAN_BASE_IMAGE}" "info"
export DOCKERFILE_USE_ARMBIAN_IMAGE_AS_BASE=no
export DOCKER_ARMBIAN_BASE_IMAGE="${DOCKER_ARMBIAN_BASE_IMAGE_SCRATCH}"
declare -g DOCKERFILE_USE_ARMBIAN_IMAGE_AS_BASE=no
declare -g DOCKER_ARMBIAN_BASE_IMAGE="${DOCKER_ARMBIAN_BASE_IMAGE_SCRATCH}"
docker_prepare_cli_skip_exts="yes" docker_cli_prepare
display_alert "Re-created" "Dockerfile, proceeding, build from scratch" "debug"
fi

View File

@@ -326,7 +326,7 @@ function adaptative_prepare_host_dependencies() {
host_dependencies+=(libc6-amd64-cross) # Support for running x86 binaries (under qemu on other arches)
fi
export EXTRA_BUILD_DEPS=""
declare -g EXTRA_BUILD_DEPS=""
call_extension_method "add_host_dependencies" <<- 'ADD_HOST_DEPENDENCIES'
*run before installing host dependencies*
you can add packages to install, space separated, to ${EXTRA_BUILD_DEPS} here.
@@ -337,7 +337,7 @@ function adaptative_prepare_host_dependencies() {
host_dependencies+=(${EXTRA_BUILD_DEPS})
fi
export FINAL_HOST_DEPS="${host_dependencies[*]}"
declare -g FINAL_HOST_DEPS="${host_dependencies[*]}"
call_extension_method "host_dependencies_known" <<- 'HOST_DEPENDENCIES_KNOWN'
*run after all host dependencies are known (but not installed)*
At this point we can read `${FINAL_HOST_DEPS}`, but changing won't have any effect.

View File

@@ -88,7 +88,7 @@ function write_uboot_to_loop_image() {
display_alert "Writing u-boot bootloader" "$loop" "info"
write_uboot_platform "${TEMP_DIR}${DIR}" "$loop" # important: DIR is set in platform_install.sh sourced above.
export UBOOT_CHROOT_DIR="${TEMP_DIR}${DIR}"
declare -g UBOOT_CHROOT_DIR="${TEMP_DIR}${DIR}"
call_extension_method "post_write_uboot_platform" <<- 'POST_WRITE_UBOOT_PLATFORM'
*allow custom writing of uboot -- only during image build*

View File

@@ -212,7 +212,7 @@ function prepare_partitions() {
exec {FD}> /var/lock/armbian-debootstrap-losetup
flock -x $FD
export LOOP
declare -g LOOP
LOOP=$(losetup -f) || exit_with_error "Unable to find free loop device"
display_alert "Allocated loop device" "LOOP=${LOOP}"

View File

@@ -115,7 +115,7 @@ function create_image_from_sdcard_rootfs() {
[[ $(type -t post_build_image_modify) == function ]] && display_alert "Custom Hook Detected" "post_build_image_modify" "info" && post_build_image_modify "${DESTIMG}/${version}.img"
# Previously, post_build_image passed the .img path as an argument to the hook. Now its an ENV var.
export FINAL_IMAGE_FILE="${DESTIMG}/${version}.img"
declare -g FINAL_IMAGE_FILE="${DESTIMG}/${version}.img"
call_extension_method "post_build_image" <<- 'POST_BUILD_IMAGE'
*custom post build hook*
Called after the final .img file is built, before it is (possibly) written to an SD writer.

View File

@@ -77,7 +77,7 @@ function main_trap_handler() {
fi
if [[ ${trap_exit_code} -gt 0 ]] && [[ "${ERROR_DEBUG_SHELL}" == "yes" ]]; then
export ERROR_DEBUG_SHELL=no # dont do it twice
declare -g ERROR_DEBUG_SHELL=no # dont do it twice
display_alert "MOUNT" "${MOUNT}" "debug"
display_alert "SDCARD" "${SDCARD}" "debug"
display_alert "ERROR_DEBUG_SHELL=yes, starting a shell." "ERROR_DEBUG_SHELL; exit to cleanup." "debug"

View File

@@ -47,7 +47,7 @@ function main_default_start_build() {
# 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"
export PATH="${BIN_WORK_DIR}:${PATH}"
declare -g PATH="${BIN_WORK_DIR}:${PATH}"
# Prepare ccache, cthreads, etc for the build
LOG_SECTION="prepare_compilation_vars" do_with_logging prepare_compilation_vars

View File

@@ -42,7 +42,7 @@ function install_deb_chroot() {
fi
# install in chroot via apt-get, not dpkg, so dependencies are also installed from repo if needed.
export if_error_detail_message="Installation of $install_target failed ${BOARD} ${RELEASE} ${BUILD_DESKTOP} ${LINUXFAMILY}"
declare -g if_error_detail_message="Installation of $install_target failed ${BOARD} ${RELEASE} ${BUILD_DESKTOP} ${LINUXFAMILY}"
DONT_MAINTAIN_APT_CACHE="yes" chroot_sdcard_apt_get --no-install-recommends install "${install_target}" # don't auto-maintain apt cache when installing from packages.
# @TODO: mysterious. store installed/downloaded packages in deb storage. only used for u-boot deb. why?

View File

@@ -101,7 +101,7 @@ function create_new_rootfs_cache_via_debootstrap() {
deploy_qemu_binary_to_chroot "${SDCARD}" # this is cleaned-up later by post_debootstrap_tweaks() @TODO: which is too late for a cache
display_alert "Installing base system" "Stage 2/2" "info"
export if_error_detail_message="Debootstrap second stage failed ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL}"
declare -g if_error_detail_message="Debootstrap second stage failed ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL}"
chroot_sdcard LC_ALL=C LANG=C /debootstrap/debootstrap --second-stage
[[ ! -f "${SDCARD}/bin/bash" ]] && exit_with_error "Debootstrap first stage did not produce /bin/bash"
@@ -163,7 +163,7 @@ function create_new_rootfs_cache_via_debootstrap() {
# stage: install additional packages
display_alert "Installing the main packages for" "Armbian" "info"
export if_error_detail_message="Installation of Armbian main packages for ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL} failed"
declare -g if_error_detail_message="Installation of Armbian main packages for ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL} failed"
# First, try to download-only up to 3 times, to work around network/proxy problems.
# AGGREGATED_PACKAGES_ROOTFS is generated by aggregation.py
chroot_sdcard_apt_get_install_dry_run "${AGGREGATED_PACKAGES_ROOTFS[@]}"
@@ -183,13 +183,13 @@ function create_new_rootfs_cache_via_debootstrap() {
do_with_retries 3 chroot_sdcard_apt_get_install_download_only "${AGGREGATED_PACKAGES_DESKTOP[@]}"
# Then do the actual install.
export if_error_detail_message="Installation of Armbian desktop packages for ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL} failed"
declare -g if_error_detail_message="Installation of Armbian desktop packages for ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL} failed"
chroot_sdcard_apt_get_install "${AGGREGATED_PACKAGES_DESKTOP[@]}"
fi
# stage: check md5 sum of installed packages. Just in case. @TODO: rpardini: this should also be done when a cache is used, not only when it is created
display_alert "Checking MD5 sum of installed packages" "debsums" "info"
export if_error_detail_message="Check MD5 sum of installed packages failed"
declare -g if_error_detail_message="Check MD5 sum of installed packages failed"
chroot_sdcard debsums --silent
# # Remove packages from packages.uninstall