# This software is a part of ISAR. # Copyright (C) 2017-2018 Mixed-Mode GmbH # # This class implements common functionality for the apt cache. # # Todo: # 1. When a function of this API return an error, bitbake should output the last function produced the error! # # 2. Add functionality of creating snapshots of local isar repo. # # CFG_FILE = "${CACHE_CONF_DIR}/${CACHE_CFG_FILE}" MIRROR = "${DISTRO_SUITE}-mirror" SNAPSHOT_BASENAME="snapshot" ISAR_REPO_LOCAL = "isar-repo-local" ISAR_FIRST_BUILD_DONE = "${TMPDIR}/first_build_done" # Reproducible build is not default ISAR_REPRODUCIBLE_BUILD ?= "1" # Rename a snapshot # $1: Old name. # $2: New name. _rename_snapshot() { aptly -config=${CFG_FILE} snapshot rename $1 $2 } # Create a new repository database for Isar generated packages. # $1: Repository database name _repo_db_create() { aptly -config=${CFG_FILE} \ repo create \ -component="main" \ -distribution="${DISTRO_SUITE}" \ $1 } # Drop a created repository database silenty. _repo_db_drop() { aptly -config=${CFG_FILE} \ repo drop \ $1 || bbwarn "drop db failed" } # Add packages to the local repository database. # $1: Repository database name. # $*: Packages to add. _repo_db_add_package() { repo=$1 shift aptly -config=${CFG_FILE} repo add -force-replace $repo $* } # Delete packages from the repository database. # $1: Repository database name. # $*: Packages to delete. _repo_db_delete_package() { # # Todo: Remove from pool? But maybe this is required for snapshots? # We have build fragments saved at the pool! That is good. # # After 3 rebuilds: # #./public/isar/pool/main/s/swupdate/swupdate_1.0_armhf.deb #./pool/df/88/702fa609fbd90b735d7cdb6dfeef_swupdate_1.0_armhf.deb #./pool/f0/6e/21d09a07366d7f9f7f6690ea7656_swupdate_1.0_armhf.deb #./pool/bd/c3/974c8903d41666d23239a8330627_swupdate_1.0_armhf.deb repo=$1 shift aptly -config=${CFG_FILE} repo remove $repo $* } # Publish repository consumed by apt. This function can only be called # for repositories # $1: Repository database name # $2: Path Prefix _repo_db_publish(){ aptly -config=${CFG_FILE} \ publish repo \ -architectures="${DEB_HOST_ARCH},${DISTRO_ARCH}" \ $1 \ $2 } # Drop an already published repository. # $1: Path prefix _repo_db_publish_drop() { aptly -config=${CFG_FILE} \ publish drop \ ${DISTRO_SUITE} \ $1 || bbwarn "drop published failed" } # Switch already published repository to new repository. This # will change the content of the published repository. This function # can only be called on published repos. # $1: Prefix. _repo_db_published_update() { aptly -config=${CFG_FILE} \ publish update \ -force-overwrite \ ${DISTRO_SUITE} $1 } # Add packages to the isar cache. # $1: Repository database name. # $2: Repository prefix # $*: Packages to add. cache_add_package() { repo=$1 prefix=$2 shift 2 _repo_db_add_package $repo $* _repo_db_published_update $prefix } # Delete a package from the apt cache. # This function is used to be called within do_clean(all) task. # $1: Repository database name. # $2: Repository prefix # $*: Packages to delete. cache_delete_package() { repo=$1 prefix=$2 shift 2 _repo_db_delete_package $repo $* _repo_db_published_update $prefix } cache_create_snapshot() { aptly -config=${CFG_FILE} \ snapshot create ${SNAPSHOT_BASENAME}_${DATETIME} from repo ${ISAR_REPO_LOCAL} } cache_load_snapshot() { "${FUNCNAME[1]} not implemented." } # Setup the apt cache, only if no cache is available, yet. do_cache_setup() { set -E _cleanup() { ret=$? bbwarn "Error in apt-cache.bblcass: ${BASH_SOURCE[0]}: (Line ${BASH_LINENO[0]}, Func:${FUNCNAME[1]})" (exit $ret) || bb_exit_handler } trap '_cleanup' ERR # Very first build of isar. Setting up the cache. if [ ! -e "${CFG_FILE}" ]; then bbplain "Creating local apt cache for first build." sed -e 's|##CACHE_DIR##|${CACHE_DIR}|' \ ${FILESDIR}/${CACHE_CFG_FILE}.in > ${CFG_FILE} _repo_db_create ${ISAR_REPO_LOCAL} ${ISAR_CACHE_LOCAL_PREFIX} _repo_db_publish ${ISAR_REPO_LOCAL} ${ISAR_CACHE_LOCAL_PREFIX} fi if [ -e "${ISAR_FIRST_BUILD_DONE}" ] && [ "${REPRODUCIBLE_BUILD_ENABLED}" == "1" ]; then bbplain "Reusing last apt cache snapshot: $(aptly --config=${CFG_FILE} --raw -sort=time snapshot list | tail -n 1)" return fi #bbwarn "Republishing repo of last build" #_repo_db_publish_drop ${ISAR_CACHE_LOCAL_PREFIX} #_repo_db_drop ${ISAR_REPO_LOCAL} #_repo_db_create ${ISAR_REPO_LOCAL} ${ISAR_CACHE_LOCAL_PREFIX} #_repo_db_publish ${ISAR_REPO_LOCAL} ${ISAR_CACHE_LOCAL_PREFIX} } addtask do_cache_setup before do_rootfs do_cache_setup[dirs] += "${CACHE_CONF_DIR}" do_cache_setup[lockfiles] = "${DPKG_LOCK}"