From eb1fe6d7bac7040fe197732a51017ef0b44086ba Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Sun, 9 Apr 2023 15:40:29 +0200 Subject: [PATCH] artifacts: introduce `PRE_PREPARED_HOST=yes`: allow running pre-prepared host CLI's for artifacts that require aggregation --- .../artifacts/artifact-armbian-bsp-desktop.sh | 1 + .../artifacts/artifact-armbian-desktop.sh | 1 + lib/functions/artifacts/artifact-rootfs.sh | 1 + lib/functions/cli/cli-artifact.sh | 14 ++++---- lib/functions/host/host-release.sh | 15 ++++++--- lib/functions/host/prepare-host.sh | 4 +++ lib/functions/main/build-packages.sh | 7 ++++ lib/functions/main/start-end.sh | 32 +++++++++++-------- 8 files changed, 51 insertions(+), 24 deletions(-) diff --git a/lib/functions/artifacts/artifact-armbian-bsp-desktop.sh b/lib/functions/artifacts/artifact-armbian-bsp-desktop.sh index 43005a10ab..beb15c3f93 100644 --- a/lib/functions/artifacts/artifact-armbian-bsp-desktop.sh +++ b/lib/functions/artifacts/artifact-armbian-bsp-desktop.sh @@ -88,6 +88,7 @@ function artifact_armbian-bsp-desktop_cli_adapter_config_prep() { : "${DESKTOP_ENVIRONMENT_CONFIG_NAME:?DESKTOP_ENVIRONMENT_CONFIG_NAME is not set}" # this requires aggregation, and thus RELEASE, but also everything else. + declare -g artifact_version_requires_aggregation="yes" use_board="yes" allow_no_family="no" skip_kernel="no" prep_conf_main_only_rootfs_ni < /dev/null # no stdin for this, so it bombs if tries to be interactive. } diff --git a/lib/functions/artifacts/artifact-armbian-desktop.sh b/lib/functions/artifacts/artifact-armbian-desktop.sh index 11f0734fb7..33f94c2553 100644 --- a/lib/functions/artifacts/artifact-armbian-desktop.sh +++ b/lib/functions/artifacts/artifact-armbian-desktop.sh @@ -87,6 +87,7 @@ function artifact_armbian-desktop_cli_adapter_config_prep() { : "${DESKTOP_ENVIRONMENT_CONFIG_NAME:?DESKTOP_ENVIRONMENT_CONFIG_NAME is not set}" # this requires aggregation, and thus RELEASE, but also everything else. + declare -g artifact_version_requires_aggregation="yes" use_board="yes" allow_no_family="no" skip_kernel="no" prep_conf_main_only_rootfs_ni < /dev/null # no stdin for this, so it bombs if tries to be interactive. } diff --git a/lib/functions/artifacts/artifact-rootfs.sh b/lib/functions/artifacts/artifact-rootfs.sh index a1f5a4278a..46b23eed6a 100644 --- a/lib/functions/artifacts/artifact-rootfs.sh +++ b/lib/functions/artifacts/artifact-rootfs.sh @@ -99,6 +99,7 @@ function artifact_rootfs_cli_adapter_pre_run() { } function artifact_rootfs_cli_adapter_config_prep() { + declare -g artifact_version_requires_aggregation="yes" declare -g ROOTFS_COMPRESSION_RATIO="${ROOTFS_COMPRESSION_RATIO:-"15"}" # default to Compress stronger when we make rootfs cache # If BOARD is set, use it to convert to an ARCH. diff --git a/lib/functions/cli/cli-artifact.sh b/lib/functions/cli/cli-artifact.sh index b4210f0af3..05a4257095 100644 --- a/lib/functions/cli/cli-artifact.sh +++ b/lib/functions/cli/cli-artifact.sh @@ -24,7 +24,13 @@ function cli_artifact_run() { display_alert "artifact" "${chosen_artifact}" "debug" display_alert "artifact" "${chosen_artifact} :: ${chosen_artifact_impl}()" "debug" - artifact_cli_adapter_config_prep # only if in cli. + declare -g artifact_version_requires_aggregation="no" # marker + artifact_cli_adapter_config_prep # only if in cli. + + # if asked by _config_prep to aggregate, and HOSTRELEASE is not set, obtain it. + if [[ "${artifact_version_requires_aggregation}" == "yes" ]] && [[ -z "${HOSTRELEASE}" ]]; then + obtain_hostrelease_only # Sets HOSTRELEASE + fi # When run in GHA, assume we're checking/updating the remote cache only. # Local cache is ignored, and if found, it's not unpacked, either from local or remote. @@ -64,9 +70,5 @@ function cli_artifact_run() { skip_unpack_if_found_in_caches="no" fi - if [[ "${CONFIG_DEFS_ONLY}" != "yes" ]]; then - do_with_default_build obtain_complete_artifact # @TODO: < /dev/null -- but what about kernel configure? - else - obtain_complete_artifact - fi + do_with_default_build obtain_complete_artifact # @TODO: < /dev/null -- but what about kernel configure? } diff --git a/lib/functions/host/host-release.sh b/lib/functions/host/host-release.sh index 4300087d24..efadc7db2e 100644 --- a/lib/functions/host/host-release.sh +++ b/lib/functions/host/host-release.sh @@ -8,11 +8,8 @@ # https://github.com/armbian/build/ function obtain_and_check_host_release_and_arch() { - # obtain the host release either from os-release or debian_version - declare -g HOSTRELEASE - HOSTRELEASE="$(cat /etc/os-release | grep VERSION_CODENAME | cut -d"=" -f2)" - [[ -z $HOSTRELEASE ]] && HOSTRELEASE="$(cut -d'/' -f1 /etc/debian_version)" - display_alert "Build host OS release" "${HOSTRELEASE:-(unknown)}" "info" + + obtain_hostrelease_only # obtain the host arch, from dpkg declare -g HOSTARCH @@ -45,3 +42,11 @@ function obtain_and_check_host_release_and_arch() { fi fi } + +function obtain_hostrelease_only() { + # obtain the host release either from os-release or debian_version + declare -g HOSTRELEASE + HOSTRELEASE="$(cat /etc/os-release | grep VERSION_CODENAME | cut -d"=" -f2)" + [[ -z $HOSTRELEASE ]] && HOSTRELEASE="$(cut -d'/' -f1 /etc/debian_version)" + display_alert "Build host OS release" "${HOSTRELEASE:-(unknown)}" "info" +} diff --git a/lib/functions/host/prepare-host.sh b/lib/functions/host/prepare-host.sh index 3339b7329b..e72ab43362 100644 --- a/lib/functions/host/prepare-host.sh +++ b/lib/functions/host/prepare-host.sh @@ -19,6 +19,10 @@ function prepare_host() { } function assert_prepared_host() { + if [[ "${PRE_PREPARED_HOST:-"no"}" == "yes" ]]; then + return 0 + fi + if [[ ${prepare_host_has_already_run:-0} -lt 1 ]]; then exit_with_error "assert_prepared_host: Host has not yet been prepared. This is a bug in armbian-next code. Please report!" fi diff --git a/lib/functions/main/build-packages.sh b/lib/functions/main/build-packages.sh index 1cda1cce81..78539317a7 100644 --- a/lib/functions/main/build-packages.sh +++ b/lib/functions/main/build-packages.sh @@ -53,6 +53,13 @@ function determine_artifacts_to_build_for_image() { artifacts_to_build+=("armbian-bsp-desktop") fi fi + + # If we're only dumping the config, include the rootfs artifact. + # In a "real" build, this artifact is built/consumed by get_or_create_rootfs_cache_chroot_sdcard(), not here. + if [[ "${CONFIG_DEFS_ONLY}" == "yes" ]]; then + artifacts_to_build+=("rootfs") + fi + } function main_default_build_packages() { diff --git a/lib/functions/main/start-end.sh b/lib/functions/main/start-end.sh index e8e34d9435..888196f2d4 100644 --- a/lib/functions/main/start-end.sh +++ b/lib/functions/main/start-end.sh @@ -10,6 +10,25 @@ # Common start/end build functions. Used by the default build and others function main_default_start_build() { + 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. @@ -48,19 +67,6 @@ function main_default_start_build() { mkdir -p "${BIN_WORK_DIR}" ln -s "/usr/bin/python2" "${BIN_WORK_DIR}/python" 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 - - # 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 main_default_end_build() {