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

Contents of /eclass/check-reqs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Wed Jul 6 20:20:03 2005 UTC (9 years ago) by agriffis
Branch: MAIN
Changes since 1.2: +1 -2 lines
Remove ECLASS= and INHERITED= which haven't been necessary for a long time now

1 ciaranm 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 agriffis 1.3 # $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.2 2004/11/21 15:11:50 ciaranm 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.2 # You should *not* override the user's CHECKREQS_ACTION setting, nor should you
43 ciaranm 1.1 # attempt to provide a value if it is unset. Note that the environment variables
44     # are used rather than parameters for a few reasons:
45     # * easier to do if use blah ; then things
46     # * we might add in additional requirements things later
47 ciaranm 1.2 # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not
48 ciaranm 1.1 # carried out.
49     #
50     # These checks should probably mostly work on non-Linux, and they should
51     # probably degrade gracefully if they don't. Probably.
52    
53     inherit eutils
54    
55     INHERITED="$INHERITED $ECLASS"
56    
57     check_reqs() {
58     [ -n "$1" ] && die "Usage: check_reqs"
59    
60 ciaranm 1.2 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
61     if [ "$CHECKREQS_ACTION" != "ignore" ] ; then
62     [ -n "$CHECKREQS_MEMORY" ] && check_build_memory
63     [ -n "$CHECKREQS_DISK_BUILD" ] && check_build_disk \
64     "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${CHECKREQS_DISK_BUILD}"
65     [ -n "$CHECKREQS_DISK_USR" ] && check_build_disk \
66     "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}"
67     [ -n "$CHECKREQS_DISK_VAR" ] && check_build_disk \
68     "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}"
69 ciaranm 1.1 fi
70    
71 ciaranm 1.2 if [ -n "${CHECKREQS_NEED_SLEEP}" ] ; then
72 ciaranm 1.1 echo
73     ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in"
74     ewarn "the next 15 seconds."
75     ewarn " "
76     einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf"
77 ciaranm 1.2 einfo "setting CHECKREQS_ACTION=\"error\". To skip build requirements checking,"
78     einfo "set CHECKREQS_ACTION=\"ignore\"."
79 ciaranm 1.1 epause 15
80     fi
81    
82 ciaranm 1.2 if [ -n "${CHECKREQS_NEED_DIE}" ] ; then
83     eerror "Bailing out as specified by CHECKREQS_ACTION"
84 ciaranm 1.1 die "Build requirements not met"
85     fi
86     }
87    
88     # internal use only!
89     check_build_memory() {
90     [ -n "$1" ] && die "Usage: check_build_memory"
91 ciaranm 1.2 check_build_msg_begin "${CHECKREQS_MEMORY}" "MBytes" "RAM"
92 ciaranm 1.1 if [ -r /proc/meminfo ] ; then
93     actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \
94     /proc/meminfo)
95     else
96     actual_memory=$(sysctl hw.physmem 2>/dev/null )
97     [ "$?" == "0" ] &&
98     actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
99     fi
100     if [ -n "${actual_memory}" ] ; then
101 ciaranm 1.2 if [ ${actual_memory} -lt $((1024 * ${CHECKREQS_MEMORY})) ] ; then
102 ciaranm 1.1 eend 1
103 ciaranm 1.2 check_build_msg_ick "${CHECKREQS_MEMORY}" "MBytes" "RAM"
104 ciaranm 1.1 else
105     eend 0
106     fi
107     else
108     eend 1
109     ewarn "Couldn't determine amount of memory, skipping ..."
110     fi
111     }
112    
113     # internal use only!
114     check_build_disk() {
115     [ -z "$3" ] && die "Usage: check_build_disk where name needed"
116     check_build_msg_begin "${3}" "MBytes" \
117     "disk space at ${2}"
118     actual_space=$(df -Pm ${1} 2>/dev/null | sed -n \
119     '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2>/dev/null )
120     if [ "$?" == "0" ] && [ -n "${actual_space}" ] ; then
121     if [ ${actual_space} -lt ${3} ] ; then
122     eend 1
123     check_build_msg_ick "${3}" "MBytes" \
124     "disk space at ${2}"
125     else
126     eend 0
127     fi
128     else
129     eend 1
130     ewarn "Couldn't figure out disk space, skipping ..."
131     fi
132     }
133    
134     # internal use only!
135     check_build_msg_begin() {
136     ebegin "Checking for at least ${1}${2} ${3}"
137     }
138    
139     # internal use only!
140     check_build_msg_skip() {
141     ewarn "Skipping check for at least ${1}${2} ${3}"
142     }
143    
144     # internal use only!
145     check_build_msg_ick() {
146 ciaranm 1.2 if [ "${CHECKREQS_ACTION}" == "error" ] ; then
147 ciaranm 1.1 eerror "Don't have at least ${1}${2} ${3}"
148     echo
149 ciaranm 1.2 export CHECKREQS_NEED_DIE="yes"
150 ciaranm 1.1 else
151     ewarn "Don't have at least ${1}${2} ${3}"
152     echo
153 ciaranm 1.2 export CHECKREQS_NEED_SLEEP="yes"
154 ciaranm 1.1 fi
155     }

  ViewVC Help
Powered by ViewVC 1.1.20