/[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.5 Revision 1.6
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2008 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.5 2006/02/15 12:51:25 ciaranm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.6 2008/04/11 13:52:55 zlin Exp $
4# 4
5# @ECLASS: check-reqs.eclass
6# @MAINTAINER:
7# Bo ├śrsted Andresen <zlin@gentoo.org>
8#
5# Original Author: Ciaran McCreesh <ciaranm@gentoo.org> 9# Original Author: Ciaran McCreesh <ciaranm@gentoo.org>
6# 10# @BLURB: Provides a uniform way of handling ebuild which have very high build requirements
11# @DESCRIPTION:
7# This eclass provides a uniform way of handling ebuilds which have very high 12# 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 13# build requirements in terms of memory or disk space. It provides a function
9# which should usually be called during pkg_setup(). 14# which should usually be called during pkg_setup().
10# 15#
11# From a user perspective, the variable CHECKREQS_ACTION can be set to: 16# From a user perspective, the variable CHECKREQS_ACTION can be set to:
12# * "warn" (default), which will display a warning and wait for 15s 17# * "warn" (default), which will display a warning and wait for 15s
13# * "error", which will make the ebuild error out 18# * "error", which will make the ebuild error out
14# * "ignore", which will not take any action 19# * "ignore", which will not take any action
20#
15# The chosen action only happens when the system's resources are detected 21# 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. 22# correctly and only if they are below the threshold specified by the package.
17# 23#
18# For ebuild authors: only use this eclass if you reaaalllllly have stupidly 24# For ebuild authors: only use this eclass if you reaaalllllly have stupidly
19# high build requirements. At an absolute minimum, you shouldn't be using this 25# high build requirements. At an absolute minimum, you shouldn't be using this
20# unless the ebuild needs >256MBytes RAM or >1GByte temporary or install space. 26# unless the ebuild needs >256MBytes RAM or >1GByte temporary or install space.
21# The code should look something like: 27# The code should look something like:
22# 28#
29# @CODE
23# pkg_setup() { 30# pkg_setup() {
24# # values in MBytes 31# # values in MBytes
25# 32#
26# # need this much memory (does *not* check swap) 33# # need this much memory (does *not* check swap)
27# CHECKREQS_MEMORY="256" 34# CHECKREQS_MEMORY="256"
36# CHECKREQS_DISK_VAR="1024" 43# CHECKREQS_DISK_VAR="1024"
37# 44#
38# # go! 45# # go!
39# check_reqs 46# check_reqs
40# } 47# }
48# @CODE
41# 49#
42# Alternatively, the check_reqs_conditional function can be used to carry out 50# Alternatively, the check_reqs_conditional function can be used to carry out
43# alternate actions (e.g. using a much slower but far less memory intensive 51# alternate actions (e.g. using a much slower but far less memory intensive
44# build option that gives the same end result). 52# build option that gives the same end result).
45# 53#
54# These checks should probably mostly work on non-Linux, and they should 62# These checks should probably mostly work on non-Linux, and they should
55# probably degrade gracefully if they don't. Probably. 63# probably degrade gracefully if they don't. Probably.
56 64
57inherit eutils 65inherit eutils
58 66
67# @ECLASS-VARIABLE: CHECKREQS_MEMORY
68# @DESCRIPTION:
69# How much RAM is needed in MB?
59 70
71# @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD
72# @DESCRIPTION:
73# How much diskspace is needed to build the package? In MB
74
75# @ECLASS-VARIABLE: CHECKREQS_DISK_USR
76# @DESCRIPTION:
77# How much space in /usr is needed to install the package? In MB
78
79# @ECLASS-VARIABLE: CHECKREQS_DISK_VAR
80# @DESCRIPTION:
81# How much space is needed in /var? In MB
82
83# @FUNCTION: check_reqs
84# @DESCRIPTION:
85# Checks the requirements given in the specific variables. If not reached,
86# either prints a warning or dies.
60check_reqs() { 87check_reqs() {
61 [ -n "$1" ] && die "Usage: check_reqs" 88 [[ -n "${1}" ]] && die "Usage: check_reqs"
62 89
63 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE="" 90 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
64 if [ "$CHECKREQS_ACTION" != "ignore" ] ; then 91 if [[ "$CHECKREQS_ACTION" != "ignore" ]] ; then
65 [ -n "$CHECKREQS_MEMORY" ] && check_build_memory 92 [[ -n "$CHECKREQS_MEMORY" ]] && check_build_memory
66 [ -n "$CHECKREQS_DISK_BUILD" ] && check_build_disk \ 93 [[ -n "$CHECKREQS_DISK_BUILD" ]] && check_build_disk \
67 "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${CHECKREQS_DISK_BUILD}" 94 "${T}" "\${T}" "${CHECKREQS_DISK_BUILD}"
68 [ -n "$CHECKREQS_DISK_USR" ] && check_build_disk \ 95 [[ -n "$CHECKREQS_DISK_USR" ]] && check_build_disk \
69 "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}" 96 "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}"
70 [ -n "$CHECKREQS_DISK_VAR" ] && check_build_disk \ 97 [[ -n "$CHECKREQS_DISK_VAR" ]] && check_build_disk \
71 "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}" 98 "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}"
72 fi 99 fi
73 100
74 if [ -n "${CHECKREQS_NEED_SLEEP}" ] ; then 101 if [[ -n "${CHECKREQS_NEED_SLEEP}" ]] ; then
75 echo 102 echo
76 ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in" 103 ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in"
77 ewarn "the next 15 seconds." 104 ewarn "the next 15 seconds."
78 ewarn " " 105 ewarn " "
79 einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf" 106 einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf"
80 einfo "setting CHECKREQS_ACTION=\"error\". To skip build requirements checking," 107 einfo "setting CHECKREQS_ACTION=\"error\". To skip build requirements checking,"
81 einfo "set CHECKREQS_ACTION=\"ignore\"." 108 einfo "set CHECKREQS_ACTION=\"ignore\"."
82 epause 15 109 epause 15
83 fi 110 fi
84 111
85 if [ -n "${CHECKREQS_NEED_DIE}" ] ; then 112 if [[ -n "${CHECKREQS_NEED_DIE}" ]] ; then
86 eerror "Bailing out as specified by CHECKREQS_ACTION" 113 eerror "Bailing out as specified by CHECKREQS_ACTION"
87 die "Build requirements not met" 114 die "Build requirements not met"
88 fi 115 fi
89} 116}
90 117
118# @FUNCTION: check_reqs_conditional
119# @RETURN: True if requirements check passed, else False
120# @DESCRIPTION:
121# Checks the requirements given in the specific variables
91check_reqs_conditional() { 122check_reqs_conditional() {
92 [ -n "$1" ] && die "Usage: check_reqs" 123 [[ -n "${1}" ]] && die "Usage: check_reqs"
93 124
94 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE="" 125 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
95 if [ "$CHECKREQS_ACTION" != "ignore" ] ; then 126 if [[ "$CHECKREQS_ACTION" != "ignore" ]] ; then
96 [ -n "$CHECKREQS_MEMORY" ] && check_build_memory 127 [[ -n "$CHECKREQS_MEMORY" ]] && check_build_memory
97 [ -n "$CHECKREQS_DISK_BUILD" ] && check_build_disk \ 128 [[ -n "$CHECKREQS_DISK_BUILD" ]] && check_build_disk \
98 "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${CHECKREQS_DISK_BUILD}" 129 "${T}" "\${T}" "${CHECKREQS_DISK_BUILD}"
99 [ -n "$CHECKREQS_DISK_USR" ] && check_build_disk \ 130 [[ -n "$CHECKREQS_DISK_USR" ]] && check_build_disk \
100 "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}" 131 "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}"
101 [ -n "$CHECKREQS_DISK_VAR" ] && check_build_disk \ 132 [[ -n "$CHECKREQS_DISK_VAR" ]] && check_build_disk \
102 "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}" 133 "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}"
103 fi 134 fi
104 135
105 [ -z "${CHECKREQS_NEED_SLEEP}" ] && [ -z "${CHECKREQS_NEED_DIE}" ] 136 [[ -z "${CHECKREQS_NEED_SLEEP}" && -z "${CHECKREQS_NEED_DIE}" ]]
106} 137}
107 138
108# internal use only! 139# internal use only!
109check_build_memory() { 140check_build_memory() {
110 [ -n "$1" ] && die "Usage: check_build_memory" 141 [[ -n "${1}" ]] && die "Usage: check_build_memory"
111 check_build_msg_begin "${CHECKREQS_MEMORY}" "MBytes" "RAM" 142 check_build_msg_begin "${CHECKREQS_MEMORY}" "MBytes" "RAM"
112 if [ -r /proc/meminfo ] ; then 143 if [[ -r /proc/meminfo ]] ; then
113 actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \ 144 actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \
114 /proc/meminfo) 145 /proc/meminfo)
115 else 146 else
116 actual_memory=$(sysctl hw.physmem 2>/dev/null ) 147 actual_memory=$(sysctl hw.physmem 2>/dev/null )
117 [ "$?" == "0" ] && 148 [[ "$?" == "0" ]] &&
118 actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' ) 149 actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
119 fi 150 fi
120 if [ -n "${actual_memory}" ] ; then 151 if [[ -n "${actual_memory}" ]] ; then
121 if [ ${actual_memory} -lt $((1024 * ${CHECKREQS_MEMORY})) ] ; then 152 if [[ ${actual_memory} -lt $((1024 * ${CHECKREQS_MEMORY})) ]] ; then
122 eend 1 153 eend 1
123 check_build_msg_ick "${CHECKREQS_MEMORY}" "MBytes" "RAM" 154 check_build_msg_ick "${CHECKREQS_MEMORY}" "MBytes" "RAM"
124 else 155 else
125 eend 0 156 eend 0
126 fi 157 fi
130 fi 161 fi
131} 162}
132 163
133# internal use only! 164# internal use only!
134check_build_disk() { 165check_build_disk() {
135 [ -z "$3" ] && die "Usage: check_build_disk where name needed" 166 [[ -z "${3}" ]] && die "Usage: check_build_disk where name needed"
136 check_build_msg_begin "${3}" "MBytes" \ 167 check_build_msg_begin "${3}" "MBytes" \
137 "disk space at ${2}" 168 "disk space at ${2}"
138 actual_space=$(df -Pm ${1} 2>/dev/null | sed -n \ 169 actual_space=$(df -Pm ${1} 2>/dev/null | sed -n \
139 '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2>/dev/null ) 170 '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2>/dev/null )
140 if [ "$?" == "0" ] && [ -n "${actual_space}" ] ; then 171 if [[ "$?" == "0" && -n "${actual_space}" ]] ; then
141 if [ ${actual_space} -lt ${3} ] ; then 172 if [[ ${actual_space} -lt ${3} ]] ; then
142 eend 1 173 eend 1
143 check_build_msg_ick "${3}" "MBytes" \ 174 check_build_msg_ick "${3}" "MBytes" \
144 "disk space at ${2}" 175 "disk space at ${2}"
145 else 176 else
146 eend 0 177 eend 0
161 ewarn "Skipping check for at least ${1}${2} ${3}" 192 ewarn "Skipping check for at least ${1}${2} ${3}"
162} 193}
163 194
164# internal use only! 195# internal use only!
165check_build_msg_ick() { 196check_build_msg_ick() {
166 if [ "${CHECKREQS_ACTION}" == "error" ] ; then 197 if [[ "${CHECKREQS_ACTION}" == "error" ]] ; then
167 eerror "Don't have at least ${1}${2} ${3}" 198 eerror "Don't have at least ${1}${2} ${3}"
168 echo 199 echo
169 export CHECKREQS_NEED_DIE="yes" 200 export CHECKREQS_NEED_DIE="yes"
170 else 201 else
171 ewarn "Don't have at least ${1}${2} ${3}" 202 ewarn "Don't have at least ${1}${2} ${3}"

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.20