/[gentoo-x86]/eclass/check-reqs.eclass
Gentoo

Diff of /eclass/check-reqs.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.1.1.1
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2004 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.1 2004/11/19 20:57:31 ciaranm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.1.1.1 2005/11/30 09:59:18 chriswhite Exp $
4# 4#
5# Original Author: Ciaran McCreesh <ciaranm@gentoo.org> 5# Original Author: Ciaran McCreesh <ciaranm@gentoo.org>
6# 6#
7# This eclass provides a uniform way of handling ebuilds which have very high 7# This eclass provides a uniform way of handling ebuilds which have very high
8# build requirements in terms of memory or disc space. It provides a function 8# build requirements in terms of memory or disc space. It provides a function
9# which should usually be called during pkg_setup(). 9# which should usually be called during pkg_setup().
10# 10#
11# From a user perspective, the variable BUILDREQS_ACTION can be set to: 11# From a user perspective, the variable CHECKREQS_ACTION can be set to:
12# * "warn" (default), which will display a warning and wait for 15s 12# * "warn" (default), which will display a warning and wait for 15s
13# * "error", which will make the ebuild error out 13# * "error", which will make the ebuild error out
14# * "ignore", which will not take any action 14# * "ignore", which will not take any action
15# The chosen action only happens when the system's resources are detected 15# The chosen action only happens when the system's resources are detected
16# correctly and only if they are below the threshold specified by the package. 16# correctly and only if they are below the threshold specified by the package.
22# 22#
23# pkg_setup() { 23# pkg_setup() {
24# # values in MBytes 24# # values in MBytes
25# 25#
26# # need this much memory (does *not* check swap) 26# # need this much memory (does *not* check swap)
27# BUILDREQS_MEMORY="256" 27# CHECKREQS_MEMORY="256"
28# 28#
29# # need this much temporary build space 29# # need this much temporary build space
30# BUILDREQS_DISK_BUILD="2048" 30# CHECKREQS_DISK_BUILD="2048"
31# 31#
32# # install will need this much space in /usr 32# # install will need this much space in /usr
33# BUILDREQS_DISK_USR="1024" 33# CHECKREQS_DISK_USR="1024"
34# 34#
35# # install will need this much space in /var 35# # install will need this much space in /var
36# BUILDREQS_DISK_VAR="1024" 36# CHECKREQS_DISK_VAR="1024"
37# 37#
38# # go! 38# # go!
39# check_reqs 39# check_reqs
40# } 40# }
41# 41#
42# You should *not* override the user's BUILDREQS_ACTION setting, nor should you 42# You should *not* override the user's CHECKREQS_ACTION setting, nor should you
43# attempt to provide a value if it is unset. Note that the environment variables 43# attempt to provide a value if it is unset. Note that the environment variables
44# are used rather than parameters for a few reasons: 44# are used rather than parameters for a few reasons:
45# * easier to do if use blah ; then things 45# * easier to do if use blah ; then things
46# * we might add in additional requirements things later 46# * we might add in additional requirements things later
47# If you don't specify a value for, say, BUILDREQS_MEMORY, then the test is not 47# If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not
48# carried out. 48# carried out.
49# 49#
50# These checks should probably mostly work on non-Linux, and they should 50# These checks should probably mostly work on non-Linux, and they should
51# probably degrade gracefully if they don't. Probably. 51# probably degrade gracefully if they don't. Probably.
52 52
53inherit eutils 53inherit eutils
54 54
55ECLASS=check-reqs
56INHERITED="$INHERITED $ECLASS"
57 55
58check_reqs() { 56check_reqs() {
59 [ -n "$1" ] && die "Usage: check_reqs" 57 [ -n "$1" ] && die "Usage: check_reqs"
60 58
61 export BUILDREQS_NEED_SLEEP="" BUILDREQS_NEED_DIE="" 59 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
62 if [ "$BUILDREQS_ACTION" != "ignore" ] ; then 60 if [ "$CHECKREQS_ACTION" != "ignore" ] ; then
63 [ -n "$BUILDREQS_MEMORY" ] && check_build_memory 61 [ -n "$CHECKREQS_MEMORY" ] && check_build_memory
64 [ -n "$BUILDREQS_DISK_BUILD" ] && check_build_disk \ 62 [ -n "$CHECKREQS_DISK_BUILD" ] && check_build_disk \
65 "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${BUILDREQS_DISK_BUILD}" 63 "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${CHECKREQS_DISK_BUILD}"
66 [ -n "$BUILDREQS_DISK_USR" ] && check_build_disk \ 64 [ -n "$CHECKREQS_DISK_USR" ] && check_build_disk \
67 "${ROOT}/usr" "\${ROOT}/usr" "${BUILDREQS_DISK_USR}" 65 "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}"
68 [ -n "$BUILDREQS_DISK_VAR" ] && check_build_disk \ 66 [ -n "$CHECKREQS_DISK_VAR" ] && check_build_disk \
69 "${ROOT}/var" "\${ROOT}/var" "${BUILDREQS_DISK_VAR}" 67 "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}"
70 fi 68 fi
71 69
72 if [ -n "${BUILDREQS_NEED_SLEEP}" ] ; then 70 if [ -n "${CHECKREQS_NEED_SLEEP}" ] ; then
73 echo 71 echo
74 ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in" 72 ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in"
75 ewarn "the next 15 seconds." 73 ewarn "the next 15 seconds."
76 ewarn " " 74 ewarn " "
77 einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf" 75 einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf"
78 einfo "setting BUILDREQS_ACTION=\"error\". To skip build requirements checking," 76 einfo "setting CHECKREQS_ACTION=\"error\". To skip build requirements checking,"
79 einfo "set BUILDREQS_ACTION=\"ignore\"." 77 einfo "set CHECKREQS_ACTION=\"ignore\"."
80 epause 15 78 epause 15
81 fi 79 fi
82 80
83 if [ -n "${BUILDREQS_NEED_DIE}" ] ; then 81 if [ -n "${CHECKREQS_NEED_DIE}" ] ; then
84 eerror "Bailing out as specified by BUILDREQS_ACTION" 82 eerror "Bailing out as specified by CHECKREQS_ACTION"
85 die "Build requirements not met" 83 die "Build requirements not met"
86 fi 84 fi
87} 85}
88 86
89# internal use only! 87# internal use only!
90check_build_memory() { 88check_build_memory() {
91 [ -n "$1" ] && die "Usage: check_build_memory" 89 [ -n "$1" ] && die "Usage: check_build_memory"
92 check_build_msg_begin "${BUILDREQS_MEMORY}" "MBytes" "RAM" 90 check_build_msg_begin "${CHECKREQS_MEMORY}" "MBytes" "RAM"
93 if [ -r /proc/meminfo ] ; then 91 if [ -r /proc/meminfo ] ; then
94 actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \ 92 actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \
95 /proc/meminfo) 93 /proc/meminfo)
96 else 94 else
97 actual_memory=$(sysctl hw.physmem 2>/dev/null ) 95 actual_memory=$(sysctl hw.physmem 2>/dev/null )
98 [ "$?" == "0" ] && 96 [ "$?" == "0" ] &&
99 actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' ) 97 actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
100 fi 98 fi
101 if [ -n "${actual_memory}" ] ; then 99 if [ -n "${actual_memory}" ] ; then
102 if [ ${actual_memory} -lt $((1024 * ${BUILDREQS_MEMORY})) ] ; then 100 if [ ${actual_memory} -lt $((1024 * ${CHECKREQS_MEMORY})) ] ; then
103 eend 1 101 eend 1
104 check_build_msg_ick "${BUILDREQS_MEMORY}" "MBytes" "RAM" 102 check_build_msg_ick "${CHECKREQS_MEMORY}" "MBytes" "RAM"
105 else 103 else
106 eend 0 104 eend 0
107 fi 105 fi
108 else 106 else
109 eend 1 107 eend 1
142 ewarn "Skipping check for at least ${1}${2} ${3}" 140 ewarn "Skipping check for at least ${1}${2} ${3}"
143} 141}
144 142
145# internal use only! 143# internal use only!
146check_build_msg_ick() { 144check_build_msg_ick() {
147 if [ "${BUILDREQS_ACTION}" == "error" ] ; then 145 if [ "${CHECKREQS_ACTION}" == "error" ] ; then
148 eerror "Don't have at least ${1}${2} ${3}" 146 eerror "Don't have at least ${1}${2} ${3}"
149 echo 147 echo
150 export BUILDREQS_NEED_DIE="yes" 148 export CHECKREQS_NEED_DIE="yes"
151 else 149 else
152 ewarn "Don't have at least ${1}${2} ${3}" 150 ewarn "Don't have at least ${1}${2} ${3}"
153 echo 151 echo
154 export BUILDREQS_NEED_SLEEP="yes" 152 export CHECKREQS_NEED_SLEEP="yes"
155 fi 153 fi
156} 154}
157 155

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.1.1

  ViewVC Help
Powered by ViewVC 1.1.20