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

Contents of /eclass/check-reqs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations) (download)
Sun Aug 22 21:18:03 2010 UTC (4 years, 2 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 zlin 1.6 # Copyright 1999-2008 Gentoo Foundation
2 ciaranm 1.1 # Distributed under the terms of the GNU General Public License v2
3 halcy0n 1.7 # $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.6 2008/04/11 13:52:55 zlin Exp $
4 zlin 1.6
5     # @ECLASS: check-reqs.eclass
6     # @MAINTAINER:
7     # Bo ├śrsted Andresen <zlin@gentoo.org>
8     #
9 ciaranm 1.1 # Original Author: Ciaran McCreesh <ciaranm@gentoo.org>
10 zlin 1.6 # @BLURB: Provides a uniform way of handling ebuild which have very high build requirements
11     # @DESCRIPTION:
12 ciaranm 1.1 # This eclass provides a uniform way of handling ebuilds which have very high
13 zlin 1.6 # build requirements in terms of memory or disk space. It provides a function
14 ciaranm 1.1 # which should usually be called during pkg_setup().
15     #
16 ciaranm 1.2 # From a user perspective, the variable CHECKREQS_ACTION can be set to:
17 ciaranm 1.1 # * "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 zlin 1.6 #
21 ciaranm 1.1 # 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 zlin 1.6 # @CODE
30 ciaranm 1.1 # pkg_setup() {
31     # # values in MBytes
32     #
33     # # need this much memory (does *not* check swap)
34 ciaranm 1.2 # CHECKREQS_MEMORY="256"
35 ciaranm 1.1 #
36     # # need this much temporary build space
37 ciaranm 1.2 # CHECKREQS_DISK_BUILD="2048"
38 ciaranm 1.1 #
39     # # install will need this much space in /usr
40 ciaranm 1.2 # CHECKREQS_DISK_USR="1024"
41 ciaranm 1.1 #
42     # # install will need this much space in /var
43 ciaranm 1.2 # CHECKREQS_DISK_VAR="1024"
44 ciaranm 1.1 #
45     # # go!
46     # check_reqs
47     # }
48 zlin 1.6 # @CODE
49 ciaranm 1.1 #
50 ciaranm 1.5 # 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 ciaranm 1.2 # You should *not* override the user's CHECKREQS_ACTION setting, nor should you
55 ciaranm 1.1 # 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 ciaranm 1.2 # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not
60 ciaranm 1.1 # 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 zlin 1.6 # @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 ciaranm 1.1 check_reqs() {
88 zlin 1.6 [[ -n "${1}" ]] && die "Usage: check_reqs"
89 ciaranm 1.1
90 ciaranm 1.2 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
91 zlin 1.6 if [[ "$CHECKREQS_ACTION" != "ignore" ]] ; then
92     [[ -n "$CHECKREQS_MEMORY" ]] && check_build_memory
93     [[ -n "$CHECKREQS_DISK_BUILD" ]] && check_build_disk \
94 halcy0n 1.7 "${T}" "${CHECKREQS_DISK_BUILD}"
95 zlin 1.6 [[ -n "$CHECKREQS_DISK_USR" ]] && check_build_disk \
96 halcy0n 1.7 "${ROOT}/usr" "${CHECKREQS_DISK_USR}"
97 zlin 1.6 [[ -n "$CHECKREQS_DISK_VAR" ]] && check_build_disk \
98 halcy0n 1.7 "${ROOT}/var" "${CHECKREQS_DISK_VAR}"
99 ciaranm 1.1 fi
100    
101 zlin 1.6 if [[ -n "${CHECKREQS_NEED_SLEEP}" ]] ; then
102 ciaranm 1.1 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 ciaranm 1.2 einfo "setting CHECKREQS_ACTION=\"error\". To skip build requirements checking,"
108     einfo "set CHECKREQS_ACTION=\"ignore\"."
109 ciaranm 1.1 epause 15
110     fi
111    
112 zlin 1.6 if [[ -n "${CHECKREQS_NEED_DIE}" ]] ; then
113 ciaranm 1.2 eerror "Bailing out as specified by CHECKREQS_ACTION"
114 ciaranm 1.1 die "Build requirements not met"
115     fi
116     }
117    
118 zlin 1.6 # @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 ciaranm 1.5 check_reqs_conditional() {
123 zlin 1.6 [[ -n "${1}" ]] && die "Usage: check_reqs"
124 ciaranm 1.5
125     export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
126 zlin 1.6 if [[ "$CHECKREQS_ACTION" != "ignore" ]] ; then
127     [[ -n "$CHECKREQS_MEMORY" ]] && check_build_memory
128     [[ -n "$CHECKREQS_DISK_BUILD" ]] && check_build_disk \
129 halcy0n 1.7 "${T}" "${CHECKREQS_DISK_BUILD}"
130 zlin 1.6 [[ -n "$CHECKREQS_DISK_USR" ]] && check_build_disk \
131 halcy0n 1.7 "${ROOT}/usr" "${CHECKREQS_DISK_USR}"
132 zlin 1.6 [[ -n "$CHECKREQS_DISK_VAR" ]] && check_build_disk \
133 halcy0n 1.7 "${ROOT}/var" "${CHECKREQS_DISK_VAR}"
134 ciaranm 1.5 fi
135    
136 zlin 1.6 [[ -z "${CHECKREQS_NEED_SLEEP}" && -z "${CHECKREQS_NEED_DIE}" ]]
137 ciaranm 1.5 }
138    
139 ciaranm 1.1 # internal use only!
140     check_build_memory() {
141 zlin 1.6 [[ -n "${1}" ]] && die "Usage: check_build_memory"
142 ciaranm 1.2 check_build_msg_begin "${CHECKREQS_MEMORY}" "MBytes" "RAM"
143 zlin 1.6 if [[ -r /proc/meminfo ]] ; then
144 ciaranm 1.1 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 zlin 1.6 [[ "$?" == "0" ]] &&
149 ciaranm 1.1 actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
150     fi
151 zlin 1.6 if [[ -n "${actual_memory}" ]] ; then
152     if [[ ${actual_memory} -lt $((1024 * ${CHECKREQS_MEMORY})) ]] ; then
153 ciaranm 1.1 eend 1
154 ciaranm 1.2 check_build_msg_ick "${CHECKREQS_MEMORY}" "MBytes" "RAM"
155 ciaranm 1.1 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 halcy0n 1.7 [[ -z "${2}" ]] && die "Usage: check_build_disk where name needed"
167     check_build_msg_begin "${2}" "MBytes" \
168     "disk space at ${1}"
169 ciaranm 1.1 actual_space=$(df -Pm ${1} 2>/dev/null | sed -n \
170     '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2>/dev/null )
171 zlin 1.6 if [[ "$?" == "0" && -n "${actual_space}" ]] ; then
172 halcy0n 1.7 if [[ ${actual_space} -lt ${2} ]] ; then
173 ciaranm 1.1 eend 1
174 halcy0n 1.7 check_build_msg_ick "${2}" "MBytes" \
175     "disk space at ${1}"
176 ciaranm 1.1 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 zlin 1.6 if [[ "${CHECKREQS_ACTION}" == "error" ]] ; then
198 ciaranm 1.1 eerror "Don't have at least ${1}${2} ${3}"
199     echo
200 ciaranm 1.2 export CHECKREQS_NEED_DIE="yes"
201 ciaranm 1.1 else
202     ewarn "Don't have at least ${1}${2} ${3}"
203     echo
204 ciaranm 1.2 export CHECKREQS_NEED_SLEEP="yes"
205 ciaranm 1.1 fi
206     }

  ViewVC Help
Powered by ViewVC 1.1.20