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

Contents of /eclass/check-reqs.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sun Nov 21 15:11:50 2004 UTC (9 years, 8 months ago) by ciaranm
Branch: MAIN
Changes since 1.1: +28 -28 lines
nicer variable names

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

  ViewVC Help
Powered by ViewVC 1.1.20