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

Contents of /eclass/check-reqs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Sun Aug 22 21:18:03 2010 UTC (3 years, 7 months ago) by halcy0n
Branch: MAIN
Changes since 1.6: +13 -13 lines
Actually print out the path that check-reqs is testing; bug #300662

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

  ViewVC Help
Powered by ViewVC 1.1.20