From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6518759238035046400 X-Received: by 10.31.150.9 with SMTP id y9mr22070507vkd.111.1517766914532; Sun, 04 Feb 2018 09:55:14 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 10.31.120.9 with SMTP id t9ls3205075vkc.13.gmail; Sun, 04 Feb 2018 09:55:14 -0800 (PST) X-Google-Smtp-Source: AH8x226Ys+AXuzpqy5X9tR/pQt3Jbe6GVZU2SWRPfQCFmlsXrFGZTCWS4E7OXIKYqCJZwgTxXHrO X-Received: by 10.31.203.71 with SMTP id b68mr22238741vkg.43.1517766914135; Sun, 04 Feb 2018 09:55:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517766914; cv=none; d=google.com; s=arc-20160816; b=sSvDUaPHsV+5A6Wpac78/aKcHkaYx+ZPcspI+mX7I9kXsFl0lrTXNBm67Mg9hcDcbo TkN0VA83eq7co2IsTWLVxBLs9U0ZuXz+MkJph70UmksDhsBgHQC7O/Xcl/Pq6t/AGOP+ TOd0VgElGFTEieAa1MKCEU1qFCYV+J1ugslutPnvSuumti6I2yFQSvTnw/0Gl73DAKaU 5etMdDcc4RDsxb5k5EPgTCbDEVseHOQMJY5Mq4326KCNlY4S0dC8Y+XN3TaR35v18uHs 4I2/VS5u4M5UZP/UTvb3rf+b3E4uuAz4KCQs7mD8cWP2m3hWjJFzCCgKjGB/f3nJlRsz S1Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-authentication-results; bh=yPwwWBTgibMu2CyZvEdigfBAOovSe8PlNDS0CwaxRpI=; b=AkZAokJwcPOHaCRINnxDtkaDEp9EzXtCtJt8Ukcq/bGfRflV1og4kFl/eWFfwW+eVa e1uWpI61k8kFYNPYMxCxd/cznHMlBrvKwZnesTrZ+Rhz53gGBtqB4SvBOGcmm7Ebo21v FBJ3JeGg9sv4qy98O5touvQt3Pwgq40fGKZZm0IzSIsyAn3R108Y+bEDeSPJ2sWRJUkk pUSn3lbIcbxTojhyJoKMNM540LE978KUW5XNsWrZV2dke3e7FAbOhH3d5SOqQ1Z8JV5w /jvDoU3EPnAH81E9NsHu3WqMXZ/fnXHVfVMyTjLkh1VRNb7ollgZ1WqjDYpB4Ca5NvHS U2SQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of cedric_hombourger@mentor.com designates 192.94.38.131 as permitted sender) smtp.mailfrom=Cedric_Hombourger@mentor.com Return-Path: Received: from relay1.mentorg.com (relay1.mentorg.com. [192.94.38.131]) by gmr-mx.google.com with ESMTPS id s65si506458vke.3.2018.02.04.09.55.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Feb 2018 09:55:13 -0800 (PST) Received-SPF: pass (google.com: domain of cedric_hombourger@mentor.com designates 192.94.38.131 as permitted sender) client-ip=192.94.38.131; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of cedric_hombourger@mentor.com designates 192.94.38.131 as permitted sender) smtp.mailfrom=Cedric_Hombourger@mentor.com Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-02.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1eiOVV-0005cD-CY from Cedric_Hombourger@mentor.com for isar-users@googlegroups.com; Sun, 04 Feb 2018 09:55:13 -0800 Received: from 3a23c91bf2ab.anacadf.mentorg.com (137.202.0.87) by svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Sun, 4 Feb 2018 17:55:09 +0000 From: To: CC: Cedric Hombourger Subject: [PATCH 2/5] meta: move reprepro handling code to its own class Date: Sun, 4 Feb 2018 17:54:51 +0000 Message-ID: <20180204175454.220-3-Cedric_Hombourger@mentor.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180204175454.220-1-Cedric_Hombourger@mentor.com> References: <20180204175454.220-1-Cedric_Hombourger@mentor.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [137.202.0.87] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) X-TUID: CO5M2DwSqvH2 From: Cedric Hombourger The reprepro handling code (cache creation and update) may be re-used in the buildchroot recipe to later add required build packages to the full repo (if one should be created). Move the code to its own class and inherit it from the image class (the only user at this time). Signed-off-by: Cedric Hombourger --- meta/classes/image.bbclass | 47 +---------------------------------------- meta/classes/reprepro.bbclass | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 meta/classes/reprepro.bbclass diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass index e2cb01b..b20db18 100644 --- a/meta/classes/image.bbclass +++ b/meta/classes/image.bbclass @@ -17,53 +17,8 @@ KERNEL_IMAGE ?= "${@get_image_name(d, 'vmlinuz')}" INITRD_IMAGE ?= "${@get_image_name(d, 'initrd.img')}" inherit ${IMAGE_TYPE} -call_reprepro() { - for i in $(seq 1 ${REPREPRO_LOCK_ATTEMPTS}); do - # According to `sh` manual page, shell exit statuses fall between - # 0-255. The EEXIST error code is (-17), so casting to usigned 8-bit - # integer results value (239). - eexist=$(python -c 'import errno; print(256-errno.EEXIST)') - retval="0" - reprepro $* || retval="$?" - - # If reprepro has failed to get database lock, it returns EEXIST code. - # In this case we continue trying to get lock until max amount of - # attempts is reached. - if [ $retval -eq $eexist ]; then - bbwarn "Failed to get reprepro lock, trying again..." - sleep 5 - else - break - fi - done - - if [ $retval -ne 0 ]; then - bbfatal "reprepro failed" - fi -} - -CACHE_CONF_DIR = "${DEPLOY_DIR_APT}/${DISTRO}/conf" -do_cache_config[dirs] = "${CACHE_CONF_DIR}" -do_cache_config[stamp-extra-info] = "${DISTRO}" - -# Generate reprepro config for current distro if it doesn't exist. Once it's -# generated, this task should do nothing. -do_cache_config() { - if [ ! -e "${CACHE_CONF_DIR}/distributions" ]; then - sed -e "s#{DISTRO_NAME}#"${DEBDISTRONAME}"#g" \ - ${FILESDIR}/distributions.in > ${CACHE_CONF_DIR}/distributions - fi - - path_cache="${DEPLOY_DIR_APT}/${DISTRO}" - path_databases="${DEPLOY_DIR_DB}/${DISTRO}" - - if [ ! -d "${path_databases}" ]; then - call_reprepro -b ${path_cache} \ - --dbdir ${path_databases} \ - export ${DEBDISTRONAME} - fi -} +inherit reprepro addtask cache_config before do_populate do_populate[stamp-extra-info] = "${DISTRO}-${MACHINE}" diff --git a/meta/classes/reprepro.bbclass b/meta/classes/reprepro.bbclass new file mode 100644 index 0000000..dfe48cb --- /dev/null +++ b/meta/classes/reprepro.bbclass @@ -0,0 +1,49 @@ +# This software is a part of ISAR. +# Copyright (C) 2015-2017 ilbers GmbH + +CACHE_CONF_DIR = "${DEPLOY_DIR_APT}/${DISTRO}/conf" +do_cache_config[dirs] = "${CACHE_CONF_DIR}" +do_cache_config[stamp-extra-info] = "${DISTRO}" + +# Generate reprepro config for current distro if it doesn't exist. Once it's +# generated, this task should do nothing. +do_cache_config() { + if [ ! -e "${CACHE_CONF_DIR}/distributions" ]; then + sed -e "s#{DISTRO_NAME}#"${DEBDISTRONAME}"#g" \ + ${FILESDIR}/distributions.in > ${CACHE_CONF_DIR}/distributions + fi + + path_cache="${DEPLOY_DIR_APT}/${DISTRO}" + path_databases="${DEPLOY_DIR_DB}/${DISTRO}" + + if [ ! -d "${path_databases}" ]; then + call_reprepro -b ${path_cache} \ + --dbdir ${path_databases} \ + export ${DEBDISTRONAME} + fi +} + +call_reprepro() { + for i in $(seq 1 ${REPREPRO_LOCK_ATTEMPTS}); do + # According to `sh` manual page, shell exit statuses fall between + # 0-255. The EEXIST error code is (-17), so casting to usigned 8-bit + # integer results value (239). + eexist=$(python -c 'import errno; print(256-errno.EEXIST)') + retval="0" + reprepro $* || retval="$?" + + # If reprepro has failed to get database lock, it returns EEXIST code. + # In this case we continue trying to get lock until max amount of + # attempts is reached. + if [ $retval -eq $eexist ]; then + bbwarn "Failed to get reprepro lock, trying again..." + sleep 5 + else + break + fi + done + + if [ $retval -ne 0 ]; then + bbfatal "reprepro failed" + fi +} -- 2.11.0