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

Contents of /eclass/check-reqs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Wed Nov 30 09:59:18 2005 UTC (8 years, 10 months ago) by chriswhite
Changes since 1.1: +28 -30 lines
*** empty log message ***

1 # Copyright 1999-2004 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.4 2005/07/06 20:23:20 agriffis Exp $
4 #
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 # From a user perspective, the variable CHECKREQS_ACTION can be set to:
12 # * "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 # CHECKREQS_MEMORY="256"
28 #
29 # # need this much temporary build space
30 # CHECKREQS_DISK_BUILD="2048"
31 #
32 # # install will need this much space in /usr
33 # CHECKREQS_DISK_USR="1024"
34 #
35 # # install will need this much space in /var
36 # CHECKREQS_DISK_VAR="1024"
37 #
38 # # go!
39 # check_reqs
40 # }
41 #
42 # You should *not* override the user's CHECKREQS_ACTION setting, nor should you
43 # 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 # If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not
48 # 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
56 check_reqs() {
57 [ -n "$1" ] && die "Usage: check_reqs"
58
59 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
60 if [ "$CHECKREQS_ACTION" != "ignore" ] ; then
61 [ -n "$CHECKREQS_MEMORY" ] && check_build_memory
62 [ -n "$CHECKREQS_DISK_BUILD" ] && check_build_disk \
63 "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${CHECKREQS_DISK_BUILD}"
64 [ -n "$CHECKREQS_DISK_USR" ] && check_build_disk \
65 "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}"
66 [ -n "$CHECKREQS_DISK_VAR" ] && check_build_disk \
67 "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}"
68 fi
69
70 if [ -n "${CHECKREQS_NEED_SLEEP}" ] ; then
71 echo
72 ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in"
73 ewarn "the next 15 seconds."
74 ewarn " "
75 einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf"
76 einfo "setting CHECKREQS_ACTION=\"error\". To skip build requirements checking,"
77 einfo "set CHECKREQS_ACTION=\"ignore\"."
78 epause 15
79 fi
80
81 if [ -n "${CHECKREQS_NEED_DIE}" ] ; then
82 eerror "Bailing out as specified by CHECKREQS_ACTION"
83 die "Build requirements not met"
84 fi
85 }
86
87 # internal use only!
88 check_build_memory() {
89 [ -n "$1" ] && die "Usage: check_build_memory"
90 check_build_msg_begin "${CHECKREQS_MEMORY}" "MBytes" "RAM"
91 if [ -r /proc/meminfo ] ; then
92 actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \
93 /proc/meminfo)
94 else
95 actual_memory=$(sysctl hw.physmem 2>/dev/null )
96 [ "$?" == "0" ] &&
97 actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
98 fi
99 if [ -n "${actual_memory}" ] ; then
100 if [ ${actual_memory} -lt $((1024 * ${CHECKREQS_MEMORY})) ] ; then
101 eend 1
102 check_build_msg_ick "${CHECKREQS_MEMORY}" "MBytes" "RAM"
103 else
104 eend 0
105 fi
106 else
107 eend 1
108 ewarn "Couldn't determine amount of memory, skipping ..."
109 fi
110 }
111
112 # internal use only!
113 check_build_disk() {
114 [ -z "$3" ] && die "Usage: check_build_disk where name needed"
115 check_build_msg_begin "${3}" "MBytes" \
116 "disk space at ${2}"
117 actual_space=$(df -Pm ${1} 2>/dev/null | sed -n \
118 '$s/\(\S\+\s\+\)\{3\}\([0-9]\+\).*/\2/p' 2>/dev/null )
119 if [ "$?" == "0" ] && [ -n "${actual_space}" ] ; then
120 if [ ${actual_space} -lt ${3} ] ; then
121 eend 1
122 check_build_msg_ick "${3}" "MBytes" \
123 "disk space at ${2}"
124 else
125 eend 0
126 fi
127 else
128 eend 1
129 ewarn "Couldn't figure out disk space, skipping ..."
130 fi
131 }
132
133 # internal use only!
134 check_build_msg_begin() {
135 ebegin "Checking for at least ${1}${2} ${3}"
136 }
137
138 # internal use only!
139 check_build_msg_skip() {
140 ewarn "Skipping check for at least ${1}${2} ${3}"
141 }
142
143 # internal use only!
144 check_build_msg_ick() {
145 if [ "${CHECKREQS_ACTION}" == "error" ] ; then
146 eerror "Don't have at least ${1}${2} ${3}"
147 echo
148 export CHECKREQS_NEED_DIE="yes"
149 else
150 ewarn "Don't have at least ${1}${2} ${3}"
151 echo
152 export CHECKREQS_NEED_SLEEP="yes"
153 fi
154 }

  ViewVC Help
Powered by ViewVC 1.1.20