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

Contents of /eclass/check-reqs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Wed Feb 15 12:51:25 2006 UTC (8 years, 10 months ago) by ciaranm
Branch: MAIN
Changes since 1.4: +22 -1 lines
Add check_reqs_conditional function

1 ciaranm 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 ciaranm 1.5 # $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.4 2005/07/06 20:23:20 agriffis Exp $
4 ciaranm 1.1 #
5     # Original Author: Ciaran McCreesh <ciaranm@gentoo.org>
6     #
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
9     # which should usually be called during pkg_setup().
10     #
11 ciaranm 1.2 # From a user perspective, the variable CHECKREQS_ACTION can be set to:
12 ciaranm 1.1 # * "warn" (default), which will display a warning and wait for 15s
13     # * "error", which will make the ebuild error out
14     # * "ignore", which will not take any action
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.
17     #
18     # 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
20     # unless the ebuild needs >256MBytes RAM or >1GByte temporary or install space.
21     # The code should look something like:
22     #
23     # pkg_setup() {
24     # # values in MBytes
25     #
26     # # need this much memory (does *not* check swap)
27 ciaranm 1.2 # CHECKREQS_MEMORY="256"
28 ciaranm 1.1 #
29     # # need this much temporary build space
30 ciaranm 1.2 # CHECKREQS_DISK_BUILD="2048"
31 ciaranm 1.1 #
32     # # install will need this much space in /usr
33 ciaranm 1.2 # CHECKREQS_DISK_USR="1024"
34 ciaranm 1.1 #
35     # # install will need this much space in /var
36 ciaranm 1.2 # CHECKREQS_DISK_VAR="1024"
37 ciaranm 1.1 #
38     # # go!
39     # check_reqs
40     # }
41     #
42 ciaranm 1.5 # 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
44     # build option that gives the same end result).
45     #
46 ciaranm 1.2 # You should *not* override the user's CHECKREQS_ACTION setting, nor should you
47 ciaranm 1.1 # attempt to provide a value if it is unset. Note that the environment variables
48     # are used rather than parameters for a few reasons:
49     # * easier to do if use blah ; then things
50     # * we might add in additional requirements things later
51 ciaranm 1.2 # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not
52 ciaranm 1.1 # carried out.
53     #
54     # These checks should probably mostly work on non-Linux, and they should
55     # probably degrade gracefully if they don't. Probably.
56    
57     inherit eutils
58    
59    
60     check_reqs() {
61     [ -n "$1" ] && die "Usage: check_reqs"
62    
63 ciaranm 1.2 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
64     if [ "$CHECKREQS_ACTION" != "ignore" ] ; then
65     [ -n "$CHECKREQS_MEMORY" ] && check_build_memory
66     [ -n "$CHECKREQS_DISK_BUILD" ] && check_build_disk \
67     "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${CHECKREQS_DISK_BUILD}"
68     [ -n "$CHECKREQS_DISK_USR" ] && check_build_disk \
69     "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}"
70     [ -n "$CHECKREQS_DISK_VAR" ] && check_build_disk \
71     "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}"
72 ciaranm 1.1 fi
73    
74 ciaranm 1.2 if [ -n "${CHECKREQS_NEED_SLEEP}" ] ; then
75 ciaranm 1.1 echo
76     ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in"
77     ewarn "the next 15 seconds."
78     ewarn " "
79     einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf"
80 ciaranm 1.2 einfo "setting CHECKREQS_ACTION=\"error\". To skip build requirements checking,"
81     einfo "set CHECKREQS_ACTION=\"ignore\"."
82 ciaranm 1.1 epause 15
83     fi
84    
85 ciaranm 1.2 if [ -n "${CHECKREQS_NEED_DIE}" ] ; then
86     eerror "Bailing out as specified by CHECKREQS_ACTION"
87 ciaranm 1.1 die "Build requirements not met"
88     fi
89     }
90    
91 ciaranm 1.5 check_reqs_conditional() {
92     [ -n "$1" ] && die "Usage: check_reqs"
93    
94     export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
95     if [ "$CHECKREQS_ACTION" != "ignore" ] ; then
96     [ -n "$CHECKREQS_MEMORY" ] && check_build_memory
97     [ -n "$CHECKREQS_DISK_BUILD" ] && check_build_disk \
98     "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${CHECKREQS_DISK_BUILD}"
99     [ -n "$CHECKREQS_DISK_USR" ] && check_build_disk \
100     "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}"
101     [ -n "$CHECKREQS_DISK_VAR" ] && check_build_disk \
102     "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}"
103     fi
104    
105     [ -z "${CHECKREQS_NEED_SLEEP}" ] && [ -z "${CHECKREQS_NEED_DIE}" ]
106     }
107    
108 ciaranm 1.1 # internal use only!
109     check_build_memory() {
110     [ -n "$1" ] && die "Usage: check_build_memory"
111 ciaranm 1.2 check_build_msg_begin "${CHECKREQS_MEMORY}" "MBytes" "RAM"
112 ciaranm 1.1 if [ -r /proc/meminfo ] ; then
113     actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \
114     /proc/meminfo)
115     else
116     actual_memory=$(sysctl hw.physmem 2>/dev/null )
117     [ "$?" == "0" ] &&
118     actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
119     fi
120     if [ -n "${actual_memory}" ] ; then
121 ciaranm 1.2 if [ ${actual_memory} -lt $((1024 * ${CHECKREQS_MEMORY})) ] ; then
122 ciaranm 1.1 eend 1
123 ciaranm 1.2 check_build_msg_ick "${CHECKREQS_MEMORY}" "MBytes" "RAM"
124 ciaranm 1.1 else
125     eend 0
126     fi
127     else
128     eend 1
129     ewarn "Couldn't determine amount of memory, skipping ..."
130     fi
131     }
132    
133     # internal use only!
134     check_build_disk() {
135     [ -z "$3" ] && die "Usage: check_build_disk where name needed"
136     check_build_msg_begin "${3}" "MBytes" \
137     "disk space at ${2}"
138     actual_space=$(df -Pm ${1} 2>/dev/null | sed -n \
139     '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2>/dev/null )
140     if [ "$?" == "0" ] && [ -n "${actual_space}" ] ; then
141     if [ ${actual_space} -lt ${3} ] ; then
142     eend 1
143     check_build_msg_ick "${3}" "MBytes" \
144     "disk space at ${2}"
145     else
146     eend 0
147     fi
148     else
149     eend 1
150     ewarn "Couldn't figure out disk space, skipping ..."
151     fi
152     }
153    
154     # internal use only!
155     check_build_msg_begin() {
156     ebegin "Checking for at least ${1}${2} ${3}"
157     }
158    
159     # internal use only!
160     check_build_msg_skip() {
161     ewarn "Skipping check for at least ${1}${2} ${3}"
162     }
163    
164     # internal use only!
165     check_build_msg_ick() {
166 ciaranm 1.2 if [ "${CHECKREQS_ACTION}" == "error" ] ; then
167 ciaranm 1.1 eerror "Don't have at least ${1}${2} ${3}"
168     echo
169 ciaranm 1.2 export CHECKREQS_NEED_DIE="yes"
170 ciaranm 1.1 else
171     ewarn "Don't have at least ${1}${2} ${3}"
172     echo
173 ciaranm 1.2 export CHECKREQS_NEED_SLEEP="yes"
174 ciaranm 1.1 fi
175     }

  ViewVC Help
Powered by ViewVC 1.1.20