Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Addressed last bunch of suggestions :) Tom # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.8 2011/08/22 04:46:31 vapier Exp $ # @ECLASS: check-reqs.eclass # @MAINTAINER: # QA Team q...@gentoo.org # @AUTHOR: # Bo Ørsted Andresen z...@gentoo.org # Original Author: Ciaran McCreesh ciar...@gentoo.org # @BLURB: Provides a uniform way of handling ebuild which have very high build requirements # @DESCRIPTION: # This eclass provides a uniform way of handling ebuilds which have very high # build requirements in terms of memory or disk space. It provides a function # which should usually be called during pkg_setup(). # # The chosen action only happens when the system's resources are detected # correctly and only if they are below the threshold specified by the package. # # @CODE # # need this much memory (does *not* check swap) # CHECKREQS_MEMORY=256M # # # need this much temporary build space # CHECKREQS_DISK_BUILD=2G # # # install will need this much space in /usr # CHECKREQS_DISK_USR=1G # # # install will need this much space in /var # CHECKREQS_DISK_VAR=1024M # # @CODE # # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not # carried out. # # These checks should probably mostly work on non-Linux, and they should # probably degrade gracefully if they don't. Probably. inherit eutils # @ECLASS-VARIABLE: CHECKREQS_MEMORY # @DEFAULT_UNSET # @DESCRIPTION: # How much RAM is needed? Eg.: CHECKREQS_MEMORY=15M # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD # @DEFAULT_UNSET # @DESCRIPTION: # How much diskspace is needed to build the package? Eg.: CHECKREQS_DISK_BUILD=2T # @ECLASS-VARIABLE: CHECKREQS_DISK_USR # @DEFAULT_UNSET # @DESCRIPTION: # How much space in /usr is needed to install the package? Eg.: CHECKREQS_DISK_USR=15G # @ECLASS-VARIABLE: CHECKREQS_DISK_VAR # @DEFAULT_UNSET # @DESCRIPTION: # How much space is needed in /var? Eg.: CHECKREQS_DISK_VAR=3000M EXPORT_FUNCTIONS pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) EXPORT_FUNCTIONS pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac # @FUNCTION: check_reqs # @DESCRIPTION: # Obsolete function executing all the checks and priting out results check_reqs() { debug-print-function ${FUNCNAME} $@ echo ewarn QA: Package calling old ${FUNCNAME} function. ewarn QA: Please file a bug against the package. ewarn QA: It should call check-reqs_pkg_pretend and check-reqs_pkg_setup ewarn QA: and possibly use EAPI=4 or later. echo check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_pkg_setup # @DESCRIPTION: # Exported function running the resources checks in pkg_setup phase. # It should be run in both phases to ensure condition changes between # pkg_pretend and pkg_setup won't affect the build. check-reqs_pkg_setup() { debug-print-function ${FUNCNAME} $@ check-reqs_prepare check-reqs_run check-reqs_output } # @FUNCTION: check-reqs_pkg_pretend # @DESCRIPTION: # Exported function running the resources checks in pkg_pretend phase. check-reqs_pkg_pretend() { debug-print-function ${FUNCNAME} $@ check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_prepare # @DESCRIPTION: # Internal function that checks the variables that should be defined. check-reqs_prepare() { debug-print-function ${FUNCNAME} $@ if [[ -z ${CHECKREQS_MEMORY} -z ${CHECKREQS_DISK_BUILD} -z ${CHECKREQS_DISK_USR} -z ${CHECKREQS_DISK_VAR} ]]; then eerror Set some check-reqs eclass variables if you want to use it. eerror If you are user and see this message fill a bug against the package. die ${FUNCNAME}: check-reqs eclass called but not actualy used! fi } # @FUNCTION: check-reqs_run # @DESCRIPTION: # Internal function that runs the check based on variable settings. check-reqs_run() { debug-print-function ${FUNCNAME} $@ # some people are *censored* unset CHECKREQS_FAILED [[ -n ${CHECKREQS_MEMORY} ]] \ check-reqs_memory \ ${CHECKREQS_MEMORY} [[ -n ${CHECKREQS_DISK_BUILD} ]] \ check-reqs_disk \ ${T} \ ${CHECKREQS_DISK_BUILD} [[ -n ${CHECKREQS_DISK_USR} ]] \ check-reqs_disk \ ${EROOT}/usr \ ${CHECKREQS_DISK_USR} [[ -n ${CHECKREQS_DISK_VAR} ]] \ check-reqs_disk \ ${EROOT}/var \ ${CHECKREQS_DISK_VAR} } # @FUNCTION: check-reqs_get_megs # @DESCRIPTION: # Internal function that returns number in mebibytes. # Converts from 1G=1024 or 1T=1048576 check-reqs_get_mebibytes() {
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Thanks for all the pointers, hopefully I addressed all issues raised by both of you :) Good pointer is that we should probably check if the MERGE_TYPE=binary and not check-reqs ram and disk_build in that case. But there is slight problem how to do it in older eapis. Also Michal if you want to have that DISK array thingu there could you write a patch? Tom # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.8 2011/08/22 04:46:31 vapier Exp $ # @ECLASS: check-reqs.eclass # @MAINTAINER: # QA Team q...@gentoo.org # @AUTHOR: # Bo Ørsted Andresen z...@gentoo.org # Original Author: Ciaran McCreesh ciar...@gentoo.org # @BLURB: Provides a uniform way of handling ebuild which have very high build requirements # @DESCRIPTION: # This eclass provides a uniform way of handling ebuilds which have very high # build requirements in terms of memory or disk space. It provides a function # which should usually be called during pkg_setup(). # # The chosen action only happens when the system's resources are detected # correctly and only if they are below the threshold specified by the package. # # @CODE # # need this much memory (does *not* check swap) # CHECKREQS_MEMORY=256M # # # need this much temporary build space # CHECKREQS_DISK_BUILD=2G # # # install will need this much space in /usr # CHECKREQS_DISK_USR=1G # # # install will need this much space in /var # CHECKREQS_DISK_VAR=1024M # # # go! # pkg_pretend() { #check-reqs_pkg_pretend # } # # # Run once again to ensure that environment didn't # # change since the pretend phase. # pkg_setup() { #check-reqs_pkg_setup # } # @CODE # # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not # carried out. # # These checks should probably mostly work on non-Linux, and they should # probably degrade gracefully if they don't. Probably. inherit eutils # @ECLASS-VARIABLE: CHECKREQS_MEMORY # @DEFAULT_UNSET # @DESCRIPTION: # How much RAM is needed? # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD # @DEFAULT_UNSET # @DESCRIPTION: # How much diskspace is needed to build the package? # @ECLASS-VARIABLE: CHECKREQS_DISK_USR # @DEFAULT_UNSET # @DESCRIPTION: # How much space in /usr is needed to install the package? # @ECLASS-VARIABLE: CHECKREQS_DISK_VAR # @DEFAULT_UNSET # @DESCRIPTION: # How much space is needed in /var? EXPORT_FUNCTIONS pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) EXPORT_FUNCTIONS pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac # @FUNCTION: check_reqs # @DESCRIPTION: # Obsolete function executing all the checks and priting out results check_reqs() { debug-print-function ${FUNCNAME} $@ echo ewarn QA: Package calling old ${FUNCNAME} function. ewarn QA: Please file a bug against the package. ewarn QA: It should call check-reqs_pkg_pretend and check-reqs_pkg_setup ewarn QA: and possibly use EAPI=4 or later. echo check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_pkg_setup # @DESCRIPTION: # Exported function running the resources checks in pkg_setup phase. # It should be run in both phases to ensure condition changes between # pkg_pretend and pkg_setup won't affect the build. check-reqs_pkg_setup() { debug-print-function ${FUNCNAME} $@ check-reqs_prepare check-reqs_run check-reqs_output } # @FUNCTION: check-reqs_pkg_pretend # @DESCRIPTION: # Exported function running the resources checks in pkg_pretend phase. check-reqs_pkg_pretend() { debug-print-function ${FUNCNAME} $@ check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_prepare # @DESCRIPTION: # Internal function that checks the variables that should be defined. check-reqs_prepare() { debug-print-function ${FUNCNAME} $@ if [[ -z ${CHECKREQS_MEMORY} -z ${CHECKREQS_DISK_BUILD} -z ${CHECKREQS_DISK_USR} -z ${CHECKREQS_DISK_VAR} ]]; then eerror Set some check-reqs eclass variables if you want to use it. eerror If you are user and see this message fill a bug against the package. die ${FUNCNAME}: check-reqs eclass called but not actualy used! fi } # @FUNCTION: check-reqs_run # @DESCRIPTION: # Internal function that runs the check based on variable settings. check-reqs_run() { debug-print-function ${FUNCNAME} $@ # some people are *censored* unset CHECKREQS_FAILED [[ -n ${CHECKREQS_MEMORY} ]] \ check-reqs_memory \ ${CHECKREQS_MEMORY} [[ -n ${CHECKREQS_DISK_BUILD} ]] \ check-reqs_disk \ ${T} \ ${CHECKREQS_DISK_BUILD} [[ -n ${CHECKREQS_DISK_USR} ]] \ check-reqs_disk \ ${EROOT}/usr \
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
On Wed, 32 Aug 2011 10:57:08 +0200 Tomáš Chvátal scarab...@gentoo.org wrote: Good pointer is that we should probably check if the MERGE_TYPE=binary and not check-reqs ram and disk_build in that case. But there is slight problem how to do it in older eapis. We simply don't. Life is hard :P. Also Michal if you want to have that DISK array thingu there could you write a patch? Well, I don't see really a need for that if we're still keeping old vars. Now about the code: * I don't see units mentioned nor described in @DESCRIPTION or vars, EXPORT_FUNCTIONS pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) EXPORT_FUNCTIONS pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac Either you export them (which breaks backwards compat) or require users to call them (your @CODE@). Don't do both, it's confusing. check-reqs_get_megs() { debug-print-function ${FUNCNAME} $@ [[ -z ${1} ]] die Usage: ${FUNCNAME} [size] local unit=${1#${1%?}} local size local unit=${1:(-1)} # Temporary workaround for unset units. # Backcompat. if [[ ${unit//*([[:digit:]])} ]]; then # the unit itself was set ; strip it out size=${1%\%} else size=${1} unit=M fi local size=${1%[GMT]} case ${unit} in [gG]) echo $((1024 * ${size})) ;; [mM]) echo ${size} ;; [tT]) echo $((1024 * 1024 * ${size})) ;; I'd just go with capital letters there. [0-9]) echo ${size} ;; (you can add that to the 'M' cond) *) die ${FUNCNAME}: Unknown unit size: ${unit} Size unit. Again. ;; esac } [gG]) echo Gigabytes ;; [mM]) echo Megabytes ;; [tT]) echo Terabytes ;; gibibytes, mebibytes, tebibytes. # @FUNCTION: check-reqs_memory # @DESCRIPTION: # Internal function that checks space on the RAM. 'space on the RAM' sounds bad :P. check-reqs_start_phase \ $(check-reqs_get_number ${size}) \ $(check-reqs_get_unit ${size}) \ RAM Move the number/unit split to _start_phase()? actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \ /proc/meminfo) awk '/MemTotal/ { print $2 }' /proc/meminfo space_megs=$(df -Pm ${1} 2/dev/null | sed -n \ '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2/dev/null) OMFG. space_megs=$(df -Pm ${1} 2/dev/null | awk 'FNR == 2 {print $4}') I guess. # @FUNCTION: check-reqs_unsattisfied unsatisfied. # @DEAULT_UNSET @INTERNAL. -- Best regards, Michał Górny signature.asc Description: PGP signature
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Dne 31.8.2011 12:14, Michał Górny napsal(a): On Wed, 32 Aug 2011 10:57:08 +0200 Tomáš Chvátalscarab...@gentoo.org wrote: Good pointer is that we should probably check if the MERGE_TYPE=binary and not check-reqs ram and disk_build in that case. But there is slight problem how to do it in older eapis. We simply don't. Life is hard :P. Meh in that case i will make it same on all eapis and just won't check for that :) gibibytes, mebibytes, tebibytes. I preffer binary units over this fancy standard :) Even our tools return the binary calculated ones not the decadic ones. actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \ /proc/meminfo) awk '/MemTotal/ { print $2 }' /proc/meminfo Just raw copy from old eclass, didn't feel like updating it, but since you did it I incorporated it :) space_megs=$(df -Pm ${1} 2/dev/null | sed -n \ '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2/dev/null) OMFG. space_megs=$(df -Pm ${1} 2/dev/null | awk 'FNR == 2 {print $4}') I guess. Hehe same as above Rest I hopefully applied. Lemme know if you find something else. # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.8 2011/08/22 04:46:31 vapier Exp $ # @ECLASS: check-reqs.eclass # @MAINTAINER: # QA Team q...@gentoo.org # @AUTHOR: # Bo Ørsted Andresen z...@gentoo.org # Original Author: Ciaran McCreesh ciar...@gentoo.org # @BLURB: Provides a uniform way of handling ebuild which have very high build requirements # @DESCRIPTION: # This eclass provides a uniform way of handling ebuilds which have very high # build requirements in terms of memory or disk space. It provides a function # which should usually be called during pkg_setup(). # # The chosen action only happens when the system's resources are detected # correctly and only if they are below the threshold specified by the package. # # @CODE # # need this much memory (does *not* check swap) # CHECKREQS_MEMORY=256M # # # need this much temporary build space # CHECKREQS_DISK_BUILD=2G # # # install will need this much space in /usr # CHECKREQS_DISK_USR=1G # # # install will need this much space in /var # CHECKREQS_DISK_VAR=1024M # # @CODE # # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not # carried out. # # These checks should probably mostly work on non-Linux, and they should # probably degrade gracefully if they don't. Probably. inherit eutils # @ECLASS-VARIABLE: CHECKREQS_MEMORY # @DEFAULT_UNSET # @DESCRIPTION: # How much RAM is needed? (15M) # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD # @DEFAULT_UNSET # @DESCRIPTION: # How much diskspace is needed to build the package? (13G) # @ECLASS-VARIABLE: CHECKREQS_DISK_USR # @DEFAULT_UNSET # @DESCRIPTION: # How much space in /usr is needed to install the package? (2T) # @ECLASS-VARIABLE: CHECKREQS_DISK_VAR # @DEFAULT_UNSET # @DESCRIPTION: # How much space is needed in /var? (3000M) DEPEND=sys-apps/gawk EXPORT_FUNCTIONS pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) EXPORT_FUNCTIONS pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac # @FUNCTION: check_reqs # @DESCRIPTION: # Obsolete function executing all the checks and priting out results check_reqs() { debug-print-function ${FUNCNAME} $@ echo ewarn QA: Package calling old ${FUNCNAME} function. ewarn QA: Please file a bug against the package. ewarn QA: It should call check-reqs_pkg_pretend and check-reqs_pkg_setup ewarn QA: and possibly use EAPI=4 or later. echo check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_pkg_setup # @DESCRIPTION: # Exported function running the resources checks in pkg_setup phase. # It should be run in both phases to ensure condition changes between # pkg_pretend and pkg_setup won't affect the build. check-reqs_pkg_setup() { debug-print-function ${FUNCNAME} $@ check-reqs_prepare check-reqs_run check-reqs_output } # @FUNCTION: check-reqs_pkg_pretend # @DESCRIPTION: # Exported function running the resources checks in pkg_pretend phase. check-reqs_pkg_pretend() { debug-print-function ${FUNCNAME} $@ check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_prepare # @DESCRIPTION: # Internal function that checks the variables that should be defined. check-reqs_prepare() { debug-print-function ${FUNCNAME} $@ if [[ -z ${CHECKREQS_MEMORY} -z ${CHECKREQS_DISK_BUILD} -z ${CHECKREQS_DISK_USR} -z ${CHECKREQS_DISK_VAR} ]]; then eerror Set some check-reqs eclass variables if you want to use it. eerror If you are user and see this message fill a bug against the package. die ${FUNCNAME}: check-reqs eclass called but not actualy used! fi } # @FUNCTION:
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
On Wed, 31 Aug 2011 12:32:03 +0200 Tomáš Chvátal scarab...@gentoo.org wrote: gibibytes, mebibytes, tebibytes. I preffer binary units over this fancy standard :) Even our tools return the binary calculated ones not the decadic ones. These are binary units, rather those fancy misnamed binary units of yours. It's not fancy standard, it's the ONLY standard :P. # @ECLASS-VARIABLE: CHECKREQS_DISK_USR # @DEFAULT_UNSET # @DESCRIPTION: # How much space in /usr is needed to install the package? (2T) Not this looks like a insane default :D. [G]) echo $((1024 * ${size})) ;; just 'G)', 'M)', 'T)'. ebegin Checking for at least ${sizeunit} ${3} What ${3} there? I think you should decide whether to name all vars, or use numeric ones. # @FUNCTION: check-reqs_unsattisfied docstring not updated. -- Best regards, Michał Górny signature.asc Description: PGP signature
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Hi, Am Mittwoch, 31. August 2011, 12:32:03 schrieb Tomáš Chvátal: Hehe same as above Rest I hopefully applied. Lemme know if you find something else. just a user lurking here, but # @FUNCTION: check-reqs_unsattisfied # @DESCRIPTION: # Internal function that inform about check result. # It has different output between pretend and setup phase, # where in pretend phase it is fatal. check-reqs_unsattisfied() { is this a typo (unsatisfied) or on purpose? Regards, Michael
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Dne 31.8.2011 14:38, Michał Górny napsal(a): On Wed, 31 Aug 2011 12:32:03 +0200 Tomáš Chvátalscarab...@gentoo.org wrote: gibibytes, mebibytes, tebibytes. I preffer binary units over this fancy standard :) Even our tools return the binary calculated ones not the decadic ones. These are binary units, rather those fancy misnamed binary units of yours. It's not fancy standard, it's the ONLY standard :P. # @ECLASS-VARIABLE: CHECKREQS_DISK_USR # @DEFAULT_UNSET # @DESCRIPTION: # How much space in /usr is needed to install the package? (2T) Not this looks like a insane default :D. [G]) echo $((1024 * ${size})) ;; just 'G)', 'M)', 'T)'. ebegin Checking for at least ${sizeunit} ${3} What ${3} there? I think you should decide whether to name all vars, or use numeric ones. # @FUNCTION: check-reqs_unsattisfied docstring not updated. How about now? # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.8 2011/08/22 04:46:31 vapier Exp $ # @ECLASS: check-reqs.eclass # @MAINTAINER: # QA Team q...@gentoo.org # @AUTHOR: # Bo Ørsted Andresen z...@gentoo.org # Original Author: Ciaran McCreesh ciar...@gentoo.org # @BLURB: Provides a uniform way of handling ebuild which have very high build requirements # @DESCRIPTION: # This eclass provides a uniform way of handling ebuilds which have very high # build requirements in terms of memory or disk space. It provides a function # which should usually be called during pkg_setup(). # # The chosen action only happens when the system's resources are detected # correctly and only if they are below the threshold specified by the package. # # @CODE # # need this much memory (does *not* check swap) # CHECKREQS_MEMORY=256M # # # need this much temporary build space # CHECKREQS_DISK_BUILD=2G # # # install will need this much space in /usr # CHECKREQS_DISK_USR=1G # # # install will need this much space in /var # CHECKREQS_DISK_VAR=1024M # # @CODE # # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not # carried out. # # These checks should probably mostly work on non-Linux, and they should # probably degrade gracefully if they don't. Probably. inherit eutils # @ECLASS-VARIABLE: CHECKREQS_MEMORY # @DEFAULT_UNSET # @DESCRIPTION: # How much RAM is needed? Eg.: CHECKREQS_MEMORY=15M # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD # @DEFAULT_UNSET # @DESCRIPTION: # How much diskspace is needed to build the package? Eg.: CHECKREQS_DISK_BUILD=2T # @ECLASS-VARIABLE: CHECKREQS_DISK_USR # @DEFAULT_UNSET # @DESCRIPTION: # How much space in /usr is needed to install the package? Eg.: CHECKREQS_DISK_USR=15G # @ECLASS-VARIABLE: CHECKREQS_DISK_VAR # @DEFAULT_UNSET # @DESCRIPTION: # How much space is needed in /var? Eg.: CHECKREQS_DISK_VAR=3000M DEPEND=sys-apps/gawk EXPORT_FUNCTIONS pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) EXPORT_FUNCTIONS pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac # @FUNCTION: check_reqs # @DESCRIPTION: # Obsolete function executing all the checks and priting out results check_reqs() { debug-print-function ${FUNCNAME} $@ echo ewarn QA: Package calling old ${FUNCNAME} function. ewarn QA: Please file a bug against the package. ewarn QA: It should call check-reqs_pkg_pretend and check-reqs_pkg_setup ewarn QA: and possibly use EAPI=4 or later. echo check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_pkg_setup # @DESCRIPTION: # Exported function running the resources checks in pkg_setup phase. # It should be run in both phases to ensure condition changes between # pkg_pretend and pkg_setup won't affect the build. check-reqs_pkg_setup() { debug-print-function ${FUNCNAME} $@ check-reqs_prepare check-reqs_run check-reqs_output } # @FUNCTION: check-reqs_pkg_pretend # @DESCRIPTION: # Exported function running the resources checks in pkg_pretend phase. check-reqs_pkg_pretend() { debug-print-function ${FUNCNAME} $@ check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_prepare # @DESCRIPTION: # Internal function that checks the variables that should be defined. check-reqs_prepare() { debug-print-function ${FUNCNAME} $@ if [[ -z ${CHECKREQS_MEMORY} -z ${CHECKREQS_DISK_BUILD} -z ${CHECKREQS_DISK_USR} -z ${CHECKREQS_DISK_VAR} ]]; then eerror Set some check-reqs eclass variables if you want to use it. eerror If you are user and see this message fill a bug against the package. die ${FUNCNAME}: check-reqs eclass called but not actualy used! fi } # @FUNCTION: check-reqs_run # @DESCRIPTION: # Internal function that runs the check based on variable settings. check-reqs_run() { debug-print-function
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
DEPEND=sys-apps/gawk gawk is in the system set. If you really want to DEP on it explicitly, maybe we should create a virtual, as any POSIX-compliant awk will handle this. # Temporary workaround for unset units. # Backcompat. [[ ${unit//*([[:digit:]])} ]] || unit=M case ${unit} in G) echo Gibibytes ;; M) echo Mebibytes ;; T) echo Tebibytes ;; *) die ${FUNCNAME}: Unknown unit: ${unit} ;; esac } case ${unit} in [M0-9]) echo mebibytes ;; ... And yes, they actually shall be written lowercase [1]. [1]:http://www.bipm.org/en/si/si_brochure/chapter5/5-2.html -- Best regards, Michał Górny signature.asc Description: PGP signature
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Dne 31.8.2011 17:30, Michał Górny napsal(a): DEPEND=sys-apps/gawk gawk is in the system set. If you really want to DEP on it explicitly, maybe we should create a virtual, as any POSIX-compliant awk will handle this. # Temporary workaround for unset units. # Backcompat. [[ ${unit//*([[:digit:]])} ]] || unit=M case ${unit} in G) echo Gibibytes ;; M) echo Mebibytes ;; T) echo Tebibytes ;; *) die ${FUNCNAME}: Unknown unit: ${unit} ;; esac } case ${unit} in [M0-9]) echo mebibytes ;; ... And yes, they actually shall be written lowercase [1]. [1]:http://www.bipm.org/en/si/si_brochure/chapter5/5-2.html Wonder if it would not be easier just to talk on irc so we don't bother everyone :P Anyway addressed :) # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.8 2011/08/22 04:46:31 vapier Exp $ # @ECLASS: check-reqs.eclass # @MAINTAINER: # QA Team q...@gentoo.org # @AUTHOR: # Bo Ørsted Andresen z...@gentoo.org # Original Author: Ciaran McCreesh ciar...@gentoo.org # @BLURB: Provides a uniform way of handling ebuild which have very high build requirements # @DESCRIPTION: # This eclass provides a uniform way of handling ebuilds which have very high # build requirements in terms of memory or disk space. It provides a function # which should usually be called during pkg_setup(). # # The chosen action only happens when the system's resources are detected # correctly and only if they are below the threshold specified by the package. # # @CODE # # need this much memory (does *not* check swap) # CHECKREQS_MEMORY=256M # # # need this much temporary build space # CHECKREQS_DISK_BUILD=2G # # # install will need this much space in /usr # CHECKREQS_DISK_USR=1G # # # install will need this much space in /var # CHECKREQS_DISK_VAR=1024M # # @CODE # # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not # carried out. # # These checks should probably mostly work on non-Linux, and they should # probably degrade gracefully if they don't. Probably. inherit eutils # @ECLASS-VARIABLE: CHECKREQS_MEMORY # @DEFAULT_UNSET # @DESCRIPTION: # How much RAM is needed? Eg.: CHECKREQS_MEMORY=15M # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD # @DEFAULT_UNSET # @DESCRIPTION: # How much diskspace is needed to build the package? Eg.: CHECKREQS_DISK_BUILD=2T # @ECLASS-VARIABLE: CHECKREQS_DISK_USR # @DEFAULT_UNSET # @DESCRIPTION: # How much space in /usr is needed to install the package? Eg.: CHECKREQS_DISK_USR=15G # @ECLASS-VARIABLE: CHECKREQS_DISK_VAR # @DEFAULT_UNSET # @DESCRIPTION: # How much space is needed in /var? Eg.: CHECKREQS_DISK_VAR=3000M EXPORT_FUNCTIONS pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) EXPORT_FUNCTIONS pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac # @FUNCTION: check_reqs # @DESCRIPTION: # Obsolete function executing all the checks and priting out results check_reqs() { debug-print-function ${FUNCNAME} $@ echo ewarn QA: Package calling old ${FUNCNAME} function. ewarn QA: Please file a bug against the package. ewarn QA: It should call check-reqs_pkg_pretend and check-reqs_pkg_setup ewarn QA: and possibly use EAPI=4 or later. echo check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_pkg_setup # @DESCRIPTION: # Exported function running the resources checks in pkg_setup phase. # It should be run in both phases to ensure condition changes between # pkg_pretend and pkg_setup won't affect the build. check-reqs_pkg_setup() { debug-print-function ${FUNCNAME} $@ check-reqs_prepare check-reqs_run check-reqs_output } # @FUNCTION: check-reqs_pkg_pretend # @DESCRIPTION: # Exported function running the resources checks in pkg_pretend phase. check-reqs_pkg_pretend() { debug-print-function ${FUNCNAME} $@ check-reqs_pkg_setup $@ } # @FUNCTION: check-reqs_prepare # @DESCRIPTION: # Internal function that checks the variables that should be defined. check-reqs_prepare() { debug-print-function ${FUNCNAME} $@ if [[ -z ${CHECKREQS_MEMORY} -z ${CHECKREQS_DISK_BUILD} -z ${CHECKREQS_DISK_USR} -z ${CHECKREQS_DISK_VAR} ]]; then eerror Set some check-reqs eclass variables if you want to use it. eerror If you are user and see this message fill a bug against the package. die ${FUNCNAME}: check-reqs eclass called but not actualy used! fi } # @FUNCTION: check-reqs_run # @DESCRIPTION: # Internal function that runs the check based on variable settings. check-reqs_run() { debug-print-function ${FUNCNAME} $@ # some people are
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
On Wed, 31 Aug 2011, Tomáš Chvátal wrote: [M0-9]) echo mebibytes ;; Anyway addressed :) Please be consistent and change the following occurences too: # Internal function that returns number in megabites. ewarn QA: Assuming Megabytes. And the name of check-reqs_get_megs() is a misnomer then, maybe it should be called check_reqs_get_size or check_reqs_get_memory? Ulrich
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
On Wed, Aug 31, 2011 at 3:14 AM, Michał Górny mgo...@gentoo.org wrote: On Wed, 32 Aug 2011 10:57:08 +0200 Tomáš Chvátal scarab...@gentoo.org wrote: Good pointer is that we should probably check if the MERGE_TYPE=binary and not check-reqs ram and disk_build in that case. But there is slight problem how to do it in older eapis. We simply don't. Life is hard :P. Also Michal if you want to have that DISK array thingu there could you write a patch? Well, I don't see really a need for that if we're still keeping old vars. Now about the code: * I don't see units mentioned nor described in @DESCRIPTION or vars, EXPORT_FUNCTIONS pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) EXPORT_FUNCTIONS pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac Either you export them (which breaks backwards compat) or require users to call them (your @CODE@). Don't do both, it's confusing. check-reqs_get_megs() { debug-print-function ${FUNCNAME} $@ [[ -z ${1} ]] die Usage: ${FUNCNAME} [size] local unit=${1#${1%?}} local size local unit=${1:(-1)} # Temporary workaround for unset units. # Backcompat. if [[ ${unit//*([[:digit:]])} ]]; then # the unit itself was set ; strip it out size=${1%\%} else size=${1} unit=M fi local size=${1%[GMT]} case ${unit} in [gG]) echo $((1024 * ${size})) ;; [mM]) echo ${size} ;; [tT]) echo $((1024 * 1024 * ${size})) ;; Also it is my understanding that all tokens in $(()) go through expansion, so for instance: $(( 1024 * 1024 * size )) and $(( 1024 * 1024 * ${size})) are equivalent. Is this only in bash4? Do we have a style preference? I'd just go with capital letters there. [0-9]) echo ${size} ;; (you can add that to the 'M' cond) *) die ${FUNCNAME}: Unknown unit size: ${unit} Size unit. Again. ;; esac } [gG]) echo Gigabytes ;; [mM]) echo Megabytes ;; [tT]) echo Terabytes ;; gibibytes, mebibytes, tebibytes. # @FUNCTION: check-reqs_memory # @DESCRIPTION: # Internal function that checks space on the RAM. 'space on the RAM' sounds bad :P. check-reqs_start_phase \ $(check-reqs_get_number ${size}) \ $(check-reqs_get_unit ${size}) \ RAM Move the number/unit split to _start_phase()? actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \ /proc/meminfo) awk '/MemTotal/ { print $2 }' /proc/meminfo space_megs=$(df -Pm ${1} 2/dev/null | sed -n \ '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2/dev/null) OMFG. space_megs=$(df -Pm ${1} 2/dev/null | awk 'FNR == 2 {print $4}') I guess. # @FUNCTION: check-reqs_unsattisfied unsatisfied. # @DEAULT_UNSET @INTERNAL. -- Best regards, Michał Górny
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
On Wed, 31 Aug 2011, Alec Warner wrote: Also it is my understanding that all tokens in $(()) go through expansion, so for instance: $(( 1024 * 1024 * size )) and $(( 1024 * 1024 * ${size})) are equivalent. Is this only in bash4? It's like this since bash 2.05 at least. Do we have a style preference? Personally, I'd prefer the first variant. Ulrich
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Dne 31.8.2011 21:03, Ulrich Mueller napsal(a): On Wed, 31 Aug 2011, Alec Warner wrote: Also it is my understanding that all tokens in $(()) go through expansion, so for instance: $(( 1024 * 1024 * size )) and $(( 1024 * 1024 * ${size})) are equivalent. Is this only in bash4? It's like this since bash 2.05 at least. Do we have a style preference? Personally, I'd prefer the first variant. Ulrich I thought it is mandatory to use the second variant, otherwise i preffer the first myself as it is from bash 2 or so :) signature.asc Description: OpenPGP digital signature
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Dne 30.8.2011 09:35, Michał Górny napsal(a): On Tue, 30 Aug 2011 09:11:40 +0200 Tomáš Chvátalscarab...@gentoo.org wrote: @@ -66,80 +52,234 @@ # @ECLASS-VARIABLE: CHECKREQS_MEMORY # @DESCRIPTION: -# How much RAM is needed in MB? +# @DEAULT_UNSET +# How much RAM is needed? Typo. Also, shouldn't defaults go before @DESCRIPTION: ? Yeah sedding it failed :) # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD # @DESCRIPTION: -# How much diskspace is needed to build the package? In MB +# @DEAULT_UNSET +# How much diskspace is needed to build the package? Ditto. # @ECLASS-VARIABLE: CHECKREQS_DISK_USR # @DESCRIPTION: -# How much space in /usr is needed to install the package? In MB +# @DEAULT_UNSET +# How much space in /usr is needed to install the package? Ditto. # @ECLASS-VARIABLE: CHECKREQS_DISK_VAR # @DESCRIPTION: -# How much space is needed in /var? In MB +# @DEAULT_UNSET +# How much space is needed in /var? Ditto. +CHECKREQS_EXPORTED_FUNCTIONS=pkg_setup +case ${EAPI:-0} in + 0|1|2|3) ;; + 4) CHECKREQS_EXPORTED_FUNCTIONS=${EXPORTED_FUNCTIONS} pkg_pretend ;; Not the same var. + *) die EAPI=${EAPI} is not supported ;; +esac CHECKREQS_EXPORTED_FUNCTIONS is not used anywhere. Fixed. # @FUNCTION: check_reqs # @DESCRIPTION: -# Checks the requirements given in the specific variables. If not reached, -# either prints a warning or dies. +# Obsolete function executing all the checks and priting out results check_reqs() { - [[ -n ${1} ]] die Usage: check_reqs + debug-print-function ${FUNCNAME} $@ + + echo + ewarn QA: Package calling old ${FUNCNAME} function. + ewarn QA: Please file a bug against the package. + ewarn QA: It should call check-reqs_pkg_pretend and check-reqs_pkg_setup + ewarn QA: and possibly use EAPI=4 or later. + echo + + check-reqs_pkg_setup $@ +} - export CHECKREQS_NEED_SLEEP= CHECKREQS_NEED_DIE= - if [[ $CHECKREQS_ACTION != ignore ]] ; then - [[ -n $CHECKREQS_MEMORY ]] check_build_memory - [[ -n $CHECKREQS_DISK_BUILD ]] check_build_disk \ - ${T} ${CHECKREQS_DISK_BUILD} - [[ -n $CHECKREQS_DISK_USR ]] check_build_disk \ - ${ROOT}/usr ${CHECKREQS_DISK_USR} - [[ -n $CHECKREQS_DISK_VAR ]] check_build_disk \ - ${ROOT}/var ${CHECKREQS_DISK_VAR} +# @FUNCTION: check-reqs_pkg_setup +# @DESCRIPTION: +# Exported function running the resources checks in pkg_setup phase. +# It should be run in both phases to ensure condition changes between +# pkg_pretend and pkg_setup won't affect the build. +check-reqs_pkg_setup() { + debug-print-function ${FUNCNAME} $@ + + check-reqs_prepare + check-reqs_run + check-reqs_output +} + +# @FUNCTION: check-reqs_pkg_pretend +# @DESCRIPTION: +# Exported function running the resources checks in pkg_pretend phase. +check-reqs_pkg_pretend() { + debug-print-function ${FUNCNAME} $@ + + check-reqs_pkg_setup $@ +} + +# @FUNCTION: check-reqs_prepare +# @DESCRIPTION: +# Internal function that checks the variables that should be defined. +check-reqs_prepare() { + debug-print-function ${FUNCNAME} $@ + + if [[ -z ${CHECKREQS_MEMORY} + -z ${CHECKREQS_DISK_BUILD} + -z ${CHECKREQS_DISK_USR} + -z ${CHECKREQS_DISK_VAR} ]]; then + eerror Set some check-reqs eclass variables if you want to use it. + eerror If you are user and see this message fill a bug against the package. + die ${FUNCNAME}: check-reqs eclass called but not actualy used! fi +} - if [[ -n ${CHECKREQS_NEED_SLEEP} ]] ; then - echo - ewarn Bad things may happen! You may abort the build by pressing ctrl+c in - ewarn the next 15 seconds. - ewarn - einfo To make this kind of warning a fatal error, add a line to /etc/make.conf - einfo setting CHECKREQS_ACTION=\error\. To skip build requirements checking, - einfo set CHECKREQS_ACTION=\ignore\. - epause 15 +# @FUNCTION: check-reqs_run +# @DESCRIPTION: +# Internal function that runs the check based on variable settings. +check-reqs_run() { + debug-print-function ${FUNCNAME} $@ + + # some people are *censored* + unset CHECKREQS_FAILED + + [[ -n ${CHECKREQS_MEMORY} ]] \ + check-reqs_memory \ + ${CHECKREQS_MEMORY} + + [[ -n ${CHECKREQS_DISK_BUILD} ]] \ + check-reqs_disk \ + ${T} \ + ${CHECKREQS_DISK_BUILD} Why not WORKDIR? I thought workdir is present later than $T plus it was used before and I just kept it. + + [[ -n ${CHECKREQS_DISK_USR} ]] \ + check-reqs_disk \ + ${EROOT}/usr \ +
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
On Tue, 30 Aug 2011, Tomáš Chvátal wrote: CHECKREQS_EXPORTED_FUNCTIONS=pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) CHECKREQS_EXPORTED_FUNCTIONS=${CHECKREQS_EXPORTED_FUNCTIONS} pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac EXPORT_FUNCTIONS ${CHECKREQS_EXPORTED_FUNCTIONS} unset CHECKREQS_EXPORTED_FUNCTIONS No need for a global variable here, the following works as well and is easier to read: EXPORT_FUNCTIONS pkg_setup case ${EAPI:-0} in 0|1|2|3) ;; 4) EXPORT_FUNCTIONS pkg_pretend ;; *) die EAPI=${EAPI} is not supported ;; esac Ulrich
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
On Tue, 30 Aug 2011 10:04:50 +0200 Tomáš Chvátal scarab...@gentoo.org wrote: + [[ -n ${CHECKREQS_DISK_BUILD} ]] \ + check-reqs_disk \ + ${T} \ + ${CHECKREQS_DISK_BUILD} Why not WORKDIR? I thought workdir is present later than $T plus it was used before and I just kept it. Ok, WORKDIR may not exist in pkg_setup()/pkg_pretend() indeed. On the other hand, you should perform those checks only when building sources and not when installing binpkg. Think about that. + + [[ -n ${CHECKREQS_DISK_USR} ]] \ + check-reqs_disk \ + ${EROOT}/usr \ + ${CHECKREQS_DISK_USR} + + [[ -n ${CHECKREQS_DISK_VAR} ]] \ + check-reqs_disk \ + ${EROOT}/var \ + ${CHECKREQS_DISK_VAR} +} Also, it may be a good idea to add some kind of generic var for this. Like: CHECKREQS_DISK_INSTALLED=( /usr 1234M /var 2345M ) I dont think that syntax like this would be more readable than the current one. Plus I preffer keeping backcompat the easy way But it won't limit you to random dirs in the fs. +# @DESCRIPTION: +# Internal function that returns number in megabites. +# Converts from 1G=1024 or 1T=1048576 +check-reqs_get_megs() { + debug-print-function ${FUNCNAME} $@ + + [[ -z ${1} ]] die Usage: ${FUNCNAME} [size] + + local unit=${1//[[:digit:]]/} + local size=${1//[[:alpha:]]/} Seems hacky and poor. What if one uses '1G234'? :P Yeah I will rather ignore it and just expect the users of the eclass are not complete asses. Maybe you should simply use '#' and '%' like in clear shell substitutions rather than running such a heavy substitutions? Not to mention in your case basically getting the last char would suffice. Start from scratch, write check-reqs-r1, make it SIMPLE. Won't create new function for simple usage like this. If you really consider this similar to python eclass you should look in that again, this is actually quite simple bash compared to it :) Quite simple bash doesn't do regexps that much. And if someone uses regexps that heavily, that means he misses a point. -- Best regards, Michał Górny signature.asc Description: PGP signature